Fetch Data and Deploy to Gh Pages #185
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: Fetch Data and Deploy to Gh Pages | |
| on: | |
| schedule: | |
| - cron: '0 1 * * *' | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| # Allows manual trigger from GitHub Actions UI | |
| # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
| permissions: | |
| actions: write | |
| contents: read | |
| pages: write | |
| id-token: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '24' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Restore Cached Data | |
| id: cache-restore | |
| uses: actions/cache/restore@v5 | |
| with: | |
| path: data/stats.json | |
| key: stats-data-${{ github.run_id }} | |
| restore-keys: | | |
| stats-data- | |
| - name: Fetch GitHub statistics | |
| if: github.event_name != 'push' || hashFiles('data/stats.json') == '' | |
| run: npm run fetch-data | |
| env: | |
| # Uses default GITHUB_TOKEN for public repos | |
| # For private repos, use a PAT stored as GH_PAT secret | |
| GITHUB_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} | |
| # Organizations to track (comma-separated), configured via repository variable | |
| GH_ORGS: ${{ vars.GH_ORGS }} | |
| # Number of years to fetch (default: 5), configured via repository variable | |
| GH_YEARS: ${{ vars.GH_YEARS }} | |
| - name: Save Data Cache | |
| if: github.event_name != 'push' || hashFiles('data/stats.json') == '' | |
| uses: actions/cache/save@v5 | |
| with: | |
| path: data/stats.json | |
| key: stats-data-${{ github.run_id }} | |
| - name: Build vendor assets | |
| run: npm run build | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v4 | |
| with: | |
| # Upload entire repository (includes generated data/stats.json) | |
| path: '.' | |
| deploy: | |
| if: github.ref_name == github.event.repository.default_branch | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |