-
Notifications
You must be signed in to change notification settings - Fork 304
247 lines (215 loc) Β· 9.11 KB
/
precommit-crit-flows.yml
File metadata and controls
247 lines (215 loc) Β· 9.11 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: precommit-crit-flows
on:
pull_request:
branches: [dev]
merge_group:
branches: [dev]
# One at a time lane for the shared precommit environment
concurrency:
group: precommit-deploy
cancel-in-progress: false # queue newer runs
jobs:
build:
# Skip entire job for Dependabot PRs
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'dependabot' }}
runs-on: buildjet-8vcpu-ubuntu-2204
timeout-minutes: 20
outputs:
unit_tests_report: ${{ env.UNIT_TEST_REPORT_FILE }}
build_artifact: ${{ env.BUILD_ARTIFACT }}
total_additions: ${{ steps.check_additions.outputs.total_additions }}
commit_url: ${{ steps.meta.outputs.commit_url }}
committer: ${{ steps.meta.outputs.committer }}
env:
BUILD_DIR: apps/server/dist/s3/
BUILD_ARTIFACT: ebs.zip
CHANGELOG_FILE: ./changelog.md
UNIT_TEST_REPORT_FILE: ./unit-tests.log
steps:
- name: Checkout (pull_request)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout (merge_group)
if: ${{ github.event_name == 'merge_group' }}
uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- run: yarn --immutable
- run: yarn nx run webapp:configure
- run: yarn nx run server:package
- name: Derive PR commit metadata
id: meta
run: |
SHA="${{ github.event.pull_request.head.sha || github.sha }}"
COMMIT_URL="https://github.com/${{ github.repository }}/commit/$SHA"
AUTHOR="$(git show -s --format='%an' "$SHA" || true)"
echo "COMMIT_URL=$COMMIT_URL" >> "$GITHUB_ENV"
echo "COMMITTER=$AUTHOR" >> "$GITHUB_ENV"
echo "commit_url=$COMMIT_URL" >> "$GITHUB_OUTPUT"
echo "committer=$AUTHOR" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v7
with:
name: build-artifact
path: ${{ env.BUILD_DIR }}${{ env.BUILD_ARTIFACT }}
- name: Check total PR additions
if: ${{ github.event_name == 'pull_request' }}
id: check_additions
run: |
total_additions=$(gh api -H "Accept: application/vnd.github.v3+json" \
"repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r '.additions')
test -n "$total_additions" -a "$total_additions" != null
echo "Found total additions: $total_additions"
echo "total_additions=$total_additions" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy_to_aws:
name: Deploy to precommit
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'dependabot' }}
runs-on: ubuntu-latest
needs: [build]
timeout-minutes: 25
outputs:
precommit_url: ${{ steps.fetch_url.outputs.url }}
steps:
- uses: actions/download-artifact@v8
with:
name: build-artifact
- name: Deploy to precommit environment
id: deploy
uses: einaregilsson/beanstalk-deploy@27edd8a0ebe8656ac70654372c73f06f7e9a1027 # v22
with:
application_name: Webapp
aws_access_key: ${{ secrets.WEBTEAM_AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.WEBTEAM_AWS_SECRET_ACCESS_KEY }}
deployment_package: ${{ needs.build.outputs.build_artifact }}
environment_name: wire-webapp-precommit
region: eu-central-1
use_existing_version_if_available: true
version_description: ${{ needs.build.outputs.committer }} β ${{ needs.build.outputs.commit_url }}
version_label: ${{ github.run_id }}
wait_for_deployment: true # β
wait until EB is green
- name: Fetch precommit URL
id: fetch_url
run: |
URL=$(aws elasticbeanstalk describe-environments \
--region eu-central-1 \
--environment-names wire-webapp-precommit \
--query "Environments[0].CNAME" --output text)
echo "url=https://$URL" >> "$GITHUB_OUTPUT"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.WEBTEAM_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.WEBTEAM_AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
- name: Deployment Status
if: ${{ always() }}
run: |
if [[ "${{ steps.deploy.outcome }}" == "success" ]]; then
echo "β
Deployment completed successfully"
else
echo "β Deployment failed"; exit 1
fi
# An extra step is needed to see if the e2e_tests folder was touched as part of the PR
check_edits_to_e2e_tests:
name: Check if the PR touches e2e tests
runs-on: ubuntu-latest
outputs:
tests_to_run: ${{ steps.check_e2e_tests.outputs.tests_to_run || steps.set_default_tests_for_merge_queue.outputs.tests_to_run }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for e2e tests changes
if: ${{ github.event_name == 'pull_request' }}
id: check_e2e_tests
run: |
git diff --exit-code origin/${{ github.base_ref }}...HEAD -- apps/webapp/test/e2e_tests/ || RESULT=$?
# If the e2e_tests folder was touched within the PR run all tests, otherwise just the critical flow ones
if [ $RESULT -eq 1 ]; then
echo "tests_to_run=" >> $GITHUB_OUTPUT
echo "E2E Tests have been modified, executing all tests"
else
echo "tests_to_run=@crit-flow-web" >> $GITHUB_OUTPUT
echo "E2E Tests have not been modified, executing critical flow tests only"
fi
- name: Use critical flow tests on merge queue
if: ${{ github.event_name == 'merge_group' }}
id: set_default_tests_for_merge_queue
run: |
echo "tests_to_run=@crit-flow-web" >> $GITHUB_OUTPUT
echo "Merge queue run detected, executing critical flow tests"
run_e2e_tests:
name: Playwright Critical Flow (precommit)
if: ${{ !cancelled() && github.repository == 'wireapp/wire-webapp' && github.actor != 'dependabot[bot]' && github.actor != 'dependabot' }}
needs: [check_edits_to_e2e_tests, deploy_to_aws]
uses: ./.github/workflows/e2e-tests.yml
with:
webappUrl: https://wire-webapp-precommit.zinfra.io/
backendUrl: https://staging-nginz-https.zinfra.io/
grep: ${{ needs.check_edits_to_e2e_tests.outputs.tests_to_run }}
secrets:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
e2e-report:
name: Generate test report
needs: run_e2e_tests
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout (pull_request)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout (merge_group)
if: ${{ github.event_name == 'merge_group' }}
uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Download report
uses: actions/download-artifact@v8
with:
artifact-ids: ${{ needs.run_e2e_tests.outputs.reportArtifactId }}
path: apps/webapp/playwright-report
- name: Generate PR comment
if: ${{ always() && github.event_name == 'pull_request' }}
id: generate_comment
run: |
echo "Checking for Playwright report..."
ls -la apps/webapp/playwright-report/ || echo "No playwright-report directory found"
ls -la apps/webapp/playwright-report/report.json || echo "No report.json found"
# Check if report.json exists before running the script
if [ -f "apps/webapp/playwright-report/report.json" ]; then
cd apps/webapp && node --experimental-strip-types test/e2e_tests/scripts/create-playwright-report-summary.ts playwright-report && cd ../..
if [ -f apps/webapp/playwright-report-summary.txt ]; then
COMMENT=$(cat apps/webapp/playwright-report-summary.txt)
else
COMMENT="β Playwright report summary could not be generated from the report data"
fi
else
COMMENT="β No Playwright report.json found - test execution may have failed or no tests were run"
fi
echo "comment<<EOF" >> $GITHUB_OUTPUT
echo "$COMMENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Comment on PR
if: ${{ always() && github.event_name == 'pull_request' }}
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405
with:
header: playwright-summary
message: |
π [Download Full Report Artifact](${{ needs.run_e2e_tests.outputs.reportUrl }})
${{ steps.generate_comment.outputs.comment }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}