Skip to content

Commit 33bd170

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

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

.github/workflows/update_h5p.yml

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

0 commit comments

Comments
 (0)