Publish Rustdoc on GitHub Pages #966
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
| # Copyright 2024 The Fuchsia Authors | |
| # | |
| # Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | |
| # <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | |
| # license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | |
| # This file may not be copied, modified, or distributed except according to | |
| # those terms. | |
| # Publish every commit from `main` to google.github.io/zerocopy. | |
| name: Publish Rustdoc on GitHub Pages | |
| on: | |
| # We trigger this workflow when the "Anneal Tests" workflow completes on the | |
| # main branch. This ensures that we always pick up the latest benchmark | |
| # data that was just computed and pushed to the storage branch. | |
| workflow_run: # zizmor: ignore[dangerous-triggers] | |
| workflows: ["Anneal Tests"] | |
| types: [completed] | |
| branches: [main] | |
| permissions: {} | |
| env: | |
| CARGO_ZEROCOPY_AUTO_INSTALL_TOOLCHAIN: 1 | |
| concurrency: | |
| group: deploy | |
| cancel-in-progress: false | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| defaults: | |
| run: | |
| working-directory: zerocopy | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| with: | |
| persist-credentials: false | |
| - name: Configure GitHub pages | |
| id: pages | |
| uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0 | |
| - name: Cargo doc | |
| # We pass --document-private-items and --document-hidden items to ensure | |
| # that documentation always builds even for these items. This makes | |
| # future changes to make those items public/non-hidden more painless. | |
| # Note that --document-hidden-items is unstable; if a future release | |
| # breaks or removes it, we can just update CI to no longer pass that | |
| # flag. | |
| run: | | |
| set -eo pipefail | |
| ZC_NIGHTLY_TOOLCHAIN="$(./cargo.sh --version nightly)" | |
| echo "Found that the 'nightly' toolchain is $ZC_NIGHTLY_TOOLCHAIN" | tee -a $GITHUB_STEP_SUMMARY | |
| # Include arguments passed during docs.rs deployments to make sure those | |
| # work properly. | |
| # | |
| # TODO(#1228): Use `jq` to parse these from `Cargo.toml` instead of | |
| # hard-coding them once we've gotten it working again. | |
| METADATA_DOCS_RS_RUSTDOC_ARGS="--cfg doc_cfg --cfg zerocopy_unstable_ptr --generate-link-to-definition --extend-css $PWD/rustdoc/style.css" | |
| export RUSTDOCFLAGS="-Z unstable-options --document-hidden-items $METADATA_DOCS_RS_RUSTDOC_ARGS" | |
| # TODO: Use `./cargo.sh` instead once we've debugged why it won't work. | |
| cargo +$ZC_NIGHTLY_TOOLCHAIN doc --document-private-items --package zerocopy --all-features | |
| - name: Add HTML redirect to doc root | |
| # By default, Rustdoc doesn't redirect to the documentation root, so we | |
| # manually generate a redirect. | |
| run: echo '<meta http-equiv="refresh" content="0;url=zerocopy/index.html">' > target/doc/index.html | |
| - name: Checkout benchmark data | |
| # We check out the dedicated branch where benchmark history is stored. | |
| # We put it in a temporary directory to avoid conflicts with the main | |
| # checkout. | |
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| with: | |
| ref: benchmark-data | |
| path: temp-bench | |
| persist-credentials: false | |
| - name: Move benchmark files | |
| # We copy the dashboard files generated by the benchmark action into | |
| # the documentation folder so they get published to GitHub Pages. | |
| run: | | |
| mkdir -p target/doc/bench | |
| if [ -d ../temp-bench/dashboard ]; then | |
| cp -r ../temp-bench/dashboard/* target/doc/bench/ | |
| else | |
| echo "No benchmark dashboard files found to copy." | |
| fi | |
| - name: Upload Cargo doc output to GitHub Pages | |
| uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 | |
| with: | |
| path: zerocopy/target/doc | |
| deploy: | |
| name: Deploy to GitHub Pages | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| pages: write # Required for Pages deployment | |
| id-token: write # Required for OIDC-based Pages deployment | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0 |