github pages #1576
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
| #******************************************************************************* | |
| # gh-pages.yml | |
| # | |
| # Github Workflow to deploy Interlisp.org. | |
| # | |
| # Interlisp.org is a Hugo based static website that contains a | |
| # detailed bibliography maintained using Zotero (https://www.zotero.org/groups/2914042/interlispwww.zotero.org/). | |
| # | |
| # This workflow consists of two jobs, one to ensure that we have the latest | |
| # version of the Zotero bibliography and a second job to deploy the website. | |
| # | |
| # The workflow is executed either on a push or via scheduled run times. When | |
| # started at a scheduled run time we only do a deploy if the cached bibliography | |
| # is no longer current. On a push, we always verifty the the current | |
| # bibliography is loaded and deploy a new version of the website. | |
| # | |
| # 2023-10-20 Bill Stumbo | |
| # | |
| # Copyright 2023 by Interlisp.org | |
| # | |
| # ****************************************************************************** | |
| name: github pages | |
| on: | |
| push: | |
| branches: | |
| - main # Set a branch to deploy | |
| pull_request: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 3 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: pages-${{ github.ref }} | |
| cancel-in-progress: true | |
| defaults: | |
| run: | |
| shell: bash | |
| env: | |
| # ---------------------------------------------------------------------------- | |
| # Specify the deployment environment: staging or production | |
| HUGO_ENVIRONMENT: ${{ vars.HUGO_ENVIRONMENT || 'staging' }} | |
| HUGO_VERSION: 0.155.3 | |
| jobs: | |
| # ---------------------------------------------------------------------------- | |
| # Use the Zotero REST API to get the current version of the Zotero Bibliography | |
| # Compare against a cached version of the bibliography. | |
| # | |
| check: | |
| outputs: | |
| zoteroVersion: ${{ steps.zoteroVersion.outputs.version }} | |
| cacheHit: ${{ steps.cache-zotero.outputs.cache-hit }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get Zotero Version Information | |
| id: zoteroVersion | |
| run: | | |
| set -euo pipefail | |
| VERSION=$(curl -fsSLI "https://api.zotero.org/groups/2914042/items?format=versions" \ | |
| | { grep -i "last-modified-version" \ | |
| | cut -d: -f2 \ | |
| | tr -d $'\r ' || true; }) | |
| if [[ -z "${VERSION:-}" ]]; then | |
| echo "Error: Failed to determine Zotero Last-Modified-Version from API response." >&2 | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Cache Zotero Bibliography | |
| id: cache-zotero | |
| uses: actions/cache/restore@v5 | |
| with: | |
| lookup-only: true | |
| path: | | |
| content/en/history/bibliography | |
| key: bib-${{ steps.zoteroVersion.outputs.version }} | |
| # ---------------------------------------------------------------------------- | |
| # Validate that README.md references the correct Hugo version. | |
| # Only runs on push/pull_request, not scheduled runs. | |
| # | |
| validate-docs: | |
| if: github.event_name == 'push' || github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Check Hugo version consistency | |
| run: | | |
| echo "Checking README.md for Hugo version $HUGO_VERSION" | |
| # Check badge | |
| if ! grep -q "badge/Hugo-${HUGO_VERSION}" README.md; then | |
| echo "::error::README.md badge does not reference Hugo version $HUGO_VERSION" | |
| FAILED=1 | |
| fi | |
| # Check download URL | |
| if ! grep -q "hugo_extended_${HUGO_VERSION}_linux-amd64.deb" README.md; then | |
| echo "::error::README.md download URL does not reference Hugo version $HUGO_VERSION" | |
| FAILED=1 | |
| fi | |
| if [ "$FAILED" = "1" ]; then | |
| echo "Update README.md to use Hugo version $HUGO_VERSION" | |
| exit 1 | |
| fi | |
| echo "README.md Hugo version references are consistent" | |
| # ---------------------------------------------------------------------------- | |
| # Run the bibliography JSON-LD test suite against a test-environment Hugo | |
| # build that mounts tests/fixtures/bibliography/ alongside the real content. | |
| # This job must pass before changes can be merged or deployed. | |
| # | |
| test: | |
| needs: [check, validate-docs] | |
| if: always() && (github.event_name == 'push' || github.event_name == 'pull_request' || needs.check.outputs.cacheHit != 'true') && (needs.validate-docs.result == 'success' || needs.validate-docs.result == 'skipped') && (needs.check.result == 'success' || needs.check.result == 'skipped') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Cache Zotero Bibliography | |
| id: cache-bib | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| static/data/bibliography.json | |
| static/data/bibItems | |
| content/en/history/bibliography | |
| key: bib-${{ needs.check.outputs.zoteroVersion }} | |
| - name: Install Bibliography | |
| if: steps.cache-bib.outputs.cache-hit != 'true' | |
| run: | | |
| echo "Retrieve bibliography" | |
| cd scripts | |
| chmod +x ./update_bibliography.sh | |
| chmod +x ./bibSplit.pl | |
| ./update_bibliography.sh | |
| - name: Install Hugo CLI | |
| run: | | |
| wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ | |
| && sudo dpkg -i ${{ runner.temp }}/hugo.deb | |
| - name: Setup Node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: 'npm' | |
| - name: Install Node dependencies | |
| run: npm ci | |
| - name: Build test site | |
| env: | |
| HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache | |
| TZ: America/New_York | |
| run: hugo --environment testing --destination tests/public_test | |
| - name: Install pytest | |
| run: pip install pytest pyyaml pytest-cov | |
| - name: Run content-integrity tests | |
| run: pytest tests/test_content_integrity.py -v --cov-report=term-missing | |
| - name: Run JSON-LD tests | |
| run: pytest tests/test_bibliography_jsonld.py -v | |
| # ---------------------------------------------------------------------------- | |
| # Build the website. This job is conditional, we will always run it on a | |
| # push or if on a scheduled run the cache was determined to be out of date. | |
| # | |
| build: | |
| needs: [check, validate-docs, test] | |
| if: always() && (github.event_name == 'push' || github.event_name == 'pull_request' || needs.check.outputs.cacheHit != 'true') && (needs.validate-docs.result == 'success' || needs.validate-docs.result == 'skipped') && (needs.check.result == 'success' || needs.check.result == 'skipped') && (needs.test.result == 'success') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Cache Zotero Bibliography | |
| id: cache-bib | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| static/data/bibliography.json | |
| static/data/bibItems | |
| content/en/history/bibliography | |
| key: bib-${{ needs.check.outputs.zoteroVersion }} | |
| - name: Install Bibliography | |
| if: steps.cache-bib.outputs.cache-hit != 'true' | |
| run: | | |
| echo "Retrieve bibliography" | |
| cd scripts | |
| chmod +x ./update_bibliography.sh | |
| chmod +x ./bibSplit.pl | |
| ./update_bibliography.sh | |
| # Install Hugo Extended | |
| # | |
| - name: Install Hugo CLI | |
| run: | | |
| wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ | |
| && sudo dpkg -i ${{ runner.temp }}/hugo.deb | |
| - name: Setup Pages | |
| id: pages | |
| uses: actions/configure-pages@v6.0.0 | |
| - name: Setup Node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: | | |
| npm ci | |
| - name: Build | |
| env: | |
| HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache | |
| TZ: America/New_York | |
| run: hugo --cleanDestinationDir -e $HUGO_ENVIRONMENT | |
| - name: Install pytest | |
| run: pip install pytest pytest-cov | |
| - name: Run build-integrity tests | |
| run: pytest tests/test_hugo_build.py -v | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v5.0.0 | |
| with: | |
| path: ./public | |
| deploy: | |
| if: github.event_name != 'pull_request' | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: [build, test] | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v5 | |