Build and Deploy to GitHub Pages #249
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
| # filepath: .github/workflows/deploy.yml | |
| name: Build and Deploy to GitHub Pages | |
| on: | |
| # Run three times daily to catch release peaks (01:00, 09:00, 17:00 UTC) | |
| schedule: | |
| - cron: '0 1,9,17 * * *' | |
| # Run on push to main branch | |
| push: | |
| branches: [ main ] | |
| # Allow manual trigger | |
| workflow_dispatch: | |
| # Sets permissions for GitHub Pages deployment | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| actions: write | |
| # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Keep workflow alive | |
| uses: silverstripe/gha-keepalive@v1 | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: | | |
| echo "Installing build dependencies" | |
| npm ci | |
| # actions/cache saves automatically at job end when the primary key is a miss. | |
| # Since key uses run_id (always unique), it always saves the updated cache. | |
| # restore-keys prefix match finds the most recent previous cache. | |
| - name: Restore activity cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: data/activity-cache.json | |
| key: activity-cache-${{ github.run_id }} | |
| restore-keys: | | |
| activity-cache- | |
| - name: Prime GitHub stats cache | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: node scripts/prime-stats-cache.js | |
| - name: Wait for stats computation | |
| run: sleep 30 | |
| - name: Build site | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "Building site for deployment" | |
| npm run build | |
| - name: Verify build output | |
| run: | | |
| echo "Verifying build output..." | |
| ls -la dist/ | |
| echo "✅ Build verification complete" | |
| - name: Setup GitHub Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: './dist' | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |