| name: CI |
| |
| on: |
| push: |
| branches: |
| - main |
| pull_request: |
| schedule: |
| # Run multiple times a day as the successful cached links are not checked every time. |
| - cron: "0 */8 * * *" |
| |
| jobs: |
| ci: |
| if: github.repository == 'rust-lang/rustc-dev-guide' |
| runs-on: ubuntu-latest |
| env: |
| MDBOOK_VERSION: 0.5.2 |
| MDBOOK_LINKCHECK2_VERSION: 0.13.0 |
| MDBOOK_MERMAID_VERSION: 0.17.0 |
| MDBOOK_OUTPUT__LINKCHECK__FOLLOW_WEB_LINKS: ${{ github.event_name != 'pull_request' }} |
| DEPLOY_DIR: book/html |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| steps: |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| with: |
| # linkcheck needs the base commit. |
| fetch-depth: 0 |
| |
| - name: Test CI scripts |
| run: ci/tests/report-scheduled-linkcheck-failure.sh |
| |
| - name: Cache binaries |
| id: mdbook-cache |
| uses: actions/cache@v4 |
| with: |
| path: | |
| ~/.cargo/bin |
| key: ${{ runner.os }}-${{ env.MDBOOK_VERSION }}--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ env.MDBOOK_MERMAID_VERSION }} |
| |
| - name: Restore cached Linkcheck |
| if: github.event_name == 'schedule' |
| id: cache-linkcheck-restore |
| uses: actions/cache/restore@v4 |
| with: |
| path: book/linkcheck/cache.json |
| key: linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ github.run_id }} |
| restore-keys: | |
| linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}-- |
| |
| - name: Install latest nightly Rust toolchain |
| if: steps.mdbook-cache.outputs.cache-hit != 'true' |
| run: | |
| rustup update nightly |
| rustup override set nightly |
| |
| - name: Install Dependencies |
| if: steps.mdbook-cache.outputs.cache-hit != 'true' |
| run: | |
| cargo install --locked mdbook --version ${{ env.MDBOOK_VERSION }} |
| cargo install --locked mdbook-linkcheck2 --version ${{ env.MDBOOK_LINKCHECK2_VERSION }} |
| cargo install --locked mdbook-mermaid --version ${{ env.MDBOOK_MERMAID_VERSION }} |
| |
| - name: Check build |
| run: ENABLE_LINKCHECK=1 mdbook build |
| |
| - name: Check build with link checking disabled |
| run: | |
| output=$(mktemp) |
| mdbook build 2>&1 | tee "$output" |
| ! grep -F "Broken pipe" "$output" |
| |
| - name: Save cached Linkcheck |
| id: cache-linkcheck-save |
| if: ${{ !cancelled() && github.event_name == 'schedule' }} |
| uses: actions/cache/save@v4 |
| with: |
| path: book/linkcheck/cache.json |
| key: linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ github.run_id }} |
| |
| - name: Deploy to gh-pages |
| if: github.event_name == 'push' |
| run: | |
| touch "${{ env.DEPLOY_DIR }}/.nojekyll" |
| cp CNAME "${{ env.DEPLOY_DIR }}" |
| cd "${{ env.DEPLOY_DIR }}" |
| rm -rf .git |
| git init |
| git config user.name "Deploy from CI" |
| git config user.email "" |
| git add . |
| git commit -m "Deploy ${GITHUB_SHA} to gh-pages" |
| git push --quiet -f "https://x-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}" HEAD:gh-pages |
| |
| - name: Check if files comply with semantic line breaks |
| continue-on-error: true |
| run: | |
| # using split_inclusive that uses regex feature that uses an unstable feature |
| RUSTC_BOOTSTRAP=1 cargo run --release --manifest-path ci/sembr/Cargo.toml src |
| |
| notify-scheduled-failure: |
| name: Open an issue if links are broken |
| needs: ci |
| if: failure() && github.event_name == 'schedule' |
| runs-on: ubuntu-latest |
| permissions: |
| actions: read |
| contents: read |
| issues: write |
| steps: |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| - name: Open an issue or comment on an existing one |
| run: ci/report-scheduled-linkcheck-failure.sh |
| env: |
| GH_TOKEN: ${{ github.token }} |
| |
| close-scheduled-failure: |
| name: Close linkcheck issue if no links are broken |
| needs: ci |
| if: success() && github.event_name == 'schedule' |
| runs-on: ubuntu-latest |
| permissions: |
| contents: read |
| issues: write |
| steps: |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| - name: Close issue |
| run: ci/close-scheduled-linkcheck-issues.sh |
| env: |
| GH_TOKEN: ${{ github.token }} |