From d4058874051170c8c4a3af64800ad3110eab8a21 Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Thu, 26 Nov 2026 15:22:36 +0800 Subject: [PATCH] fix(ci): deploy release docs from main --- .github/workflows/on-release-main.yml | 37 +----------- .github/workflows/pages.yml | 83 +++++++++++++++++++++++++++ docs/releasing.md | 6 +- 3 files changed, 89 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/pages.yml diff --git a/.github/workflows/on-release-main.yml b/.github/workflows/on-release-main.yml index 620606a2..2ed2ff9d 100644 --- a/.github/workflows/on-release-main.yml +++ b/.github/workflows/on-release-main.yml @@ -6,12 +6,6 @@ on: permissions: contents: read - pages: write - id-token: write - -concurrency: - group: "pages" - cancel-in-progress: true jobs: set-version: @@ -21,7 +15,7 @@ jobs: - name: Export tag id: vars - run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT + run: printf 'tag=%s\n' "$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT" if: ${{ github.event_name == 'release' }} - name: Update project version @@ -59,32 +53,3 @@ jobs: run: uv publish env: UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }} - - build-docs: - needs: publish - runs-on: ubuntu-latest - steps: - - name: Check out - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 - - - name: Set up the environment - uses: ./.github/actions/setup-python-env - - - name: Build site - run: uv run mkdocs build -f mkdocs.yml --clean - - - name: Upload Pages artifact - uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1 - with: - path: site - - deploy-docs: - needs: build-docs - runs-on: ubuntu-latest - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 00000000..27a71c8b --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,83 @@ +name: Publish release docs + +on: + workflow_run: + workflows: [release-main] + types: [completed] + workflow_dispatch: + inputs: + release-tag: + description: Published release to build (for example, 1.1.0) + required: true + type: string + +permissions: + contents: read + +jobs: + build-docs: + # workflow_run runs on the default branch, even when release-main ran on a tag. + if: >- + github.ref == 'refs/heads/main' && + (github.event_name == 'workflow_dispatch' || + (github.event.workflow_run.event == 'release' && + github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.head_repository.full_name == github.repository)) + runs-on: ubuntu-latest + steps: + - name: Check out main and release history + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Select the release source + env: + GH_TOKEN: ${{ github.token }} + RELEASE_TAG: ${{ inputs.release-tag }} + RELEASE_SHA: ${{ github.event.workflow_run.head_sha }} + run: | + if [[ "$GITHUB_EVENT_NAME" == workflow_dispatch ]]; then + git check-ref-format "refs/tags/$RELEASE_TAG" + published_tag=$(gh release view --repo "$GITHUB_REPOSITORY" \ + --json isDraft,tagName --jq 'select(.isDraft == false) | .tagName' -- "$RELEASE_TAG") + if [[ "$published_tag" != "$RELEASE_TAG" ]]; then + echo "Select a published GitHub Release." >&2 + exit 1 + fi + RELEASE_SHA=$(git rev-parse --verify "refs/tags/${RELEASE_TAG}^{commit}") + fi + + if ! git merge-base --is-ancestor "$RELEASE_SHA" "$GITHUB_SHA"; then + echo "The release commit must be in the history of main." >&2 + exit 1 + fi + git checkout --detach "$RELEASE_SHA" + + - name: Set up the environment + uses: ./.github/actions/setup-python-env + + - name: Build site + run: uv run mkdocs build -f mkdocs.yml --clean + + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1 + with: + path: site + + deploy-docs: + needs: build-docs + runs-on: ubuntu-latest + concurrency: + group: pages + cancel-in-progress: false + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 diff --git a/docs/releasing.md b/docs/releasing.md index 68fd50e6..b4b2ba37 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -35,10 +35,14 @@ Releases are automated by `on-release-main.yml` once the PR lands on `main`. 2. Publishing the release triggers the workflow, which: - Syncs the tag back into `pyproject.toml`. - Builds and uploads to PyPI via `uv publish` using `PYPI_TOKEN`. - - Deploys updated docs with `mkdocs gh-deploy`. +3. After `release-main` succeeds, **Publish release docs** starts on `main`. It builds the MkDocs site from the same commit as the release and deploys it to GitHub Pages. The repository's Pages source is **GitHub Actions**. No local build/publish steps are needed—just provide a clear release summary (highlights, compatibility notes, migration tips). +## Republish docs for a release + +In **Actions → Publish release docs → Run workflow**, select the **`main`** branch and enter the published release tag (for example, `1.1.0`) in **release-tag**. The tag selects the docs to build; the deployment runs from `main`. This does not publish anything to PyPI. After deployment, check that the public quickstart matches the example at the release tag. + ## Extra tips - Breaking schema bumps often mean updating `tests/test_golden.py`, `tests/test_rpc.py`, and any examples touched by new fields.