-
Notifications
You must be signed in to change notification settings - Fork 779
131 lines (114 loc) · 5.07 KB
/
Copy pathtest-e2e-pr.yml
File metadata and controls
131 lines (114 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: test-e2e-pr
on:
issue_comment:
types: [created]
permissions:
id-token: write
contents: read
issues: write
pull-requests: write
jobs:
check-permissions:
if: github.event.issue.pull_request && contains(github.event.comment.body, '/test-e2e')
runs-on: ubuntu-latest
outputs:
has-permission: ${{ steps.check.outputs.has-permission }}
pr-number: ${{ steps.get-pr.outputs.pr-number }}
steps:
- name: Check if user has permission
id: check
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { data: collaborator } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.actor
});
const hasPermission = ['admin', 'maintain'].includes(collaborator.permission);
console.log(`User ${context.actor} has permission: ${collaborator.permission}`);
console.log(`Has required permission: ${hasPermission}`);
core.setOutput('has-permission', hasPermission);
if (!hasPermission) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `❌ @${context.actor} You don't have permission to run this command. Only repository owners and maintainers can trigger this workflow.`
});
}
- name: Get PR number
id: get-pr
if: steps.check.outputs.has-permission == 'true'
run: echo "pr-number=${PR_URL##*/}" >> "$GITHUB_OUTPUT"
env:
PR_URL: ${{ github.event.issue.pull_request.url }}
start-comment:
needs: check-permissions
if: needs.check-permissions.outputs.has-permission == 'true'
runs-on: ubuntu-latest
steps:
- name: Add status comment - Starting
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 @${context.actor} Starting E2E tests...
**Workflow Run:** [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
**Environment:** ${{ vars.AZURE_ENV_NAME }}
**Location:** ${{ vars.AZURE_LOCATION }}`
});
test-e2e:
needs: [check-permissions, start-comment]
if: needs.check-permissions.outputs.has-permission == 'true'
uses: ./.github/workflows/test-e2e-reusable.yaml
secrets: inherit
with:
deploy-from-source: true
deploy-method: kustomize
deploy-full-services: true
pr-number: ${{ needs.check-permissions.outputs.pr-number }}
result-comment:
needs: [check-permissions, test-e2e]
if: always() && needs.check-permissions.outputs.has-permission == 'true'
runs-on: ubuntu-latest
steps:
- name: Add status comment - Success
if: needs.test-e2e.result == 'success'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const startTime = new Date('${{ github.event.comment.created_at }}');
const endTime = new Date();
const duration = Math.round((endTime - startTime) / 1000 / 60); // minutes
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `✅ @${context.actor} E2E tests completed successfully!
**Workflow Run:** [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
**Duration:** ~${duration} minutes
**Status:** Passed
**Environment:** ${{ vars.AZURE_ENV_NAME }}
**Location:** ${{ vars.AZURE_LOCATION }}
All tests passed and resources have been cleaned up.`
});
- name: Add status comment - Failure
if: needs.test-e2e.result == 'failure'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `❌ @${context.actor} E2E tests failed!
**Workflow Run:** [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
**Status:** Failed
**Environment:** ${{ vars.AZURE_ENV_NAME }}
**Location:** ${{ vars.AZURE_LOCATION }}
Please check the workflow logs for details and try again.`
});