Skip to content

Commit ec86cf5

Browse files
authored
Merge pull request #12806 from rtibbles/auto_update_h5p
Auto update h5p
2 parents 81023f1 + 5bc3d41 commit ec86cf5

14 files changed

+156
-25
lines changed

.github/workflows/update_h5p.yml

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

kolibri/core/content/static/h5p/h5p-3cb6c6945b6a04ef3335.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)