Skip to content

Commit 583efe7

Browse files
committed
feat(workflow): AZD deployment testing on PR
1 parent 08c27e8 commit 583efe7

5 files changed

Lines changed: 163 additions & 4 deletions

File tree

.github/workflows/audit-bicep.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Scan Bicep code
1+
name: audit-bicep
22
on:
33
push:
44
branches:

.github/workflows/audit-terraform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# separate terms of service, privacy policy, and support
44
# documentation.
55

6-
name: Scan Terraform code
6+
name: audit-terraform
77

88
on:
99
push:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# composite workflow to test the azd deployment of the app
22
# uses a github federated identity
3-
name: Test AZD Deployment
3+
name: test-e2e-main
44

55
on:
66
push:

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

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

.github/workflows/test-playwright.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Playwright Tests
1+
name: test-playwright
22

33
on:
44
workflow_call:

0 commit comments

Comments
 (0)