Skip to content

Commit d45d852

Browse files
committed
refactor: consolidate e2e workflows and enhance deployment configurations
1 parent 092add4 commit d45d852

4 files changed

Lines changed: 221 additions & 377 deletions

File tree

.github/workflows/test-e2e-main.yaml

Lines changed: 6 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -14,150 +14,11 @@ permissions:
1414
contents: read
1515

1616
jobs:
17-
deploy:
18-
outputs:
19-
storeAdminIp: ${{ steps.kubectl_get_service.outputs.STORE_ADMIN_IP }}
20-
storeFrontIp: ${{ steps.kubectl_get_service.outputs.STORE_FRONT_IP }}
21-
runs-on: ubuntu-latest
22-
steps:
23-
- name: Checkout
24-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
25-
26-
- name: Install Terraform
27-
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
28-
29-
- name: Install azd
30-
uses: Azure/setup-azd@ae0f8b5482eeac61e940f447327d84c73beb8b1e # v2.1.0
31-
32-
- name: Install kubelogin
33-
uses: azure/use-kubelogin@76597ae0fcbaace21b05e13a2cbf8daee2c6e820 # v1
34-
with:
35-
kubelogin-version: "v0.2.8"
36-
37-
- name: Azure CLI login
38-
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2
39-
with:
40-
client-id: ${{ secrets.AZURE_CLIENT_ID }}
41-
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
42-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
43-
44-
- name: Azure Developer CLI login
45-
run: |
46-
azd auth login \
47-
--client-id ${{ secrets.AZURE_CLIENT_ID }} \
48-
--federated-credential-provider "github" \
49-
--tenant-id ${{ secrets.AZURE_TENANT_ID }}
50-
51-
- name: Turn on Helm support for azd
52-
run: azd config set alpha.aks.helm on
53-
54-
- name: Swap azd config files to build from source
55-
run: |
56-
mv azure.yaml azure.yaml.bak
57-
mv azure-build-from-source.yaml azure.yaml
58-
59-
- name: Provision and deploy
60-
id: provision_deploy
61-
continue-on-error: true
62-
run: |
63-
azd env new ${{ vars.AZURE_ENV_NAME }}
64-
azd env set DEPLOY_AZURE_CONTAINER_REGISTRY true
65-
azd env set DEPLOY_AZURE_OPENAI true
66-
azd env set AZURE_OPENAI_LOCATION ${{ vars.AZURE_LOCATION }}
67-
azd env set DEPLOY_AZURE_SERVICE_BUS true
68-
azd env set DEPLOY_AZURE_COSMOSDB true
69-
azd env set AZURE_COSMOSDB_ACCOUNT_KIND MongoDB
70-
azd env set DEPLOY_OBSERVABILITY_TOOLS true
71-
azd env set SOURCE_REGISTRY "ghcr.io/${{ github.repository_owner }}"
72-
azd up --no-prompt
73-
env:
74-
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
75-
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
76-
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
77-
78-
- name: Save azd cache
79-
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4
80-
if: always()
81-
with:
82-
path: |
83-
.azure/
84-
key: ${{ runner.os }}-azd-${{ github.run_id }}-${{ github.sha }}
85-
86-
- name: Check provision and deploy result
87-
if: steps.provision_deploy.outcome == 'failure'
88-
run: |
89-
echo "Provision and deploy failed"
90-
exit 1
91-
92-
- name: Get Store IPs
93-
id: kubectl_get_service
94-
if: steps.provision_deploy.outcome == 'success'
95-
run: |
96-
eval $(azd env get-values)
97-
storeAdminIp=$(kubectl get service store-admin -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
98-
while [ -z "$storeAdminIp" ]; do
99-
sleep 60
100-
storeAdminIp=$(kubectl get service store-admin -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
101-
done
102-
echo "STORE_ADMIN_IP=${storeAdminIp}"
103-
echo "STORE_ADMIN_IP=${storeAdminIp}" >> "$GITHUB_OUTPUT"
104-
storeFrontIp=$(kubectl get service store-front -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
105-
while [ -z "$storeFrontIp" ]; do
106-
sleep 60
107-
storeFrontIp=$(kubectl get service store-front -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
108-
done
109-
echo "STORE_FRONT_IP=${storeFrontIp}"
110-
echo "STORE_FRONT_IP=${storeFrontIp}" >> "$GITHUB_OUTPUT"
111-
112-
playwright-tests:
113-
needs: deploy
114-
uses: ./.github/workflows/test-playwright.yaml
17+
test-e2e:
18+
uses: ./.github/workflows/test-e2e-reusable.yaml
11519
secrets: inherit
11620
with:
117-
storeAdminUrl: "http://${{ needs.deploy.outputs.storeAdminIp }}"
118-
storeFrontUrl: "http://${{ needs.deploy.outputs.storeFrontIp }}"
119-
120-
teardown:
121-
if: always()
122-
needs: playwright-tests
123-
runs-on: ubuntu-latest
124-
steps:
125-
- name: Checkout
126-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
127-
128-
- name: Install Terraform
129-
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
130-
131-
- name: Install azd
132-
uses: Azure/setup-azd@ae0f8b5482eeac61e940f447327d84c73beb8b1e # v2.1.0
133-
134-
- name: Restore azd cache
135-
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4
136-
with:
137-
path: |
138-
.azure/
139-
key: ${{ runner.os }}-azd-${{ github.run_id }}-${{ github.sha }}
140-
141-
- name: Azure CLI login
142-
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2
143-
with:
144-
client-id: ${{ secrets.AZURE_CLIENT_ID }}
145-
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
146-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
147-
148-
- name: Azure Developer CLI login
149-
run: |
150-
azd auth login \
151-
--client-id ${{ secrets.AZURE_CLIENT_ID }} \
152-
--federated-credential-provider "github" \
153-
--tenant-id ${{ secrets.AZURE_TENANT_ID }}
154-
155-
- name: Destroy environment
156-
run: azd down --force --purge
157-
env:
158-
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
159-
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
160-
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
161-
162-
- name: Remove azd folder
163-
run: rm -rf .azure
21+
deploy-from-source: true
22+
deploy-method: helm
23+
deploy-full-services: true
24+
source-registry: "ghcr.io/${{ github.repository_owner }}"

.github/workflows/test-e2e-pr.yml

Lines changed: 27 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
outputs:
1818
has-permission: ${{ steps.check.outputs.has-permission }}
19+
pr-number: ${{ steps.get-pr.outputs.pr-number }}
1920
steps:
2021
- name: Check if user has permission
2122
id: check
@@ -43,7 +44,14 @@ jobs:
4344
});
4445
}
4546
46-
test-e2e:
47+
- name: Get PR number
48+
id: get-pr
49+
if: steps.check.outputs.has-permission == 'true'
50+
run: echo "pr-number=${PR_URL##*/}" >> "$GITHUB_OUTPUT"
51+
env:
52+
PR_URL: ${{ github.event.issue.pull_request.url }}
53+
54+
start-comment:
4755
needs: check-permissions
4856
if: needs.check-permissions.outputs.has-permission == 'true'
4957
runs-on: ubuntu-latest
@@ -63,128 +71,24 @@ jobs:
6371
**Location:** ${{ vars.AZURE_LOCATION }}`
6472
});
6573
66-
- name: Checkout
67-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
68-
69-
- name: PR checkout
70-
run: |
71-
PR_URL="${{ github.event.issue.pull_request.url }}"
72-
PR_NUM=${PR_URL##*/}
73-
gh pr checkout $PR_NUM
74-
env:
75-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76-
77-
- name: Install Terraform
78-
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
79-
80-
- name: Install azd
81-
uses: Azure/setup-azd@ae0f8b5482eeac61e940f447327d84c73beb8b1e # v2.1.0
82-
83-
- name: Install kubelogin
84-
uses: azure/use-kubelogin@76597ae0fcbaace21b05e13a2cbf8daee2c6e820 # v1
85-
with:
86-
kubelogin-version: "v0.2.8"
87-
88-
- name: Azure login
89-
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2
90-
with:
91-
client-id: ${{ secrets.AZURE_CLIENT_ID }}
92-
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
93-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
94-
95-
- name: Azure Developer CLI login
96-
run: |
97-
azd auth login \
98-
--client-id ${{ secrets.AZURE_CLIENT_ID }} \
99-
--federated-credential-provider "github" \
100-
--tenant-id ${{ secrets.AZURE_TENANT_ID }}
101-
102-
- name: Turn on Kustomize support
103-
run: azd config set alpha.aks.kustomize on
104-
105-
- name: Swap azd config files to build from source
106-
run: |
107-
mv azure.yaml azure.yaml.bak
108-
mv azure-build-from-source.yaml azure.yaml
109-
110-
- name: Provision resources and deploy app
111-
run: |
112-
azd env new ${{ vars.AZURE_ENV_NAME }}
113-
azd env set DEPLOY_AZURE_CONTAINER_REGISTRY true
114-
azd env set DEPLOY_AZURE_OPENAI true
115-
azd env set AZURE_OPENAI_LOCATION ${{ vars.AZURE_LOCATION }}
116-
azd env set DEPLOY_AZURE_SERVICE_BUS true
117-
azd env set DEPLOY_AZURE_COSMOSDB true
118-
azd env set AZURE_COSMOSDB_ACCOUNT_KIND MongoDB
119-
azd env set DEPLOY_OBSERVABILITY_TOOLS true
120-
azd up
121-
env:
122-
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
123-
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
124-
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
125-
126-
- name: Get endpoint URLs
127-
id: azd_get_endpoint_urls
128-
run: |
129-
echo "STORE_ADMIN_URL=$(azd env get-value SERVICE_STORE_ADMIN_ENDPOINT_URL)" >> "$GITHUB_OUTPUT"
130-
echo "STORE_FRONT_URL=$(azd env get-value SERVICE_STORE_FRONT_ENDPOINT_URL)" >> "$GITHUB_OUTPUT"
131-
132-
- name: Install Playwright dependencies
133-
run: npm ci
134-
working-directory: tests
135-
136-
- name: Wait for services to be ready
137-
run: |
138-
STORE_FRONT_URL="${{ steps.azd_get_endpoint_urls.outputs.STORE_FRONT_URL }}"
139-
echo "Waiting for store-front at ${STORE_FRONT_URL}..."
140-
for i in $(seq 1 30); do
141-
if curl -sf "${STORE_FRONT_URL}" > /dev/null 2>&1; then
142-
echo "Store front is responding"
143-
break
144-
fi
145-
echo "Attempt ${i}/30: Store front not ready, waiting 10s..."
146-
sleep 10
147-
done
148-
149-
echo "Waiting for order-service to be ready via ${STORE_FRONT_URL}/api/orders/health..."
150-
for i in $(seq 1 30); do
151-
if curl -sf "${STORE_FRONT_URL}/api/orders/health" > /dev/null 2>&1; then
152-
echo "Order service is responding, waiting 30s for all services to stabilize..."
153-
sleep 30
154-
break
155-
fi
156-
echo "Attempt ${i}/30: Order service not ready, waiting 10s..."
157-
sleep 10
158-
done
159-
160-
- name: Run Playwright tests
161-
run: npx playwright test --config=playwright.service.config.ts --workers=20
162-
working-directory: tests
163-
env:
164-
PLAYWRIGHT_SERVICE_URL: ${{ secrets.PLAYWRIGHT_SERVICE_URL }}
165-
PLAYWRIGHT_SERVICE_ACCESS_TOKEN: ${{ secrets.PLAYWRIGHT_SERVICE_ACCESS_TOKEN }}
166-
STORE_ADMIN_URL: ${{ steps.azd_get_endpoint_urls.outputs.STORE_ADMIN_URL }}
167-
STORE_FRONT_URL: ${{ steps.azd_get_endpoint_urls.outputs.STORE_FRONT_URL }}
168-
CI: true
169-
170-
- name: Upload Playwright report
171-
uses: actions/upload-artifact@v6
172-
if: always()
173-
with:
174-
name: playwright-report
175-
path: tests/playwright-report/
176-
retention-days: 10
177-
178-
- name: Clean up resources
179-
if: always()
180-
run: azd down --force --purge
181-
env:
182-
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
183-
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
184-
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
185-
74+
test-e2e:
75+
needs: [check-permissions, start-comment]
76+
if: needs.check-permissions.outputs.has-permission == 'true'
77+
uses: ./.github/workflows/test-e2e-reusable.yaml
78+
secrets: inherit
79+
with:
80+
deploy-from-source: true
81+
deploy-method: kustomize
82+
deploy-full-services: true
83+
pr-number: ${{ needs.check-permissions.outputs.pr-number }}
84+
85+
result-comment:
86+
needs: [check-permissions, test-e2e]
87+
if: always() && needs.check-permissions.outputs.has-permission == 'true'
88+
runs-on: ubuntu-latest
89+
steps:
18690
- name: Add status comment - Success
187-
if: success()
91+
if: needs.test-e2e.result == 'success'
18892
uses: actions/github-script@v7
18993
with:
19094
script: |
@@ -208,7 +112,7 @@ jobs:
208112
});
209113
210114
- name: Add status comment - Failure
211-
if: failure()
115+
if: needs.test-e2e.result == 'failure'
212116
uses: actions/github-script@v7
213117
with:
214118
script: |

0 commit comments

Comments
 (0)