| # Copyright 2026 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 commits from `main` which pass `CI (Trusted)` to | |
| # google.github.io/anneal. | |
| name: Publish Docs on GitHub Pages | |
| on: | |
| # These workflow names are coupled to `.github/workflows/ci-core-trusted.yml` | |
| # and `.github/workflows/anneal-perf.yml`. Triggering on `ci-core-trusted.yml` | |
| # publishes Pages once main-branch CI succeeds; triggering on `anneal-perf.yml` | |
| # refreshes Pages if performance telemetry finishes publishing to | |
| # `benchmark-data` after `CI (Trusted)` has completed (or on scheduled/manual | |
| # perf runs on `main` HEAD). | |
| workflow_run: # zizmor: ignore[dangerous-triggers] | |
| workflows: | |
| - "CI (Trusted)" | |
| - "Anneal Performance Tracking" | |
| types: [completed] | |
| branches: [main] | |
| permissions: {} | |
| concurrency: | |
| group: deploy | |
| cancel-in-progress: false | |
| jobs: | |
| coordinate: | |
| name: Verify CI workflows and deploy readiness | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| # Only main-branch runs in google/anneal publish documentation. CI | |
| # (Trusted) must be a main-branch `push` run that succeeded; Anneal | |
| # Performance Tracking may run via `push`, `schedule`, or | |
| # `workflow_dispatch` on `main` and may conclude `failure` when its final | |
| # budget gate fails *after* publishing telemetry to `benchmark-data`. | |
| if: | | |
| github.repository == 'google/anneal' && | |
| github.event.workflow_run.head_repository.full_name == github.repository && | |
| github.event.workflow_run.head_branch == 'main' && | |
| ( | |
| ( | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' | |
| ) || | |
| ( | |
| github.event.workflow_run.name == 'Anneal Performance Tracking' && | |
| ( | |
| github.event.workflow_run.event == 'push' || | |
| github.event.workflow_run.event == 'schedule' || | |
| github.event.workflow_run.event == 'workflow_dispatch' | |
| ) && | |
| ( | |
| github.event.workflow_run.conclusion == 'success' || | |
| github.event.workflow_run.conclusion == 'failure' | |
| ) | |
| ) | |
| ) | |
| permissions: | |
| actions: read # Query canonical ci-core-trusted.yml push runs and perf publish step status | |
| contents: read # Resolve refs/heads/main tip SHA | |
| outputs: | |
| deploy: ${{ steps.coordinate.outputs.deploy }} | |
| sha: ${{ steps.coordinate.outputs.sha }} | |
| steps: | |
| - name: Select the deployment-ready main SHA | |
| id: coordinate | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| REPOSITORY: ${{ github.repository }} | |
| SOURCE_SHA: ${{ github.event.workflow_run.head_sha }} | |
| TRIGGER_RUN_ID: ${{ github.event.workflow_run.id }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| TRIGGER_RUN="$( | |
| gh api --method GET \ | |
| -H 'X-GitHub-Api-Version: 2022-11-28' \ | |
| "repos/$REPOSITORY/actions/runs/$TRIGGER_RUN_ID" | |
| )" | |
| TRIGGER_PATH="$(jq -r '.path // ""' <<< "$TRIGGER_RUN")" | |
| TRIGGER_IS_PERF=false | |
| if [ "$TRIGGER_PATH" = ".github/workflows/anneal-perf.yml" ]; then | |
| TRIGGER_IS_PERF=true | |
| if ! jq -e --arg REPO "$REPOSITORY" --arg SHA "$SOURCE_SHA" ' | |
| .head_repository.full_name == $REPO | |
| and .head_branch == "main" | |
| and .head_sha == $SHA | |
| and ( | |
| .event == "push" | |
| or .event == "schedule" | |
| or .event == "workflow_dispatch" | |
| ) | |
| and .status == "completed" | |
| and (.conclusion == "success" or .conclusion == "failure") | |
| ' <<< "$TRIGGER_RUN" >/dev/null; then | |
| echo "Ignoring non-main or incomplete performance run $TRIGGER_RUN_ID" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| # Query by filename so a future run-name collision cannot | |
| # impersonate `.github/workflows/anneal-perf.yml`. | |
| PERF_RESPONSE="$( | |
| gh api --method GET \ | |
| -H 'X-GitHub-Api-Version: 2022-11-28' \ | |
| "repos/$REPOSITORY/actions/workflows/anneal-perf.yml/runs" \ | |
| -f branch=main \ | |
| -f head_sha="$SOURCE_SHA" \ | |
| -F per_page=100 | |
| )" | |
| if ! jq -e --arg ID "$TRIGGER_RUN_ID" --arg SHA "$SOURCE_SHA" ' | |
| any( | |
| .workflow_runs[]; | |
| (.id | tostring) == $ID | |
| and .head_sha == $SHA | |
| and .head_branch == "main" | |
| and .status == "completed" | |
| ) | |
| ' <<< "$PERF_RESPONSE" >/dev/null; then | |
| echo "Run $TRIGGER_RUN_ID does not belong to anneal-perf.yml for $SOURCE_SHA" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| PUBLISH_CONCLUSION="$( | |
| gh api --method GET \ | |
| -H 'X-GitHub-Api-Version: 2022-11-28' \ | |
| "repos/$REPOSITORY/actions/runs/$TRIGGER_RUN_ID/jobs?per_page=100" \ | |
| --jq ' | |
| [.jobs[] | |
| | select(.name == "Collect and publish performance telemetry") | |
| | .steps[] | |
| | select(.name == "Publish telemetry and dashboard") | |
| | .conclusion] | |
| | first // "missing" | |
| ' | |
| )" | |
| echo "- Anneal Performance Tracking: publish=$PUBLISH_CONCLUSION ($(jq -r '.html_url' <<< "$TRIGGER_RUN"))" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| if [ "$PUBLISH_CONCLUSION" != "success" ]; then | |
| echo "Performance run $TRIGGER_RUN_ID did not publish telemetry; skipping deploy" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| fi | |
| # Coupled to `on.workflow_run.workflows` above. Query by filename so | |
| # a future run-name collision cannot satisfy this deployment gate. | |
| RESPONSE="$( | |
| gh api --method GET \ | |
| -H 'X-GitHub-Api-Version: 2022-11-28' \ | |
| "repos/$REPOSITORY/actions/workflows/ci-core-trusted.yml/runs" \ | |
| -f branch=main \ | |
| -f event=push \ | |
| -f head_sha="$SOURCE_SHA" \ | |
| -F per_page=100 | |
| )" | |
| RUN="$( | |
| jq -c --arg SHA "$SOURCE_SHA" ' | |
| [.workflow_runs[] | |
| | select( | |
| .head_sha == $SHA | |
| and .head_branch == "main" | |
| and .event == "push" | |
| )] | |
| | sort_by([.updated_at, .id]) | |
| | last // empty | |
| ' <<< "$RESPONSE" | |
| )" | |
| if [ -z "$RUN" ]; then | |
| echo "No ci-core-trusted.yml push run exists for $SOURCE_SHA" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| jq -r ' | |
| "- \(.name): \(.status) / \(.conclusion // "pending") (\(.html_url))" | |
| ' <<< "$RUN" >> "$GITHUB_STEP_SUMMARY" | |
| if ! jq -e ' | |
| .status == "completed" and .conclusion == "success" | |
| ' <<< "$RUN" >/dev/null; then | |
| echo "CI (Trusted) has not succeeded for $SOURCE_SHA" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| if [ "$TRIGGER_IS_PERF" != "true" ]; then | |
| WINNER_RUN_ID="$(jq -r '.id' <<< "$RUN")" | |
| if [ "$WINNER_RUN_ID" != "$TRIGGER_RUN_ID" ]; then | |
| echo "Run $WINNER_RUN_ID owns deployment for $SOURCE_SHA" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| fi | |
| # A manually rerun workflow retains event `push` even after its | |
| # commit stops being the tip of main. Never let such a stale run | |
| # replace newer Pages content. | |
| MAIN_SHA="$( | |
| gh api \ | |
| -H 'X-GitHub-Api-Version: 2022-11-28' \ | |
| "repos/$REPOSITORY/git/ref/heads/main" \ | |
| --jq .object.sha | |
| )" | |
| if [ "$MAIN_SHA" != "$SOURCE_SHA" ]; then | |
| echo "Refusing to replace $MAIN_SHA docs with stale $SOURCE_SHA" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| echo "deploy=true" >> "$GITHUB_OUTPUT" | |
| echo "sha=$SOURCE_SHA" >> "$GITHUB_OUTPUT" | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| needs: coordinate | |
| if: needs.coordinate.outputs.deploy == 'true' | |
| permissions: | |
| contents: read # Check out verified main SHA and benchmark-data branch. | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| # `workflow_run` otherwise checks out the latest default branch, | |
| # which may not be the commit whose tests caused this deployment. | |
| ref: ${{ needs.coordinate.outputs.sha }} | |
| persist-credentials: false | |
| - name: Configure GitHub pages | |
| id: pages | |
| uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0 | |
| - 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: benchmark-data | |
| path: temp-bench | |
| persist-credentials: false | |
| - name: Install Zola | |
| uses: ./.github/actions/install-zola | |
| - name: Build Anneal landing page | |
| env: | |
| # Zola templates can read environment variables, so strip GitHub | |
| # Actions cache and artifact service credentials. | |
| ACTIONS_CACHE_URL: '' | |
| ACTIONS_RESULTS_URL: '' | |
| ACTIONS_RUNTIME_TOKEN: '' | |
| PAGES_BASE_URL: ${{ steps.pages.outputs.base_url }} | |
| run: | | |
| set -euo pipefail | |
| python3 -I -B ci/build_site.py build \ | |
| --base-url "${PAGES_BASE_URL%/}" \ | |
| --output-dir "${GITHUB_WORKSPACE}/target/pages" | |
| - name: Assemble GitHub Pages output | |
| run: | | |
| set -euo pipefail | |
| mkdir -p target/pages/bench | |
| if [ -d temp-bench/dashboard ]; then | |
| cp -r temp-bench/dashboard/* target/pages/bench/ | |
| else | |
| echo "No benchmark dashboard files found to copy." | |
| fi | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 | |
| with: | |
| path: target/pages | |
| deploy: | |
| name: Deploy to GitHub Pages | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: [coordinate, build] | |
| permissions: | |
| contents: read # Revalidate current refs/heads/main SHA before deploy. | |
| pages: write # Required for Pages deployment | |
| id-token: write # Required for OIDC-based Pages deployment | |
| steps: | |
| - name: Revalidate current main immediately before deployment | |
| id: current | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| REPOSITORY: ${{ github.repository }} | |
| SOURCE_SHA: ${{ needs.coordinate.outputs.sha }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| MAIN_SHA="$( | |
| gh api \ | |
| -H 'X-GitHub-Api-Version: 2022-11-28' \ | |
| "repos/$REPOSITORY/git/ref/heads/main" \ | |
| --jq .object.sha | |
| )" | |
| if [ "$MAIN_SHA" = "$SOURCE_SHA" ]; then | |
| echo "deploy=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Skipping stale $SOURCE_SHA; current main is $MAIN_SHA" \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| - name: Deploy to GitHub Pages | |
| if: steps.current.outputs.deploy == 'true' | |
| id: deployment | |
| uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 |