Repository navigation
334 lines (324 loc) · 14.2 KB
/
Copy pathdependency_updates.yml
File metadata and controls
334 lines (324 loc) · 14.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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
name: Update dependencies
on:
schedule:
# Runs at 00:00 UTC on the 1st of every month
- cron: '0 0 1 * *'
# Optional: Allow manual triggering
workflow_dispatch:
permissions:
contents: read
jobs:
update-h5p:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v7.0.1
with:
ref: 'develop'
fetch-depth: 0
persist-credentials: false
- name: Get latest commit from target repo
id: get-commit
uses: octokit/request-action@v2.x
with:
route: GET /repos/{owner}/{repo}/branches/{branch}
owner: h5p
repo: h5p-php-library
branch: master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check commit status
id: check-commit
run: |
import os
from pathlib import Path
# Get the latest commit from the API response
latest_commit = "${{ fromJson(steps.get-commit.outputs.data).commit.sha }}".strip()
# Check stored commit
commit_file = Path('kolibri/plugins/h5p_viewer/h5p_build/.h5p-commit-sha')
stored_commit = ""
if commit_file.exists():
stored_commit = commit_file.read_text().strip()
has_changed = stored_commit != latest_commit
else:
print("No stored commit found, treating as new")
has_changed = True
# Set outputs for GitHub Actions
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
print(f"stored_commit={stored_commit}", file=f)
print(f"latest_commit={latest_commit}", file=f)
print(f"changed={'true' if has_changed else 'false'}", file=f)
shell: python
- name: Install pnpm
uses: pnpm/action-setup@v6.1.1
- name: Use Node.js
uses: actions/setup-node@v7
with:
node-version-file: 'package.json'
cache: 'pnpm'
- name: Install dependencies
run: |
pnpm install --frozen-lockfile
pnpm rebuild node-sass
- name: Update commit file and run script
if: steps.check-commit.outputs.changed == 'true'
run: |
# Update the commit file
echo "${{ steps.check-commit.outputs.latest_commit }}" > kolibri/plugins/h5p_viewer/h5p_build/.h5p-commit-sha
# Run your script here
pnpm --filter kolibri-h5p-viewer-plugin run build-h5p
- name: Check for actual build changes
if: steps.check-commit.outputs.changed == 'true'
id: check-build-changes
run: |
# Stage only the build output files, excluding the commit SHA file
git add kolibri/plugins/h5p_viewer/static/h5p kolibri/plugins/h5p_viewer/h5p_build/h5p_build.json
if git diff --cached --quiet; then
echo "has_build_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_build_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Generate App Token
if: steps.check-commit.outputs.changed == 'true' && steps.check-build-changes.outputs.has_build_changes == 'true'
id: generate-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.LE_BOT_APP_ID }}
private-key: ${{ secrets.LE_BOT_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
- name: Create Pull Request
if: steps.check-commit.outputs.changed == 'true' && steps.check-build-changes.outputs.has_build_changes == 'true'
uses: peter-evans/create-pull-request@v8
with:
token: ${{ steps.generate-token.outputs.token }}
commit-message: |
Update H5P JavaScript library
From h5p/h5p-php-library @ ${{ steps.check-commit.outputs.latest_commit }}
branch: h5p_update
delete-branch: true
title: 'Update H5P JavaScript library'
body: |
Updates the H5P JavaScript core library from [h5p/h5p-php-library](https://github.com/h5p/h5p-php-library).
**New commit:** `${{ steps.check-commit.outputs.latest_commit }}`
**Previous commit:** `${{ steps.check-commit.outputs.stored_commit }}`
[View upstream changes](https://github.com/h5p/h5p-php-library/compare/${{ steps.check-commit.outputs.stored_commit }}...${{ steps.check-commit.outputs.latest_commit }})
---
*Auto-generated by the [Update dependencies workflow](https://github.com/learningequality/kolibri/blob/develop/.github/workflows/dependency_updates.yml)*
base: develop
build-bloom-player:
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
tag: ${{ steps.check-commit.outputs.tag }}
stored_commit: ${{ steps.check-commit.outputs.stored_commit }}
latest_commit: ${{ steps.check-commit.outputs.latest_commit }}
has_build_changes: ${{ steps.check-build-changes.outputs.has_build_changes }}
steps:
- name: Checkout repository
uses: actions/checkout@v7.0.1
with:
ref: 'develop'
persist-credentials: false
- name: Get latest release from upstream
id: get-release
uses: octokit/request-action@v2.x
with:
route: GET /repos/{owner}/{repo}/releases/latest
owner: BloomBooks
repo: bloom-player
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get commit of latest release
id: get-commit
uses: octokit/request-action@v2.x
with:
route: GET /repos/{owner}/{repo}/commits/{ref}
owner: BloomBooks
repo: bloom-player
ref: ${{ fromJson(steps.get-release.outputs.data).tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check commit status
id: check-commit
env:
RELEASE_TAG: ${{ fromJson(steps.get-release.outputs.data).tag_name }}
LATEST_COMMIT: ${{ fromJson(steps.get-commit.outputs.data).sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import json
import os
from pathlib import Path
from urllib.request import Request, urlopen
latest_commit = os.environ['LATEST_COMMIT'].strip()
stored_commit = Path('kolibri/plugins/bloompub_viewer/bloom_build/.bloom-player-commit-sha').read_text().strip()
with urlopen(f"https://raw.githubusercontent.com/BloomBooks/bloom-player/{latest_commit}/package.json") as response:
node_version = json.load(response)['volta']['node']
compare = Request(
f"https://api.github.com/repos/BloomBooks/bloom-player/compare/{stored_commit}...{latest_commit}?per_page=1",
headers={'Authorization': f"Bearer {os.environ['GITHUB_TOKEN']}", 'Accept': 'application/vnd.github+json'},
)
with urlopen(compare) as response:
release_is_newer = json.load(response)['status'] in ('ahead', 'diverged')
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
print(f"tag={os.environ['RELEASE_TAG']}", file=f)
print(f"node_version={node_version}", file=f)
print(f"stored_commit={stored_commit}", file=f)
print(f"latest_commit={latest_commit}", file=f)
print(f"changed={'true' if release_is_newer else 'false'}", file=f)
shell: python
- name: Install pnpm
if: steps.check-commit.outputs.changed == 'true'
uses: pnpm/action-setup@v6.1.1
- name: Use Node.js
if: steps.check-commit.outputs.changed == 'true'
uses: actions/setup-node@v7
with:
node-version: ${{ steps.check-commit.outputs.node_version }}
- name: Install dependencies
if: steps.check-commit.outputs.changed == 'true'
run: pnpm install --frozen-lockfile --ignore-scripts --filter kolibri-bloompub-viewer-plugin...
- name: Update commit file and run script
if: steps.check-commit.outputs.changed == 'true'
env:
LATEST_COMMIT: ${{ steps.check-commit.outputs.latest_commit }}
run: |
echo "$LATEST_COMMIT" > kolibri/plugins/bloompub_viewer/bloom_build/.bloom-player-commit-sha
pnpm --filter kolibri-bloompub-viewer-plugin run build-bloom
- name: Check for actual build changes
if: steps.check-commit.outputs.changed == 'true'
id: check-build-changes
run: |
git add kolibri/plugins/bloompub_viewer/static/bloom kolibri/plugins/bloompub_viewer/bloom_build/bloom_build.json
if git diff --cached --quiet; then
echo "has_build_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_build_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Upload build output
if: steps.check-build-changes.outputs.has_build_changes == 'true'
uses: actions/upload-artifact@v7
with:
name: bloom-player-build
path: |
kolibri/plugins/bloompub_viewer/static/bloom
kolibri/plugins/bloompub_viewer/bloom_build/bloom_build.json
if-no-files-found: error
update-bloom-player:
needs: build-bloom-player
if: needs.build-bloom-player.outputs.has_build_changes == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v7.0.1
with:
ref: 'develop'
persist-credentials: false
- name: Remove previous build output
run: rm -rf kolibri/plugins/bloompub_viewer/static/bloom
- name: Download build output
uses: actions/download-artifact@v8
with:
name: bloom-player-build
path: kolibri/plugins/bloompub_viewer
- name: Update commit file
env:
LATEST_COMMIT: ${{ needs.build-bloom-player.outputs.latest_commit }}
run: echo "$LATEST_COMMIT" > kolibri/plugins/bloompub_viewer/bloom_build/.bloom-player-commit-sha
- name: Generate App Token
id: generate-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.LE_BOT_APP_ID }}
private-key: ${{ secrets.LE_BOT_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
- name: Create Pull Request
uses: peter-evans/create-pull-request@v8
with:
token: ${{ steps.generate-token.outputs.token }}
add-paths: |
kolibri/plugins/bloompub_viewer/bloom_build/.bloom-player-commit-sha
kolibri/plugins/bloompub_viewer/bloom_build/bloom_build.json
kolibri/plugins/bloompub_viewer/static/bloom
commit-message: |
Update Bloom Player to ${{ needs.build-bloom-player.outputs.tag }}
From BloomBooks/bloom-player @ ${{ needs.build-bloom-player.outputs.latest_commit }}
branch: bloom_player_update
delete-branch: true
title: 'Update Bloom Player to ${{ needs.build-bloom-player.outputs.tag }}'
body: |
Updates Bloom Player from [BloomBooks/bloom-player](https://github.com/BloomBooks/bloom-player) and rebuilds it with Kolibri's patches.
**New commit:** `${{ needs.build-bloom-player.outputs.latest_commit }}`
**Previous commit:** `${{ needs.build-bloom-player.outputs.stored_commit }}`
[View upstream changes](https://github.com/BloomBooks/bloom-player/compare/${{ needs.build-bloom-player.outputs.stored_commit }}...${{ needs.build-bloom-player.outputs.latest_commit }})
---
*Auto-generated by the [Update dependencies workflow](https://github.com/learningequality/kolibri/blob/develop/.github/workflows/dependency_updates.yml)*
base: develop
update-precommit-hooks:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7.0.1
with:
ref: develop
persist-credentials: false
- name: Set up uv
uses: astral-sh/setup-uv@v10.2.0
with:
enable-cache: true
cache-python: true
- name: Install Python
run: uv python install 3.11
- name: Install dev dependencies
run: uv sync --group dev --python 3.11
- name: Install pnpm
uses: pnpm/action-setup@v6.1.1
- name: Use Node.js
uses: actions/setup-node@v7
with:
node-version-file: package.json
cache: pnpm
- name: Install Node dependencies
run: pnpm install --frozen-lockfile
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Update pre-commit hook versions
run: uv run prek autoupdate
- name: Commit pre-commit config update
run: |
git add .pre-commit-config.yaml
git diff --cached --quiet || git commit -m "Update pre-commit hook versions"
- name: Apply formatting from updated hooks
run: uv run prek run --all-files || true
- name: Commit formatting changes
run: |
git add -A
git diff --cached --quiet || git commit -m "Apply formatting from updated pre-commit hooks"
- name: Generate App Token
id: generate-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.LE_BOT_APP_ID }}
private-key: ${{ secrets.LE_BOT_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
# Pushing a change to .github/workflows/, which the prek run above can
# produce, needs the app installation's Workflows permission.
permission-workflows: write
- name: Create Pull Request
uses: peter-evans/create-pull-request@v8
with:
token: ${{ steps.generate-token.outputs.token }}
branch: precommit_hooks_update
delete-branch: true
title: Update pre-commit hook versions
body: |
Updates pre-commit hook versions using `prek autoupdate` and applies any resulting formatting changes.
---
*Auto-generated by the [Update dependencies workflow](https://github.com/learningequality/kolibri/blob/develop/.github/workflows/dependency_updates.yml)*
base: develop