Deploy Pages #886
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: Deploy Pages | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - site/** | |
| - .github/workflows/pages.yml | |
| workflow_dispatch: {} | |
| workflow_run: | |
| workflows: | |
| - Sync Heatmaps | |
| - Sync Strava Heatmaps | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| env: | |
| DASHBOARD_DATA_BRANCH: dashboard-data | |
| concurrency: | |
| group: pages | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Restore site data | |
| run: | | |
| set -euo pipefail | |
| branch="${DASHBOARD_DATA_BRANCH}" | |
| if git ls-remote --exit-code --heads origin "${branch}" >/dev/null; then | |
| git fetch origin "${branch}" | |
| if git checkout "origin/${branch}" -- site/data.json; then | |
| echo "Using site/data.json from ${branch}." | |
| exit 0 | |
| fi | |
| echo "Branch ${branch} exists but site/data.json is missing; writing empty fallback." | |
| else | |
| echo "No ${branch} branch yet; writing empty site/data.json." | |
| fi | |
| mkdir -p site | |
| cat <<JSON > site/data.json | |
| { | |
| "activities": [], | |
| "aggregates": {}, | |
| "generated_at": null, | |
| "repo": "${GITHUB_REPOSITORY}", | |
| "type_meta": {}, | |
| "types": [], | |
| "units": { | |
| "distance": "mi", | |
| "elevation": "ft" | |
| }, | |
| "week_start": "sunday", | |
| "years": [] | |
| } | |
| JSON | |
| - name: Stamp repository in site data | |
| run: | | |
| set -euo pipefail | |
| python - <<'PY' | |
| import json | |
| import os | |
| path = "site/data.json" | |
| repo = os.environ.get("GITHUB_REPOSITORY", "").strip() | |
| try: | |
| with open(path, "r", encoding="utf-8") as handle: | |
| payload = json.load(handle) | |
| except Exception: | |
| payload = {} | |
| if not isinstance(payload, dict): | |
| payload = {} | |
| if repo and "/" in repo: | |
| payload["repo"] = repo | |
| with open(path, "w", encoding="utf-8") as handle: | |
| json.dump(payload, handle, ensure_ascii=True, indent=2, sort_keys=True) | |
| handle.write("\n") | |
| PY | |
| - name: Configure Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Stamp app asset version | |
| run: | | |
| set -euo pipefail | |
| version="${GITHUB_SHA::12}" | |
| sed -i "s|__APP_VERSION__|${version}|g" site/index.html | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: site | |
| - name: Deploy | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |