-
Notifications
You must be signed in to change notification settings - Fork 1
230 lines (205 loc) · 7.42 KB
/
e2e.yml
File metadata and controls
230 lines (205 loc) · 7.42 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: E2E
# Reusuable workflow to be called from within the oauth2-proxy source repository
on: workflow_call
jobs:
prepare:
# https://docs.github.com/en/graphql/reference/enums#commentauthorassociation
if: |
github.event.issue.pull_request &&
(github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'OWNER') &&
startsWith(github.event.comment.body, '/e2e')
name: Prepare
runs-on: ubuntu-latest
permissions:
statuses: write
issues: read
pull-requests: read
outputs:
status_sha: ${{ steps.status.outputs.status_sha }}
mode: ${{ steps.origin.outputs.mode }}
branch: ${{ steps.origin.outputs.branch || '' }}
pr_number: ${{ steps.origin.outputs.pr_number || '' }}
steps:
- name: Add status to PR
id: status
uses: actions/github-script@v6
with:
script: |
try {
const sha = ${{ github.event.issue.number }} ?
(await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ github.event.issue.number }}
})).data.head.sha :
context.sha;
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: sha,
state: 'pending',
context: 'E2E Tests',
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
description: '⏳ E2E tests running...'
});
core.setOutput('status_sha', sha);
} catch (error) {
core.setFailed(`Failed to set status: ${error.message}`);
}
- name: Determine checkout origin
id: origin
run: |
COMMENT="${{ github.event.comment.body }}"
if [[ "$COMMENT" == "/e2e PR-"* && "$COMMENT" =~ PR-([0-9]+) ]]; then
PR_NUMBER="${BASH_REMATCH[1]}"
echo "mode=pr" >> $GITHUB_OUTPUT
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
elif [[ "$COMMENT" == "/e2e "* ]]; then
BRANCH=${COMMENT#/e2e }
echo "mode=branch" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
else
echo "mode=default" >> $GITHUB_OUTPUT
fi
build-test-image:
name: Build test image
runs-on: ubuntu-latest
needs: prepare
outputs:
image-digest: ${{ steps.get-digest.outputs.digest }}
permissions:
contents: read
steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/merge
- name: Build image
run: |
make build-docker-local
docker save -o e2e-image.tar quay.io/oauth2-proxy/oauth2-proxy:latest
- name: Get image digest
id: get-digest
run: |
digest=$(docker inspect --format='{{.Id}}' quay.io/oauth2-proxy/oauth2-proxy:latest)
echo "digest=$digest" >> $GITHUB_OUTPUT
- name: Upload image
uses: actions/upload-artifact@v4
with:
name: oauth2-proxy-e2e-image
path: ./e2e-image.tar
retention-days: 1
run-e2e:
name: E2E tests
needs:
- prepare
- build-test-image
permissions:
contents: read
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test-suite:
- 01_smoke
- 02_keycloak
steps:
- name: Fetch test image
uses: actions/download-artifact@v4
with:
name: oauth2-proxy-e2e-image
- name: Load image
run: |
docker load -i e2e-image.tar
- name: Verify image
run: |
docker image inspect quay.io/oauth2-proxy/oauth2-proxy:latest
# Verify the digest matches the built image
current_digest=$(docker inspect --format='{{.Id}}' quay.io/oauth2-proxy/oauth2-proxy:latest)
if [ "$current_digest" != "${{ needs.build-test-image.outputs.image-digest }}" ]; then
echo "Image digest mismatch!"
exit 1
fi
- name: Checkout e2e tests (main)
if: needs.prepare.outputs.mode == 'default'
uses: actions/checkout@v4
with:
repository: oauth2-proxy/e2e-suite
- name: Checkout e2e tests (branch)
if: needs.prepare.outputs.mode == 'branch'
uses: actions/checkout@v4
with:
repository: oauth2-proxy/e2e-suite
ref: ${{ needs.prepare.outputs.branch }}
- name: Checkout e2e tests (PR)
if: needs.prepare.outputs.mode == 'pr'
uses: actions/checkout@v4
with:
repository: oauth2-proxy/e2e-suite
ref: refs/pull/${{ needs.prepare.outputs.pr_number }}/merge
- name: Set up Docker Compose
uses: docker/setup-compose-action@v1
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install Playwright dependencies
run: go run github.com/playwright-community/playwright-go/cmd/playwright@latest install --with-deps chromium
- name: E2E Testing
run: |
make test-${{ matrix.test-suite }}
status-update:
name: Status update
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request &&
(github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'OWNER') &&
startsWith(github.event.comment.body, '/e2e') && always()
needs:
- prepare
- run-e2e
permissions:
statuses: write
issues: write
pull-requests: write
steps:
- name: Write E2E test results to PR
uses: actions/github-script@v7
with:
script: |
const conclusion = "${{ needs.run-e2e.result }}" === 'success';
const label = conclusion ? 'e2e/passed' : 'e2e/failed';
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ needs.prepare.outputs.status_sha }}',
state: conclusion ? 'success' : 'failure',
context: 'E2E Tests',
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
description: conclusion ? '✅ E2E tests passed' : '❌ E2E tests failed'
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: '${{ github.event.issue.number }}',
labels: [label]
});
const oppositeLabel = conclusion ? 'e2e/failed' : 'e2e/passed';
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: '${{ github.event.issue.number }}',
name: oppositeLabel
}).catch(() => {
// Ignore if label doesnt exist
});
} catch (error) {
core.warning(`Failed to update labels: ${error}`);
}
// Fail the job if tests failed
if (!conclusion) {
core.setFailed('E2E tests failed');
}