ci: skip deploy when GitHub Pages is disabled #621
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: Build and deploy an updated version of the website | |
| on: [push, pull_request] | |
| # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| env: | |
| MDBOOK_LINKCHECK_VER: 0.7.7 | |
| jobs: | |
| # Fork may have GitHub Pages disabled, so deploying would result in 404 | |
| # errors. This job checks whether Pages is enabled so the deploy job can be | |
| # skipped on repositories where it isn't configured. | |
| check-pages: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pages: read | |
| outputs: | |
| pages_enabled: ${{ steps.check_pages.outputs.is_enabled }} | |
| steps: | |
| - name: Check if GitHub Pages is enabled | |
| id: check_pages | |
| uses: AlexAegis/check-github-pages@v1 | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout gb-asm-tutorial | |
| uses: actions/checkout@v2 | |
| with: | |
| path: gb-asm-tutorial | |
| - name: Install mdbook | |
| uses: peaceiris/actions-mdbook@v1 | |
| with: | |
| mdbook-version: 0.4.52 | |
| - name: Install static-sitemap-cli | |
| run: npm install static-sitemap-cli | |
| # FIXME: Keep this up to date | |
| - name: Install mdbook-linkcheck | |
| run: | # `-L` because GitHub performs a redirection | |
| curl -L -o mdbook-linkcheck.zip "https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/download/v$MDBOOK_LINKCHECK_VER/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip" | |
| unzip mdbook-linkcheck.zip mdbook-linkcheck | |
| chmod +x mdbook-linkcheck | |
| - name: Cache build dir | |
| uses: actions/cache@v4 | |
| with: | |
| path: gb-asm-tutorial/target/ | |
| key: ${{ runner.os }}-build-${{ hashFiles('gb-asm-tutorial/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build- | |
| - name: Build | |
| working-directory: gb-asm-tutorial/ | |
| env: | |
| MDBOOK_BUILD__CREATE_MISSING: "false" # Prevent creating missing files in SUMMARY.md | |
| MDBOOK_OUTPUT__LINKCHECK__COMMAND: "../mdbook-linkcheck" | |
| MDBOOK_OUTPUT__LINKCHECK__OPTIONAL: "false" | |
| run: | | |
| mdbook build | |
| for f in po/*.po; do | |
| lang=$(basename -s .po "$f") | |
| MDBOOK_BOOK__LANGUAGE="$lang" mdbook build -d book/"$lang" | |
| mv book/"$lang"/custom book/custom/"$lang" | |
| done | |
| - name: Generate sitemap | |
| run: | | |
| cd gb-asm-tutorial/book/custom/ | |
| npx sscli --no-clean --base https://gbdev.io/gb-asm-tutorial | |
| - name: Store final build | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: gb-asm-tutorial/book/custom/ | |
| deploy: | |
| name: Deploy to GitHub pages | |
| # Do not run this unless *pushing* to `master` and GitHub Pages is enabled. | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/master' && needs.check-pages.outputs.pages_enabled == 'true' | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: [build, check-pages] | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |