|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +# Rebuilds the site and publishes it to GitHub Pages. The daily run only |
| 4 | +# rebuilds when the language repository has a commit the live site wasn't |
| 5 | +# built from (the site's /build.json records it); pushes here and manual runs |
| 6 | +# always rebuild. |
| 7 | +on: |
| 8 | + schedule: |
| 9 | + - cron: "17 3 * * *" |
| 10 | + push: |
| 11 | + branches: [master] |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + pages: write |
| 17 | + id-token: write |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: pages |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +env: |
| 24 | + UPSTREAM: https://github.com/lambda-discipline/lambda-discipline |
| 25 | + UPSTREAM_BRANCH: master |
| 26 | + SITE: https://lambda-discipline.github.io |
| 27 | + |
| 28 | +jobs: |
| 29 | + check: |
| 30 | + name: Check for changes |
| 31 | + runs-on: ubuntu-latest |
| 32 | + outputs: |
| 33 | + build: ${{ steps.compare.outputs.build }} |
| 34 | + steps: |
| 35 | + - id: compare |
| 36 | + run: | |
| 37 | + upstream=$(git ls-remote "$UPSTREAM" "refs/heads/$UPSTREAM_BRANCH" | cut -f1) |
| 38 | + deployed=$(curl -fsSL "$SITE/build.json" | jq -r '.commit // empty' || true) |
| 39 | + echo "upstream: $upstream" |
| 40 | + echo "deployed: ${deployed:-none}" |
| 41 | + if [ "$GITHUB_EVENT_NAME" != "schedule" ] || [ "$upstream" != "$deployed" ]; then |
| 42 | + echo "build=true" >> "$GITHUB_OUTPUT" |
| 43 | + else |
| 44 | + echo "build=false" >> "$GITHUB_OUTPUT" |
| 45 | + echo "The site is already up to date." >> "$GITHUB_STEP_SUMMARY" |
| 46 | + fi |
| 47 | +
|
| 48 | + build: |
| 49 | + name: Build |
| 50 | + needs: check |
| 51 | + if: needs.check.outputs.build == 'true' |
| 52 | + runs-on: ubuntu-latest |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Clone the language repository |
| 57 | + run: git clone --depth 1 --branch "$UPSTREAM_BRANCH" "$UPSTREAM" .cache/lambda-discipline |
| 58 | + |
| 59 | + - name: Install Rust |
| 60 | + # Installs the version the language repository's rust-toolchain.toml asks for. |
| 61 | + working-directory: .cache/lambda-discipline |
| 62 | + run: rustup toolchain install |
| 63 | + |
| 64 | + - uses: Swatinem/rust-cache@v2 |
| 65 | + with: |
| 66 | + workspaces: .cache/lambda-discipline |
| 67 | + |
| 68 | + - uses: actions/setup-python@v5 |
| 69 | + with: |
| 70 | + python-version: "3.13" |
| 71 | + cache: pip |
| 72 | + |
| 73 | + - run: pip install -r requirements.txt |
| 74 | + |
| 75 | + - name: Build the site |
| 76 | + run: python build.py --no-update |
| 77 | + |
| 78 | + - uses: actions/upload-pages-artifact@v3 |
| 79 | + with: |
| 80 | + path: _site |
| 81 | + |
| 82 | + deploy: |
| 83 | + name: Deploy |
| 84 | + needs: build |
| 85 | + runs-on: ubuntu-latest |
| 86 | + environment: |
| 87 | + name: github-pages |
| 88 | + url: ${{ steps.deployment.outputs.page_url }} |
| 89 | + steps: |
| 90 | + - id: deployment |
| 91 | + uses: actions/deploy-pages@v4 |
0 commit comments