Repository navigation
242 lines (233 loc) · 10.2 KB
/
Copy pathci.yml
File metadata and controls
242 lines (233 loc) · 10.2 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
name: CI
# Every pull request and push to main tests, in Chromium, the packages it changes and those that
# depend on them, the heaviest each in a job of its own so they run side by side. The weekly run,
# and a run by hand before a release, test everything: every package, the player's slow browser
# files, Firefox and WebKit, and the VS Code extension in a real editor. A change to the docs alone
# starts no run.
on:
push:
branches:
- main
paths-ignore:
- 'design/**'
- 'docs/**'
- '*.md'
- LICENSE
pull_request:
branches:
- main
paths-ignore:
- 'design/**'
- 'docs/**'
- '*.md'
- LICENSE
# Everything, and the week's caches saved on main, which pull requests restore.
schedule:
- cron: '0 5 * * 1'
workflow_dispatch:
permissions:
contents: read
env:
# The player's browser files that wait out real time run weekly and by hand only
# (packages/player/vite.config.ts).
H5P_TEST_SKIP_SLOW: ${{ (github.event_name != 'schedule' && github.event_name != 'workflow_dispatch') && '1' || '' }}
jobs:
# What the run tests, as lanes: the player, the verifier, the skills and the embed package, most
# of the time, each in a job of its own, and the rest in one more. A pull request or a push picks
# the packages it changes and those that depend on them, as pnpm's `...[<commit>]` reads the
# change. A file outside packages/, apps/ and skills/ that is not docs (the lockfile, a workflow,
# the root's package.json) picks every package: what it reaches cannot be read off its path. The
# weekly run and a run by hand pick every package.
scope:
runs-on: ubuntu-latest
outputs:
lanes: ${{ steps.scope.outputs.lanes }}
demo: ${{ steps.scope.outputs.demo }}
vscode: ${{ steps.scope.outputs.vscode }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 2
- uses: pnpm/action-setup@v6
# bash by name, which adds pipefail: a pnpm that fails must fail the run, not pick nothing.
- id: scope
shell: bash
env:
EVENT: ${{ github.event_name }}
BEFORE: ${{ github.event.before }}
run: |
all=false; weekly=false; base=; changed=
case "$EVENT" in
# A pull request's run checks out the merge commit, whose first parent is main.
pull_request) base=HEAD^1 ;;
# Where main was before the push; a new or forced branch may have nothing to compare.
push) if git fetch -q --depth=1 origin "$BEFORE"; then base=$BEFORE; else all=true; fi ;;
*) all=true; weekly=true ;;
esac
if [ -n "$base" ]; then
changed=$(git diff --name-only "$base" HEAD)
if grep -qvE '^(packages|apps|skills|design|docs)/|^[^/]+\.md$|^LICENSE$' <<< "$changed"; then all=true; fi
fi
# pnpm counts a file outside the packages as the root's, whose test script tests them all.
names() { pnpm "$@" ls --depth -1 --json | jq -r --arg root "$PWD" '.[] | select(.path != $root) | .name'; }
if [ "$all" = true ]; then
picked=$(names -r)
else
picked=$(names --filter "...[$base]")
# The skills are tested from apps/skills, and h5p-author's ships in the author package.
if grep -q '^skills/' <<< "$changed"; then
picked=$(printf '%s\n' $picked @missing-elements/h5p-author @missing-elements/h5p-skills)
fi
fi
lanes=$(printf '%s\n' $picked | jq -Rsc '
(split("\n") | map(select(. != "")) | unique) as $picked
| ["@missing-elements/h5p-offline-player", "@missing-elements/h5p-verify",
"@missing-elements/h5p-skills", "@missing-elements/h5p-embed"] as $heavy
| [$heavy[] | select(IN($picked[])) | {name: sub("@missing-elements/h5p-(offline-)?"; ""), select: "--filter \(.)"}]
+ ([$picked[] | select(IN($heavy[]) | not)]
| if length > 0 then [{name: "other", select: (map("--filter \(.)") | join(" "))}] else [] end)')
demo=false
if grep -qx @missing-elements/h5p-demo <<< "$picked"; then demo=true; fi
vscode=$weekly
if grep -q '^packages/vscode/' <<< "$changed"; then vscode=true; fi
printf '%s\n' "lanes=$lanes" "demo=$demo" "vscode=$vscode" | tee -a "$GITHUB_OUTPUT"
# What the packages share: the demo built as Vercel builds it, every type check, the player's
# build.
checks:
needs: scope
if: needs.scope.outputs.lanes != '[]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# The demo first, from a checkout with nothing built, as Vercel builds it. Run after `pnpm
# build`, it found the player's dist/ there, and passed while the deploy of #123 failed.
- if: needs.scope.outputs.demo == 'true'
run: pnpm build:demo
# Every package that has a type check, whatever the change: each one's check writes the
# types the packages after it read.
- run: pnpm typecheck
- run: pnpm build
# The tests in Chromium, a lane per job. Each package's test script builds what it needs.
test:
name: test (${{ matrix.lane.name }})
needs: scope
if: needs.scope.outputs.lanes != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
lane: ${{ fromJSON(needs.scope.outputs.lanes) }}
steps:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# Without --with-deps: the runner image ships Chrome and Firefox, so the libraries they link
# against are there, and what apt would add (fonts, Xvfb, FFmpeg's codecs) a headless suite that
# decodes no video does not use. Some runners reach Ubuntu's mirror at 40 kB/s, where that took
# up to 20 minutes (#73).
- run: pnpm --filter @missing-elements/h5p-offline-player exec playwright install chromium
- run: pnpm $SELECT --workspace-concurrency=1 test
env:
SELECT: ${{ matrix.lane.select }}
# The player's browser suite and the installable app's tests in the other two engines, weekly and
# by hand. One engine per job: the dev server's switches are shared, and two engines would flip
# them under each other. Firefox stops a worker that has no event for thirty seconds and checks
# the scripts the worker makes up by the worker's URL; WebKit drops the cache writes of a worker
# terminated just after them — each found here first.
engines:
name: browser suite (${{ matrix.browser }})
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
H5P_TEST_BROWSER: ${{ matrix.browser }}
strategy:
fail-fast: false
matrix:
browser: [firefox, webkit]
# WebKit needs its system packages, GStreamer among them. Firefox, like Chromium, has its
# libraries from the runner image.
include:
- browser: webkit
deps: --with-deps
steps:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# WebKit's packages are 117 MB from Ubuntu's mirror, which some runners reach at 40 kB/s (#77).
# apt keeps what it fetches in its archive folder, cached here, so a run fetches only what
# Ubuntu has updated since. The folder is made writable for the restore, which runs as the
# runner's user; a new key each week keeps the cache from going stale.
- if: matrix.deps
id: apt
run: |
sudo chmod a+w /var/cache/apt/archives
echo "week=$(date -u +%G-%V)" >> "$GITHUB_OUTPUT"
- if: matrix.deps
uses: actions/cache@v6
with:
path: /var/cache/apt/archives/*.deb
key: apt-${{ matrix.browser }}-${{ steps.apt.outputs.week }}
restore-keys: apt-${{ matrix.browser }}-
# Playwright installs WebKit's packages through apt. Retry transient Ubuntu mirror failures.
- run: |
for attempt in 1 2 3; do
if pnpm --filter @missing-elements/h5p-offline-player exec playwright install ${{ matrix.deps }} ${{ matrix.browser }}; then
exit 0
fi
if [ "$attempt" -lt 3 ]; then
echo "Browser installation failed; retrying in 30 seconds ($attempt/3)."
sleep 30
fi
done
exit 1
# Drops the versions Ubuntu has since replaced, so the cache holds one copy of each package
# rather than every week's.
- if: matrix.deps
run: sudo apt-get autoclean
- run: pnpm test:engine
# The VS Code extension in a real VS Code, on a display Xvfb gives it, and the .vsix the owner
# publishes, built from what the tests ran against: weekly, by hand, and when packages/vscode
# changes. Its unit tests run with the other packages'.
vscode:
name: VS Code extension
needs: scope
if: needs.scope.outputs.vscode == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# The player and the runtime, which the extension carries.
- run: pnpm build
# The editor the tests download, about 150 MB, a new stable a month: kept a week at a time.
- id: week
run: echo "week=$(date -u +%G-%V)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v6
with:
path: packages/vscode/.vscode-test
key: vscode-test-${{ steps.week.outputs.week }}
restore-keys: vscode-test-
- run: xvfb-run -a pnpm --filter h5p-preview test:vscode
- run: pnpm --filter h5p-preview package
- uses: actions/upload-artifact@v4
with:
name: h5p-preview-vsix
path: packages/vscode/*.vsix