|
| 1 | +name: CI & Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pages: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + # --- JOB 1: TEST --- |
| 17 | + test: |
| 18 | + name: Run Rust Doc Tests |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v6 |
| 22 | + |
| 23 | + - name: Install Rust |
| 24 | + run: | |
| 25 | + rustup set profile minimal |
| 26 | + rustup toolchain install stable |
| 27 | + rustup default stable |
| 28 | +
|
| 29 | + - name: Install latest mdbook |
| 30 | + run: | |
| 31 | + tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name') |
| 32 | + url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz" |
| 33 | + mkdir bin |
| 34 | + curl -sSL $url | tar -xz --directory=bin |
| 35 | + echo "$(pwd)/bin" >> $GITHUB_PATH |
| 36 | +
|
| 37 | + - name: Run tests |
| 38 | + run: mdbook test |
| 39 | + |
| 40 | + # --- JOB 2: DEPLOY --- |
| 41 | + deploy: |
| 42 | + name: Deploy to GitHub Pages |
| 43 | + runs-on: ubuntu-latest |
| 44 | + needs: test # This ensures Deploy ONLY runs if Test passes! |
| 45 | + # This ensures Deploy ONLY runs on the main branch, not on PRs |
| 46 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 47 | + |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v6 |
| 50 | + with: |
| 51 | + fetch-depth: 0 |
| 52 | + |
| 53 | + - name: Install latest mdbook |
| 54 | + run: | |
| 55 | + tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name') |
| 56 | + url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz" |
| 57 | + mkdir bin |
| 58 | + curl -sSL $url | tar -xz --directory=bin |
| 59 | + echo "$(pwd)/bin" >> $GITHUB_PATH |
| 60 | +
|
| 61 | + - name: Build Book |
| 62 | + run: mdbook build |
| 63 | + |
| 64 | + - name: Setup Pages |
| 65 | + uses: actions/configure-pages@v4 |
| 66 | + |
| 67 | + - name: Upload artifact |
| 68 | + uses: actions/upload-pages-artifact@v3 |
| 69 | + with: |
| 70 | + path: "book" # The default mdbook output folder |
| 71 | + |
| 72 | + - name: Deploy to GitHub Pages |
| 73 | + id: deployment |
| 74 | + uses: actions/deploy-pages@v4 |
0 commit comments