Sync filament libraries #51
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: Sync filament libraries | |
| on: | |
| schedule: | |
| # Daily at 04:17 UTC. Off-peak avoids the top-of-hour cron stampede on | |
| # GitHub's runners and keeps the sync from racing the deploy job. | |
| - cron: '17 4 * * *' | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # SYNC_BOT_TOKEN is an admin PAT (ondrejbartas). Used here so the PR | |
| # creator and merger has the admin identity, letting `gh pr merge --admin` | |
| # bypass the CODEOWNERS-approval requirement (enforce_admins: false). | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.SYNC_BOT_TOKEN }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - run: npm ci | |
| - name: Sync OpenPrintTag library | |
| run: npm run sync:openprinttag | |
| - name: Sync HueForge library | |
| run: npm run sync:hueforge | |
| - name: Compute commit message | |
| id: msg | |
| run: | | |
| OPT='data/filament-library-openprinttag.json' | |
| HF='data/filament-library-hueforge.json' | |
| OPT_COUNT=$(node -e "console.log(JSON.parse(require('fs').readFileSync('$OPT','utf8')).entryCount)") | |
| HF_COUNT=$(node -e "console.log(JSON.parse(require('fs').readFileSync('$HF','utf8')).entryCount)") | |
| DATE=$(date -u +%Y-%m-%d) | |
| echo "msg=chore: refresh filament libraries (OpenPrintTag ${OPT_COUNT}, HueForge ${HF_COUNT}, ${DATE})" >> "$GITHUB_OUTPUT" | |
| - name: Open PR if changed | |
| id: pr | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| token: ${{ secrets.SYNC_BOT_TOKEN }} | |
| commit-message: ${{ steps.msg.outputs.msg }} | |
| title: ${{ steps.msg.outputs.msg }} | |
| body: | | |
| Automated daily refresh of filament libraries. | |
| - OpenPrintTag → `data/filament-library-openprinttag.json` | |
| - HueForge → `data/filament-library-hueforge.json` | |
| Source workflow: [`sync-libraries.yml`](./.github/workflows/sync-libraries.yml). | |
| Squash-merged automatically by the workflow using the admin PAT | |
| (`SYNC_BOT_TOKEN`) — `enforce_admins: false` allows this bypass. | |
| branch: bot/sync-libraries | |
| delete-branch: true | |
| author: 'filament-library-bot <[email protected]>' | |
| committer: 'filament-library-bot <[email protected]>' | |
| add-paths: | | |
| data/filament-library-openprinttag.json | |
| data/filament-library-hueforge.json | |
| - name: Squash-merge as admin | |
| if: steps.pr.outputs.pull-request-number | |
| run: | | |
| gh pr merge "${{ steps.pr.outputs.pull-request-number }}" \ | |
| --admin --squash --delete-branch \ | |
| --repo "${{ github.repository }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.SYNC_BOT_TOKEN }} |