feat: add InnerSource and AI section #2
Workflow file for this run
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: Deploy mdBook PR preview | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, closed] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| # One running preview job per PR number. If new commits arrive, cancel older runs. | |
| group: pr-preview-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| deploy-preview: | |
| if: github.event.action != 'closed' && github.event.pull_request.head.repo.full_name == github.repository | |
| runs-on: ubuntu-latest | |
| env: | |
| CARGO_HOME: ${{ github.workspace }}/.cargo | |
| RUSTUP_HOME: ${{ github.workspace }}/.rustup | |
| PREVIEW_DIR: pr-${{ github.event.pull_request.number }} | |
| PREVIEW_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.pull_request.number }}/ | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Cache Cargo registry and git index | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ env.CARGO_HOME }}/registry | |
| ${{ env.CARGO_HOME }}/git | |
| key: ${{ runner.os }}-cargo-registry-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-registry- | |
| - name: Cache Rust toolchains | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ env.RUSTUP_HOME }}/toolchains | |
| ${{ env.RUSTUP_HOME }}/update-hashes | |
| key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-rust-toolchain- | |
| - name: Cache installed mdBook binaries | |
| id: mdbook-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ env.CARGO_HOME }}/bin | |
| key: ${{ runner.os }}-mdbook-bin-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-mdbook-bin- | |
| - name: Install mdBook | |
| if: steps.mdbook-cache.outputs.cache-hit != 'true' | |
| run: bash scripts/install-mdbook.sh | |
| env: | |
| REPO_ROOT: ${{ github.workspace }} | |
| - name: Add Cargo bin to PATH | |
| run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH" | |
| - name: Build with mdBook | |
| run: ${{ env.CARGO_HOME }}/bin/mdbook build | |
| - name: Deploy preview to gh-pages/pr-<id> | |
| # Important: we build from the PR branch, but publish static files to gh-pages. | |
| # GitHub Pages serves from a configured publishing branch (gh-pages here), | |
| # not from arbitrary PR branches. | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_branch: gh-pages | |
| publish_dir: ./book | |
| # Keep each preview isolated under pr-<number>/ so multiple PR previews can coexist. | |
| destination_dir: ${{ env.PREVIEW_DIR }} | |
| keep_files: true | |
| - name: Comment preview URL on PR | |
| uses: actions/github-script@v7 | |
| with: | |
| # Keep workflow YAML concise: run comment logic from .github/workflows/mdbook/comment-preview-url.js. | |
| script: | | |
| const { commentPreviewUrl } = require('./.github/workflows/mdbook/comment-preview-url.js') | |
| await commentPreviewUrl({ | |
| github, | |
| context, | |
| previewUrl: process.env.PREVIEW_URL, | |
| }) | |
| cleanup-preview: | |
| if: github.event.action == 'closed' && github.event.pull_request.head.repo.full_name == github.repository | |
| runs-on: ubuntu-latest | |
| env: | |
| PREVIEW_DIR: pr-${{ github.event.pull_request.number }} | |
| steps: | |
| - name: Checkout gh-pages | |
| # Cleanup edits the published site branch directly because previews live there. | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: gh-pages | |
| fetch-depth: 0 | |
| - name: Remove preview directory | |
| run: | | |
| # Keep workflow YAML concise: run cleanup logic from .github/workflows/mdbook/cleanup-preview.sh. | |
| bash .github/workflows/mdbook/cleanup-preview.sh "${PREVIEW_DIR}" "${{ github.event.pull_request.number }}" |