From 1dfaa1f4cece710d2ac4d811e6616fd147cf04e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ad=C3=A1mek?= Date: Tue, 17 Nov 2026 11:09:11 +0100 Subject: [PATCH] ci: split the docs workflows into build, commit and deploy jobs The docs toolchain now runs in a job with a read-only token. The signed commit, the Pages deploy and the CloudFront invalidation run in separate jobs that do not install or build anything. Also drops the `npx only-allow pnpm` preinstall hook from the website. --- .github/workflows/manual_release_docs.yaml | 84 +++++++++++++++++----- .github/workflows/manual_version_docs.yaml | 54 +++++++++++++- website/package.json | 3 +- 3 files changed, 119 insertions(+), 22 deletions(-) diff --git a/.github/workflows/manual_release_docs.yaml b/.github/workflows/manual_release_docs.yaml index dc78e0f6..c88a401d 100644 --- a/.github/workflows/manual_release_docs.yaml +++ b/.github/workflows/manual_release_docs.yaml @@ -27,16 +27,14 @@ env: PYTHON_VERSION: 3.14 jobs: - release_docs: - name: Release docs - environment: - name: github-pages + build_docs: + name: Build docs permissions: - contents: write - pages: write - id-token: write + contents: read checks: read runs-on: ubuntu-latest + outputs: + sha: ${{ steps.sha.outputs.sha }} steps: # Gate manual dispatches on the `Checks` workflow already succeeding on this commit (run by `on_master.yaml`); @@ -52,7 +50,11 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ inputs.ref }} - token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + persist-credentials: false + + - name: Record the built commit + id: sha + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - name: Set up Node uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 @@ -81,13 +83,14 @@ jobs: - name: Update docs theme run: uv run poe update-docs-theme - - name: Commit the updated package.json and lockfile - uses: apify/actions/signed-commit@v1.6.2 + - name: Upload the updated package.json and lockfile + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - message: "chore: Automatic docs theme update [skip ci]" - add: website/package.json website/pnpm-lock.yaml - pull: --rebase --autostash - github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + name: docs-theme-update + path: | + website/package.json + website/pnpm-lock.yaml + retention-days: 1 - name: Build docs run: uv run poe build-docs @@ -95,14 +98,61 @@ jobs: APIFY_SIGNING_TOKEN: ${{ secrets.APIFY_SIGNING_TOKEN }} SEGMENT_TOKEN: ${{ secrets.SEGMENT_TOKEN }} - - name: Set up GitHub Pages - uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0 - - name: Upload GitHub Pages artifact uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 with: path: ./website/build + # The service account token is only used in jobs that do not run the docs toolchain. + commit_docs_theme: + name: Commit docs theme update + needs: [build_docs] + permissions: + contents: read + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.ref }} + fetch-depth: 0 + persist-credentials: false + + # Start from the commit the update was made on, so the pull below merges it with anything pushed since. + - name: Reset to the built commit + run: git reset --hard "$BUILT_SHA" + env: + BUILT_SHA: ${{ needs.build_docs.outputs.sha }} + + - name: Download the updated package.json and lockfile + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: docs-theme-update + path: website + + - name: Commit the updated package.json and lockfile + uses: apify/actions/signed-commit@v1.6.2 + with: + message: "chore: Automatic docs theme update [skip ci]" + add: website/package.json website/pnpm-lock.yaml + pull: --rebase --autostash + github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + + deploy_docs: + name: Deploy docs + needs: [build_docs] + environment: + name: github-pages + permissions: + pages: write + id-token: write + runs-on: ubuntu-latest + + steps: + - name: Set up GitHub Pages + uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0 + - name: Deploy artifact to GitHub Pages uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 diff --git a/.github/workflows/manual_version_docs.yaml b/.github/workflows/manual_version_docs.yaml index e8821592..38e03ae0 100644 --- a/.github/workflows/manual_version_docs.yaml +++ b/.github/workflows/manual_version_docs.yaml @@ -35,8 +35,11 @@ jobs: name: Version docs runs-on: ubuntu-latest permissions: - contents: write + contents: read checks: read + outputs: + sha: ${{ steps.sha.outputs.sha }} + version: ${{ steps.snapshot.outputs.version }} steps: # Gate manual dispatches on the `Checks` workflow already succeeding on this commit (run by `on_master.yaml`); @@ -51,7 +54,11 @@ jobs: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + persist-credentials: false + + - name: Record the built commit + id: sha + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - name: Set up Node uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 @@ -123,10 +130,51 @@ jobs: uv run pnpm exec docusaurus docs:version "$MAJOR_MINOR_VERSION" uv run pnpm exec docusaurus api:version "$MAJOR_MINOR_VERSION" + - name: Upload versioned docs + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: versioned-docs + path: | + website/versioned_docs + website/versioned_sidebars + website/versions.json + include-hidden-files: true + retention-days: 1 + + # The service account token is only used in a job that does not run the docs toolchain. + commit_versioned_docs: + name: Commit versioned docs + needs: [version_docs] + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + # Start from the commit the snapshot was made on, so the pull below merges it with anything pushed since. + - name: Reset to the built commit + run: git reset --hard "$BUILT_SHA" + env: + BUILT_SHA: ${{ needs.version_docs.outputs.sha }} + + - name: Remove the previous snapshot + run: rm -rf website/versioned_docs website/versioned_sidebars website/versions.json + + - name: Download versioned docs + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: versioned-docs + path: website + - name: Commit and push versioned docs uses: apify/actions/signed-commit@v1.6.2 with: - message: "docs: Version docs for v${{ steps.snapshot.outputs.version }} [skip ci]" + message: "docs: Version docs for v${{ needs.version_docs.outputs.version }} [skip ci]" add: website/versioned_docs website/versioned_sidebars website/versions.json pull: --rebase --autostash github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} diff --git a/website/package.json b/website/package.json index 4239c590..575a42d8 100644 --- a/website/package.json +++ b/website/package.json @@ -20,8 +20,7 @@ "lint:code:fix": "oxlint --type-aware --fix", "format": "oxfmt", "format:check": "oxfmt --check", - "opt:images": "pnx --config.onlyBuiltDependencies=* @343dev/optimizt --webp", - "preinstall": "npx only-allow pnpm" + "opt:images": "pnx --config.onlyBuiltDependencies=* @343dev/optimizt --webp" }, "dependencies": { "@apify/docs-theme": "^1.0.287",