-
Notifications
You must be signed in to change notification settings - Fork 2k
310 lines (298 loc) · 12.6 KB
/
e2e.yml
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
name: End-to-end tests
on:
push:
branches: [main]
paths-ignore:
- '**.md'
- '**.d.ts'
- 'examples/**'
- 'private/**'
- 'website/**'
- '.github/**'
- '!.github/workflows/e2e.yml'
pull_request_target:
types: [opened, synchronize, reopened, labeled]
paths-ignore:
- '**.md'
- '**.d.ts'
- 'examples/**'
- 'private/**'
- 'website/**'
- '.github/**'
pull_request:
types: [opened, synchronize, reopened]
paths:
- .github/workflows/e2e.yml
concurrency:
group:
${{ github.workflow }}--${{ github.event.pull_request.head.repo.full_name ||
github.repository }} -- ${{ github.head_ref || github.ref }}
cancel-in-progress:
# For PRs coming from forks, we need the previous job to run until the end
# to be sure it can remove the `safe to test` label before it affects the next run.
${{ github.event.pull_request.head.repo.full_name == github.repository }}
permissions:
pull-requests: write
env:
YARN_ENABLE_GLOBAL_CACHE: false
jobs:
compare_diff:
runs-on: ubuntu-latest
env:
DIFF_BUILDER: true
outputs:
diff: ${{ steps.diff.outputs.OUTPUT_DIFF }}
is_accurate_diff: ${{ steps.diff.outputs.IS_ACCURATE_DIFF }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 2
ref:
${{ github.event.pull_request && format('refs/pull/{0}/merge',
github.event.pull_request.number) || github.sha }}
- name: Check if there are "unsafe" changes
id: build_chain_changes
# If there are changes in JS script that generates the output, we cannot
# test them here without human review to make sure they don't contain
# someting "nasty".
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "MIGHT_CONTAIN_OTHER_CHANGES<<$EOF" >> "$GITHUB_OUTPUT"
git --no-pager diff HEAD^ --name-only bin package.json yarn.lock babel.config.js >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- run: git reset HEAD^ --hard
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run:
echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run:
corepack yarn workspaces focus $(corepack yarn workspaces list --json
| jq -r .name | awk '/^@uppy-example/{ next } { if ($0!="uppy.io")
print $0 }')
env:
# https://docs.cypress.io/guides/references/advanced-installation#Skipping-installation
CYPRESS_INSTALL_BINARY: 0
- run: corepack yarn build:js:typeless
- name: Store output file
run: tar cf /tmp/previousVersion.tar packages/@uppy/*/lib
- name: Fetch source from the PR
if: steps.build_chain_changes.outputs.MIGHT_CONTAIN_OTHER_CHANGES == ''
run: |
git checkout FETCH_HEAD -- packages
echo 'IS_ACCURATE_DIFF=true' >> "$GITHUB_ENV"
- name: Fetch source from the PR
if:
steps.build_chain_changes.outputs.MIGHT_CONTAIN_OTHER_CHANGES != '' &&
(!github.event.pull_request || (github.event.action == 'labeled' &&
github.event.label.name == 'safe to test' &&
github.event.pull_request.state == 'open') ||
(github.event.pull_request.head.repo.full_name == github.repository &&
github.event.event_name != 'labeled'))
run: |
git reset FETCH_HEAD --hard
corepack yarn workspaces focus $(\
corepack yarn workspaces list --json | \
jq -r .name | \
awk '/^@uppy-example/{ next } { if ($0!="uppy.io") print $0 }'\
)
echo 'IS_ACCURATE_DIFF=true' >> "$GITHUB_ENV"
env:
# https://docs.cypress.io/guides/references/advanced-installation#Skipping-installation
CYPRESS_INSTALL_BINARY: 0
- name: Fetch source from the PR
if:
steps.build_chain_changes.outputs.MIGHT_CONTAIN_OTHER_CHANGES != '' &&
github.event.pull_request.head.repo.full_name != github.repository &&
(github.event.action != 'labeled' || github.event.label.name != 'safe
to test')
run: |
git checkout FETCH_HEAD -- packages
- run: corepack yarn build:js:typeless
- name: Store output file
run: tar cf /tmp/newVersion.tar packages/@uppy/*/lib
- name: Setup git
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git init /tmp/uppy
echo '*.map' > /tmp/uppy/.gitignore
- name: Install dformat
run: |
curl -fsSL https://dprint.dev/install.sh | sh
cd /tmp/uppy && echo '{"plugins":[]}' > dprint.json && "$HOME/.dprint/bin/dprint" config add typescript
- name: Extract previous version
run: cd /tmp/uppy && tar xf /tmp/previousVersion.tar
- name: Format previous output code
run: cd /tmp/uppy && "$HOME/.dprint/bin/dprint" fmt **/*.js
- name: Commit previous version
run: cd /tmp/uppy && git add -A . && git commit -m 'previous version'
- name: Extract new version
run: cd /tmp/uppy && tar xf /tmp/newVersion.tar
- name: Format new output code
run: cd /tmp/uppy && "$HOME/.dprint/bin/dprint" fmt **/*.js
- name: Build diff
id: diff
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "OUTPUT_DIFF<<$EOF" >> "$GITHUB_OUTPUT"
cd /tmp/uppy && git --no-pager diff >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
echo "IS_ACCURATE_DIFF=$IS_ACCURATE_DIFF" >> "$GITHUB_OUTPUT"
- name: Add/update comment
if: github.event.pull_request
uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
<details><summary>Diff output files</summary>
```diff
${{ steps.diff.outputs.OUTPUT_DIFF || 'No diff' }}
```
${{ env.IS_ACCURATE_DIFF != 'true' && format(fromJson('"The following build files have been modified and might affect the actual diff:\n\n```\n{0}\n```"'), steps.build_chain_changes.outputs.MIGHT_CONTAIN_OTHER_CHANGES) || '' }}
</details>
- name: Remove 'safe to test' label if cancelled
if:
cancelled() && github.event.pull_request &&
github.event.pull_request.head.repo.full_name != github.repository
run: gh pr edit "$NUMBER" --remove-label 'safe to test'
env:
NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
toggle-pending-e2e-label:
# Add the 'pending end-to-end tests' label for PRs that come from forks.
# For those PRs, we want to review the code before running e2e tests.
# See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/.
needs: [compare_diff]
if:
github.event.pull_request.state == 'open' &&
github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- name: Add label
if:
(needs.compare_diff.outputs.diff != '' ||
!needs.compare_diff.outputs.is_accurate_diff) && (github.event.action
!= 'labeled' || github.event.label.name != 'safe to test')
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
gh pr edit "$PR_URL" --repo ${{ github.repository }} --add-label
'pending end-to-end tests'
- name: Remove label
if:
needs.compare_diff.outputs.diff == '' &&
needs.compare_diff.outputs.is_accurate_diff && github.event.action ==
'labeled' && github.event.label.name == 'safe to test'
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
gh pr edit "$PR_URL" --remove-label 'safe to test' --remove-label
'pending end-to-end tests'
e2e:
needs: [compare_diff]
if:
${{ needs.compare_diff.outputs.diff != '' && (!github.event.pull_request
|| (github.event.action == 'labeled' && github.event.label.name == 'safe
to test' && github.event.pull_request.state == 'open') ||
(github.event.pull_request.head.repo.full_name == github.repository &&
github.event.event_name != 'labeled')) }}
name: Browser tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run:
echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Create cache folder for Cypress
id: cypress-cache-dir-path
run: echo "dir=$(mktemp -d)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: ${{ steps.cypress-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-cypress
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Start Redis
uses: supercharge/redis-github-action@ea9b21c6ecece47bd99595c532e481390ea0f044 # 1.8.0
with:
redis-version: 7
- name: Install dependencies
run: corepack yarn install --immutable
env:
# https://docs.cypress.io/guides/references/advanced-installation#Binary-cache
CYPRESS_CACHE_FOLDER: ${{ steps.cypress-cache-dir-path.outputs.dir }}
- name: Build Uppy packages
run: corepack yarn build
- name: Run end-to-end browser tests
run: corepack yarn run e2e:ci
env:
COMPANION_DATADIR: ./output
COMPANION_DOMAIN: localhost:3020
COMPANION_PROTOCOL: http
COMPANION_REDIS_URL: redis://localhost:6379
COMPANION_UNSPLASH_KEY: ${{secrets.COMPANION_UNSPLASH_KEY}}
COMPANION_UNSPLASH_SECRET: ${{secrets.COMPANION_UNSPLASH_SECRET}}
COMPANION_AWS_KEY: ${{secrets.COMPANION_AWS_KEY}}
COMPANION_AWS_SECRET: ${{secrets.COMPANION_AWS_SECRET}}
COMPANION_AWS_BUCKET: ${{secrets.COMPANION_AWS_BUCKET}}
COMPANION_AWS_REGION: ${{secrets.COMPANION_AWS_REGION}}
VITE_COMPANION_URL: http://localhost:3020
VITE_TRANSLOADIT_KEY: ${{secrets.TRANSLOADIT_KEY}}
VITE_TRANSLOADIT_SECRET: ${{secrets.TRANSLOADIT_SECRET}}
VITE_TRANSLOADIT_TEMPLATE: ${{secrets.TRANSLOADIT_TEMPLATE}}
VITE_TRANSLOADIT_SERVICE_URL: ${{secrets.TRANSLOADIT_SERVICE_URL}}
# https://docs.cypress.io/guides/references/advanced-installation#Binary-cache
CYPRESS_CACHE_FOLDER: ${{ steps.cypress-cache-dir-path.outputs.dir }}
- name: Upload videos in case of failure
uses: actions/upload-artifact@v4
if: failure()
with:
name: videos-and-screenshots
path: |
e2e/cypress/videos/
e2e/cypress/screenshots/
- name: Remove labels
# Remove the 'pending end-to-end tests' label if tests ran successfully
if:
github.event.pull_request &&
contains(github.event.pull_request.labels.*.name, 'pending end-to-end
tests')
run: gh pr edit "$NUMBER" --remove-label 'pending end-to-end tests'
env:
NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove 'safe to test' label
if:
always() && github.event.pull_request &&
contains(github.event.pull_request.labels.*.name, 'safe to test')
run: gh pr edit "$NUMBER" --remove-label 'safe to test'
env:
NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}