Update H5P JS library #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update H5P JS library | |
| on: | |
| schedule: | |
| # Runs at 00:00 UTC on Wednesday | |
| - cron: '0 0 * * 3' | |
| # Optional: Allow manual triggering | |
| workflow_dispatch: | |
| jobs: | |
| check-commits: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| 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('packages/kolibri-sandbox/.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: Use Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: 'package.json' | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v5 | |
| with: | |
| cache: true | |
| - 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 }}" > packages/kolibri-sandbox/.h5p-commit-sha | |
| # Run your script here | |
| pnpm --filter kolibri-sandbox 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/core/content/static/h5p packages/kolibri-sandbox/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 }} | |
| - 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 H5P JS library workflow](https://github.com/learningequality/kolibri/blob/develop/.github/workflows/update_h5p.yml)* | |
| base: develop |