name: Sync documentation on: # A maintainer publishes the draft GitHub release after approving the staged # npm packages. A release event runs the workflow file from the tag, so it # only dispatches the sync from the default branch. The token is limited to # the push step. release: types: [published] workflow_dispatch: inputs: release_tag: description: Optional published release tag; leave empty to publish all docs from main required: false type: string docs_commit: description: Optional full SHA of a docs-only correction based on that tag type: string permissions: contents: read jobs: dispatch: if: >- github.event_name == 'release' && (startsWith(github.event.release.tag_name, 'v11.') || startsWith(github.event.release.tag_name, 'v12.') || startsWith(github.event.release.tag_name, 'pnpr@')) runs-on: ubuntu-latest permissions: actions: write steps: - name: Dispatch the sync from the default branch env: GH_TOKEN: ${{ github.token }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} RELEASE_TAG: ${{ github.event.release.tag_name }} run: gh workflow run sync-docs.yml -R "$GITHUB_REPOSITORY" --ref "$DEFAULT_BRANCH" -f release_tag="$RELEASE_TAG" sync: if: github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest outputs: publish: ${{ steps.source.outputs.publish }} main_sync: ${{ steps.source.outputs.main_sync }} docs_commit: ${{ steps.source.outputs.docs_commit }} line: ${{ steps.source.outputs.line }} version: ${{ steps.source.outputs.version }} website_commit: ${{ steps.website.outputs.commit }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - name: Select the main or released documentation snapshot id: source env: RELEASE_TAG: ${{ inputs.release_tag }} DOCS_COMMIT: ${{ inputs.docs_commit }} run: | export GNUPGHOME="$(mktemp -d)" chmod 700 "$GNUPGHOME" trap 'rm -rf "$GNUPGHOME"' EXIT gpg --batch --quiet --import .github/release-keys/*.asc node .github/scripts/prepare-docs-sync.mjs - name: Check out the documentation snapshot if: steps.source.outputs.publish == 'true' env: DOCS_COMMIT: ${{ steps.source.outputs.docs_commit }} run: git worktree add --detach "$RUNNER_TEMP/docs-source" "$DOCS_COMMIT" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 if: steps.source.outputs.publish == 'true' with: repository: pnpm/pnpm.io ref: main path: website persist-credentials: false - name: Record the website revision before executing website code if: steps.source.outputs.publish == 'true' id: website working-directory: website run: echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - uses: pnpm/setup@a0881977cd8ea73b1ed212236c99ca10dcc80cf4 # v3.1.1 if: steps.source.outputs.publish == 'true' with: runtime: node@22 install: false - name: Install the website dependencies if: steps.source.outputs.publish == 'true' working-directory: website run: pnpm install --frozen-lockfile - name: Sync and verify the pages if: steps.source.outputs.publish == 'true' working-directory: website env: MAIN_SYNC: ${{ steps.source.outputs.main_sync }} LINE: ${{ steps.source.outputs.line }} VERSION: ${{ steps.source.outputs.version }} RELEASE_COMMIT: ${{ steps.source.outputs.release_commit }} DOCS_COMMIT: ${{ steps.source.outputs.docs_commit }} run: | if [ "$MAIN_SYNC" = true ]; then node scripts/sync-docs.mjs "$RUNNER_TEMP/docs-source" --preview else node scripts/sync-docs.mjs "$RUNNER_TEMP/docs-source" "$LINE" "$VERSION" "$RELEASE_COMMIT" "$DOCS_COMMIT" fi pnpm build pnpm check-urls - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: steps.source.outputs.publish == 'true' with: name: generated-documentation retention-days: 1 if-no-files-found: error path: | website/docs website/pnpr-docs website/versioned_docs/version-11.x website/sidebars.json website/sidebars-pnpr.json website/versioned_sidebars/version-11.x-sidebars.json website/static/docs-assets website/blog/releases website/docs-sync.json publish: needs: sync if: needs.sync.outputs.publish == 'true' runs-on: ubuntu-latest environment: docs-sync steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: pnpm/pnpm.io ref: ${{ needs.sync.outputs.website_commit }} path: website persist-credentials: false - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: generated-documentation path: generated-documentation - name: Copy only documentation into the clean checkout run: node .github/scripts/copy-docs-artifact.mjs generated-documentation website - name: Commit the generated documentation id: commit working-directory: website env: MAIN_SYNC: ${{ needs.sync.outputs.main_sync }} DOCS_COMMIT: ${{ needs.sync.outputs.docs_commit }} VERSION: ${{ needs.sync.outputs.version }} LINE: ${{ needs.sync.outputs.line }} run: | git add docs pnpr-docs sidebars-pnpr.json versioned_docs/version-11.x versioned_sidebars/version-11.x-sidebars.json sidebars.json static/docs-assets blog/releases docs-sync.json if git diff --cached --quiet; then exit 0; fi git config user.name 'pnpm docs sync' git config user.email 'pnpm-docs-sync@users.noreply.github.com' if [ "$MAIN_SYNC" = true ]; then title="docs: sync product documentation from main" else title="docs: sync ${LINE} documentation for ${VERSION}" fi git commit -m "$title" -m "Generated from pnpm/pnpm commit ${DOCS_COMMIT}. Written by release automation." echo 'changed=true' >> "$GITHUB_OUTPUT" - name: Push the verified documentation commit if: steps.commit.outputs.changed == 'true' working-directory: website env: GH_TOKEN: ${{ secrets.DOCS_SYNC_TOKEN }} run: | test -n "$GH_TOKEN" || { echo '::error::Configure DOCS_SYNC_TOKEN in the docs-sync environment'; exit 1; } gh auth setup-git git push origin HEAD:main