From e37a7bc4fb081e7c4e4c799c0977b0ae63a67083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ad=C3=A1mek?= Date: Tue, 17 Nov 2026 11:09:15 +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 | 30 +++++++----- .github/workflows/manual_version_docs.yaml | 54 ++++++++++++++++++++-- website/package.json | 3 +- 3 files changed, 71 insertions(+), 16 deletions(-) diff --git a/.github/workflows/manual_release_docs.yaml b/.github/workflows/manual_release_docs.yaml index a2287dc289..7dfea5beea 100644 --- a/.github/workflows/manual_release_docs.yaml +++ b/.github/workflows/manual_release_docs.yaml @@ -27,14 +27,10 @@ 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 @@ -52,7 +48,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ inputs.ref }} - token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + persist-credentials: false - name: Set up Node uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 @@ -83,14 +79,26 @@ 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 a job that does not run the docs toolchain. + 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 e97160c879..e63c10a5c3 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 @@ -122,10 +129,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 a351f473c7..9c36c22d9d 100644 --- a/website/package.json +++ b/website/package.json @@ -22,8 +22,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/docusaurus-plugin-typedoc-api": "^5.1.16",