chore(book): update for cross-repo publishing #1
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 book and publish to GHCR | |
| on: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - "book/**" | |
| - ".github/workflows/book.yaml" | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write # push to GHCR | |
| # Allow one concurrent deployment | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| env: | |
| CARGO_TERM_COLOR: always | |
| REF_MUTABLE: ghcr.io/criterion-rs/criterion.rs-book:latest | |
| REF_IMMUTABLE: ghcr.io/criterion-rs/criterion.rs-book:${{ github.sha }} | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install mdBook | |
| uses: jontze/action-mdbook@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| use-linkcheck: true | |
| use-mermaid: true | |
| use-toc: true | |
| use-opengh: true | |
| use-admonish: true | |
| use-katex: true | |
| - name: Build Book | |
| run: | | |
| set -euo pipefail | |
| cd book && mdbook build | |
| - name: Create tarball | |
| run: | | |
| set -euo pipefail | |
| tar -czf book.tar.gz -C book/book/html . | |
| - name: Setup ORAS | |
| uses: oras-project/setup-oras@v1 | |
| - name: Login to GHCR | |
| run: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u "${{ github.actor }}" --password-stdin | |
| - name: Push tarball as OCI artifact (mutable latest) | |
| run: | | |
| set -euo pipefail | |
| oras push "${REF_MUTABLE}" \ | |
| book.tar.gz:application/gzip \ | |
| --annotation org.opencontainers.image.title="book.tar.gz" \ | |
| --annotation org.opencontainers.image.source="${{ github.repository }}" \ | |
| --annotation org.opencontainers.image.revision="${{ github.sha }}" | |
| - name: Copy to immutable SHA tag | |
| run: | | |
| set -euo pipefail | |
| oras copy "${REF_MUTABLE}" "${REF_IMMUTABLE}" | |
| - name: Make GHCR package public | |
| # This uses gh CLI to set visibility; repo must allow Actions to create a public package. | |
| # Package name matches ghcr repo path without registry and tag | |
| # criterion.rs-book is the package under org criterion-rs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| gh api \ | |
| -X PATCH \ | |
| -H "Accept: application/vnd.github+json" \ | |
| /orgs/criterion-rs/packages/container/criterion.rs-book/visibility \ | |
| -f visibility=public | |
| - name: Repository Dispatch | |
| uses: peter-evans/repository-dispatch@v4 | |
| with: | |
| token: ${{ secrets.DISPATCH_TOKEN }} | |
| repository: criterion-rs/criterion-rs.github.io | |
| event-type: publish-book |