|
| 1 | +# Sample workflow for building and deploying a mdBook site to GitHub Pages |
| 2 | +# |
| 3 | +# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html |
| 4 | +# |
| 5 | +name: Deploy mdBook site to Pages |
| 6 | + |
| 7 | +on: |
| 8 | + # Runs on pushes targeting the default branch |
| 9 | + push: |
| 10 | + branches: ["main"] |
| 11 | + |
| 12 | + # Allows you to run this workflow manually from the Actions tab |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + pages: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 22 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 23 | +concurrency: |
| 24 | + group: "pages" |
| 25 | + cancel-in-progress: false |
| 26 | + |
| 27 | +jobs: |
| 28 | + # Build job |
| 29 | + build: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + env: |
| 32 | + MDBOOK_VERSION: 0.4.45 |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Dynamically generate resources.md file |
| 37 | + run: ./scripts/generate_resources.sh |
| 38 | + |
| 39 | + # Install rust with GitHub's 'setup-rs' action (most recent stable version) |
| 40 | + - name: Install Rust |
| 41 | + uses: actions-rs/toolchain@v1 |
| 42 | + with: |
| 43 | + toolchain: stable # Or specify a version |
| 44 | + override: true # ensure this version is used globally in the workflow |
| 45 | + components: cargo |
| 46 | + |
| 47 | + # Cache rust crates (mdbook dependencies) so reinstalls don't take long |
| 48 | + - name: Cache the cargo registry and build artifacts |
| 49 | + uses: actions/cache@v3 |
| 50 | + with: |
| 51 | + path: | |
| 52 | + ~/.cargo/registry |
| 53 | + ~/.cargo/git |
| 54 | + target |
| 55 | + key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }} |
| 56 | + restore-keys: cargo-${{ runner.os }}- |
| 57 | + |
| 58 | + # Cache the mdbook binary so we don't need to install it every time |
| 59 | + - name: Cache mdbook binary |
| 60 | + id: cache-mdbook |
| 61 | + uses: actions/cache@v3 |
| 62 | + with: |
| 63 | + path: ~/.cargo/bin/mdbook |
| 64 | + key: mdbook-${{ runner.os }}-${{ env.MDBOOK_VERSION }} |
| 65 | + restore-keys: mdbook-${{ runner.os }}- |
| 66 | + |
| 67 | + # Install mdbook if it's not cached |
| 68 | + - name: Install mdBook |
| 69 | + if: steps.cache-mdbook.outputs.cache-hit != 'true' |
| 70 | + run: cargo install --version ${MDBOOK_VERSION} mdbook --force |
| 71 | + |
| 72 | + - name: Setup Pages |
| 73 | + id: pages |
| 74 | + uses: actions/configure-pages@v5 |
| 75 | + |
| 76 | + - name: Build with mdBook |
| 77 | + run: mdbook build |
| 78 | + |
| 79 | + - name: Upload artifact |
| 80 | + uses: actions/upload-pages-artifact@v3 |
| 81 | + with: |
| 82 | + path: ./book |
| 83 | + |
| 84 | + # Deployment job |
| 85 | + deploy: |
| 86 | + environment: |
| 87 | + name: github-pages |
| 88 | + url: ${{ steps.deployment.outputs.page_url }} |
| 89 | + runs-on: ubuntu-latest |
| 90 | + needs: build |
| 91 | + steps: |
| 92 | + - name: Deploy to GitHub Pages |
| 93 | + id: deployment |
| 94 | + uses: actions/deploy-pages@v4 |
0 commit comments