Repository navigation
148 lines (135 loc) · 7.65 KB
/
Copy pathlibraries.yml
File metadata and controls
148 lines (135 loc) · 7.65 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
name: Library pack
# Rebuilds packages/libraries from the H5P hub every week and opens a pull request when a library
# changed, saying whether every content type and h5p-author's examples play against it. The pack is
# built deterministically, in any time zone, so an unchanged hub leaves the tree clean.
on:
schedule:
- cron: '0 6 * * 1'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
concurrency:
group: library-pack
cancel-in-progress: false
jobs:
refresh:
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
- run: pnpm libraries
- name: Open a pull request if a library changed
env:
GH_TOKEN: ${{ github.token }}
run: |
if git diff --quiet -- packages/libraries; then
echo "The hub has not changed."
exit 0
fi
branch=libraries/refresh
# Every library's line, `<folder> <version> <licence>`, FontAwesome and jQuery.ui among them.
changes=$(git diff -U0 -- packages/libraries/libraries.txt | grep -E '^[-+][A-Za-z][^ ]*-[0-9]+\.[0-9]+ ' | sort -k1.2 || true)
if [ -z "$changes" ]; then
# The files changed and no library's version, licence or authors did: the build is not
# deterministic, as it was once in the builder's time zone (#51), or the hub changed a
# library's files without a new version. Either way a pull request would say the hub
# changed when no library did.
echo "::error::The pack's files changed, but no library in libraries.txt did. Rebuild with pnpm libraries and compare the archives' entries before releasing anything."
git status --short -- packages/libraries | head -20
exit 1
fi
# The same for one part: a part whose library did not change is written as it was, so a
# new hash would make every browser download it again and give every package played
# with it a new revision, for no library's sake (#116).
stray=""
for part in $(git diff --name-only -- packages/libraries/parts | sed -n 's|^packages/libraries/parts/\(.*\)\.h5p$|\1|p'); do
case "$changes" in
*"+$part "* | *"-$part "*) ;;
*) stray="$stray $part" ;;
esac
done
if [ -n "$stray" ]; then
echo "::error::These parts changed, but their libraries in libraries.txt did not:$stray. Compare the archives' entries before releasing anything."
exit 1
fi
version=$(node -e "
const fs = require('fs'), path = 'packages/libraries/package.json'
const pkg = JSON.parse(fs.readFileSync(path, 'utf8'))
const [major, minor, patch] = pkg.version.split('.').map(Number)
pkg.version = [major, minor, patch + 1].join('.')
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\\n')
console.log(pkg.version)")
# The player's libraries="pack" pins this version and carries its parts' index: stamp
# both in the same change.
pnpm --filter @missing-elements/h5p-offline-player sync:assets
# The h5p-author skill's type files list each content type's fields from the pack.
pnpm --filter @missing-elements/h5p-author sync:skill
# Every content type played against the new pack, for the review: CI does not start on
# a pull request a workflow opened, so the result goes into its description.
pnpm build > /dev/null
if pnpm sweep --out "$RUNNER_TEMP/sweep" > "$RUNNER_TEMP/sweep.log" 2>&1; then
sweep="Every content type plays against the new pack, untrusted and trusted (\`pnpm sweep\`)."
else
sweep="**Some content types fail against the new pack** (\`pnpm sweep\`): see the report below."
fi
report=$(cat "$RUNNER_TEMP/sweep/report.md" 2>/dev/null || tail -n 30 "$RUNNER_TEMP/sweep.log")
# h5p-author against the new pack, for the same reason: its own tests, then every type
# file's example built and played, untrusted and trusted (apps/skills), which is where a
# library's renamed, new or hidden field shows. The playback test drives Playwright's
# Chromium.
pnpm --filter @missing-elements/h5p-offline-player exec playwright install chromium > /dev/null
author_ok=true
NO_COLOR=1 pnpm --filter @missing-elements/h5p-author test > "$RUNNER_TEMP/author.log" 2>&1 || author_ok=false
NO_COLOR=1 pnpm --filter @missing-elements/h5p-skills test >> "$RUNNER_TEMP/author.log" 2>&1 || author_ok=false
if $author_ok; then
author="h5p-author builds and plays every type file's example against the new pack, untrusted and trusted, and its own tests pass."
author_details=""
else
author="**h5p-author fails against the new pack**: fix the type file, its example or \`packages/author/lib/types.mjs\` on this branch. The tests' output is below."
author_details=$(printf '%s\n' "<details><summary>h5p-author's tests</summary>" "" '```' "$(tail -n 120 "$RUNNER_TEMP/author.log" | sed -e 's/\x1b\[[0-9;]*m//g')" '```' "" "</details>")
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git switch -C "$branch"
git add packages/libraries packages/player/src/shared/constants.ts packages/player/src/shared/pack-index.ts skills/h5p-author/references/types
git commit -m "chore(libraries): refresh from the H5P hub, $version"
git push --force origin "$branch"
body=$(printf '%s\n' \
"The weekly rebuild of the library pack found changes on the H5P hub." \
"" \
"Before merging: play a package exported without its libraries against the new pack:" \
"" \
"\`pnpm verify <package> --libraries https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$branch/packages/libraries/libraries.h5p\`" \
"" \
"Then push to this branch, or close and reopen the pull request, to run CI: it does not start on a pull" \
"request opened by a workflow. After merging, publish \`@missing-elements/h5p-libraries\`" \
"$version with pnpm, before the next player release: the player's \`libraries=\"pack\"\` now names it," \
"and its prepublishOnly refuses a pack version that is not on npm." \
"" \
'```diff' "$changes" '```' \
"" \
"$sweep" \
"" \
"$author" \
"" \
"<details><summary>The sweep's report</summary>" \
"" \
"$report" \
"" \
"</details>" \
"" \
"$author_details")
if gh pr view "$branch" --json state --jq .state 2>/dev/null | grep -q OPEN; then
gh pr edit "$branch" --title "Library pack $version" --body "$body"
elif ! gh pr create --base main --head "$branch" --title "Library pack $version" --body "$body"; then
# Opening a pull request needs "Allow GitHub Actions to create and approve pull
# requests" in the repository's Actions settings; without it the branch is still pushed.
echo "::warning::Could not open the pull request. Open it from $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/main...$branch"
printf '%s\n' "$body" >> "$GITHUB_STEP_SUMMARY"
fi