Skip to content

Commit 441a7df

Browse files
committed
Add manual/scheduled job to create h5p update PRs when needed.
1 parent fcb8c36 commit 441a7df

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

.github/workflows/update_h5p.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Update H5P JS library
2+
3+
on:
4+
schedule:
5+
# Runs at 00:00 UTC on Wednesday
6+
- cron: '0 0 * * 3'
7+
# Optional: Allow manual triggering
8+
workflow_dispatch:
9+
10+
jobs:
11+
check-commits:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Generate App Token
19+
id: generate-token
20+
uses: tibdex/github-app-token@v2
21+
with:
22+
app_id: ${{ secrets.APP_ID }}
23+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
24+
25+
- name: Get latest commit from target repo
26+
id: get-commit
27+
uses: octokit/request-action@v2.x
28+
with:
29+
route: GET /repos/{owner}/{repo}/branches/{branch}
30+
owner: h5p
31+
repo: h5p-php-library
32+
branch: master
33+
env:
34+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
35+
36+
- name: Check commit status
37+
id: check-commit
38+
run: |
39+
import json
40+
import os
41+
from pathlib import Path
42+
43+
# Get the latest commit from the API response
44+
latest_commit = "${{ steps.get-commit.outputs.data.commit.sha }}".strip()
45+
46+
# Check stored commit
47+
commit_file = Path('packages/hashi/.h5p-commit-sha')
48+
if commit_file.exists():
49+
stored_commit = commit_file.read_text().strip()
50+
has_changed = stored_commit != latest_commit
51+
else:
52+
print("No stored commit found, treating as new")
53+
has_changed = True
54+
55+
# Set outputs for GitHub Actions
56+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
57+
print(f"latest_commit={latest_commit}", file=f)
58+
print(f"changed={'true' if has_changed else 'false'}", file=f)
59+
shell: python
60+
61+
- name: Use Node.js
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version: '18.x'
65+
- name: Get yarn cache directory path
66+
id: yarn-cache-dir-path
67+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
68+
- name: Cache Node.js modules
69+
uses: actions/cache@v4
70+
with:
71+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
72+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
73+
restore-keys: |
74+
${{ runner.os }}-yarn-
75+
76+
- name: Update commit file and run script
77+
if: steps.check-commit.outputs.changed == 'true'
78+
run: |
79+
# Update the commit file
80+
echo "${{ steps.check-commit.outputs.latest_commit }}" > packages/hashi/.h5p-commit-sha
81+
82+
# Run your script here
83+
yarn workspace hashi run build-h5p
84+
85+
- name: Create Pull Request
86+
if: steps.check-commit.outputs.changed == 'true'
87+
uses: peter-evans/create-pull-request@v6
88+
with:
89+
token: ${{ steps.generate-token.outputs.token }}
90+
commit-message: |
91+
Update commit SHA and run script
92+
93+
Target repo commit: ${{ steps.check-commit.outputs.latest_commit }}
94+
branch: h5p_update
95+
delete-branch: true
96+
title: 'Update from target repository commit'
97+
body: |
98+
This PR was automatically created by the Update H5P JS library.
99+
100+
Updates from target repository commit: ${{ steps.check-commit.outputs.latest_commit }}
101+
base: develop

0 commit comments

Comments
 (0)