Skip to content

Commit 2f85520

Browse files
committed
ci: add workflow for end-to-end pr testing
1 parent 6cc093e commit 2f85520

1 file changed

Lines changed: 191 additions & 0 deletions

File tree

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

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: test-e2e-pr
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
permissions:
8+
id-token: write
9+
contents: read
10+
issues: write
11+
pull-requests: write
12+
13+
jobs:
14+
check-permissions:
15+
if: github.event.issue.pull_request && contains(github.event.comment.body, '/test-e2e')
16+
runs-on: ubuntu-latest
17+
outputs:
18+
has-permission: ${{ steps.check.outputs.has-permission }}
19+
steps:
20+
- name: Check if user has permission
21+
id: check
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
const { data: collaborator } = await github.rest.repos.getCollaboratorPermissionLevel({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
username: context.actor
29+
});
30+
31+
const hasPermission = ['admin', 'maintain'].includes(collaborator.permission);
32+
console.log(`User ${context.actor} has permission: ${collaborator.permission}`);
33+
console.log(`Has required permission: ${hasPermission}`);
34+
35+
core.setOutput('has-permission', hasPermission);
36+
37+
if (!hasPermission) {
38+
github.rest.issues.createComment({
39+
issue_number: context.issue.number,
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
body: `❌ @${context.actor} You don't have permission to run this command. Only repository owners and maintainers can trigger this workflow.`
43+
});
44+
}
45+
46+
test-e2e:
47+
needs: check-permissions
48+
if: needs.check-permissions.outputs.has-permission == 'true'
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Add status comment - Starting
52+
uses: actions/github-script@v7
53+
with:
54+
script: |
55+
github.rest.issues.createComment({
56+
issue_number: context.issue.number,
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
body: `🚀 @${context.actor} Starting E2E tests...
60+
61+
**Workflow Run:** [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
62+
**Environment:** ${{ vars.AZURE_ENV_NAME }}
63+
**Location:** ${{ vars.AZURE_LOCATION }}`
64+
});
65+
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: Provision resources and deploy app
106+
run: |
107+
azd env new ${{ vars.AZURE_ENV_NAME }}
108+
azd env set AKS_NODE_POOL_VM_SIZE Standard_D2_v4
109+
azd env set DEPLOY_AZURE_CONTAINER_REGISTRY true
110+
azd env set DEPLOY_AZURE_OPENAI true
111+
azd env set AZURE_OPENAI_LOCATION ${{ vars.AZURE_LOCATION }}
112+
azd env set DEPLOY_AZURE_OPENAI_DALL_E_MODEL false
113+
azd env set DEPLOY_AZURE_SERVICE_BUS true
114+
azd env set DEPLOY_AZURE_COSMOSDB true
115+
azd env set AZURE_COSMOSDB_ACCOUNT_KIND MongoDB
116+
azd env set DEPLOY_OBSERVABILITY_TOOLS true
117+
azd up
118+
env:
119+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
120+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
121+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
122+
123+
- name: Get endpoint URLs
124+
id: azd_get_endpoint_urls
125+
run: |
126+
echo "STORE_ADMIN_URL=$(azd env get-value SERVICE_STORE_ADMIN_ENDPOINT_URL)" >> "$GITHUB_OUTPUT"
127+
echo "STORE_FRONT_URL=$(azd env get-value SERVICE_STORE_FRONT_ENDPOINT_URL)" >> "$GITHUB_OUTPUT"
128+
129+
- name: Install Playwright dependencies
130+
run: npm ci
131+
working-directory: tests
132+
133+
- name: Run Playwright tests
134+
run: npx playwright test --config=playwright.service.config.ts --workers=20
135+
working-directory: tests
136+
env:
137+
PLAYWRIGHT_SERVICE_URL: ${{ secrets.PLAYWRIGHT_SERVICE_URL }}
138+
STORE_ADMIN_URL: ${{ steps.azd_get_endpoint_urls.outputs.STORE_ADMIN_URL }}
139+
STORE_FRONT_URL: ${{ steps.azd_get_endpoint_urls.outputs.STORE_FRONT_URL }}
140+
CI: true
141+
142+
- name: Clean up resources
143+
if: always()
144+
run: azd down --force --purge
145+
env:
146+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
147+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
148+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
149+
150+
- name: Add status comment - Success
151+
if: success()
152+
uses: actions/github-script@v7
153+
with:
154+
script: |
155+
const startTime = new Date('${{ github.event.comment.created_at }}');
156+
const endTime = new Date();
157+
const duration = Math.round((endTime - startTime) / 1000 / 60); // minutes
158+
159+
github.rest.issues.createComment({
160+
issue_number: context.issue.number,
161+
owner: context.repo.owner,
162+
repo: context.repo.repo,
163+
body: `✅ @${context.actor} E2E tests completed successfully!
164+
165+
**Workflow Run:** [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
166+
**Duration:** ~${duration} minutes
167+
**Status:** Passed
168+
**Environment:** ${{ vars.AZURE_ENV_NAME }}
169+
**Location:** ${{ vars.AZURE_LOCATION }}
170+
171+
All tests passed and resources have been cleaned up.`
172+
});
173+
174+
- name: Add status comment - Failure
175+
if: failure()
176+
uses: actions/github-script@v7
177+
with:
178+
script: |
179+
github.rest.issues.createComment({
180+
issue_number: context.issue.number,
181+
owner: context.repo.owner,
182+
repo: context.repo.repo,
183+
body: `❌ @${context.actor} E2E tests failed!
184+
185+
**Workflow Run:** [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
186+
**Status:** Failed
187+
**Environment:** ${{ vars.AZURE_ENV_NAME }}
188+
**Location:** ${{ vars.AZURE_LOCATION }}
189+
190+
Please check the workflow logs for details and try again.`
191+
});

0 commit comments

Comments
 (0)