Docs Preview Deploy #1979
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docs Preview Deploy | |
| on: | |
| workflow_run: | |
| workflows: ["Docs Preview Build"] | |
| types: [completed] | |
| jobs: | |
| deploy: | |
| name: Deploy Docs & Snippets | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| environment: docs-development | |
| steps: | |
| # Extract PR metadata | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: pr-metadata | |
| path: ./pr-metadata | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - id: pr-metadata | |
| run: | | |
| echo "pr_number=$(cat ./pr-metadata/pr-number.txt)" >> $GITHUB_OUTPUT | |
| echo "pr_head_ref=$(cat ./pr-metadata/pr-head-ref.txt)" >> $GITHUB_OUTPUT | |
| echo "pr_head_sha=$(cat ./pr-metadata/pr-head-sha.txt)" >> $GITHUB_OUTPUT | |
| # Escape branch name and create short SHA for URL | |
| - id: escape-branch | |
| run: | | |
| BRANCH="$(cat ./pr-metadata/pr-head-ref.txt)" | |
| ESCAPED="${BRANCH//\//-}" | |
| echo "branch=$ESCAPED" >> $GITHUB_OUTPUT | |
| - id: short-sha | |
| run: | | |
| SHA="$(cat ./pr-metadata/pr-head-sha.txt)" | |
| echo "sha=${SHA:0:7}" >> $GITHUB_OUTPUT | |
| # Deploy Snippets | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: docs-snippets-build | |
| path: ./docs-snippets--build | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - uses: cloudflare/wrangler-action@v3 | |
| id: publish-docs-snippets | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ vars.CLOUDFLARE_ACCOUNT_ID }} | |
| command: pages deploy ./docs-snippets--build --project-name=${{ vars.CLOUDFLARE_SNIPPETS_PROJECT_NAME }} --branch=${{ steps.escape-branch.outputs.branch }}-${{ steps.short-sha.outputs.sha }} | |
| # Deploy docs | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: main | |
| sparse-checkout: | | |
| docs/package.json | |
| docs/pnpm-lock.yaml | |
| docs/wrangler.jsonc | |
| docs/open-next.config.ts | |
| .github/deployment_preview_template.md | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: docs-build | |
| path: ./docs | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Extract docs build | |
| working-directory: ./docs | |
| run: tar -xf docs-build.tar && rm docs-build.tar | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| - uses: pnpm/action-setup@v5 | |
| with: | |
| version: 10 | |
| - name: Deploy docs to Cloudflare Workers | |
| id: publish-docs | |
| working-directory: ./docs | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }} | |
| run: | | |
| pnpm install | |
| set +e | |
| OUTPUT=$(pnpm exec opennextjs-cloudflare upload -- --env dev 2>&1) | |
| EXIT_CODE=$? | |
| echo "$OUTPUT" | |
| PREVIEW_URL=$(echo "$OUTPUT" | grep "Version Preview URL:" | awk '{print $NF}') | |
| echo "preview-url=$PREVIEW_URL" >> $GITHUB_OUTPUT | |
| exit $EXIT_CODE | |
| # Create/update comment with link to preview | |
| - uses: actions/create-github-app-token@v3 | |
| id: generate-token | |
| with: | |
| app-id: ${{ secrets.AUTO_MAID_APP_ID }} | |
| private-key: ${{ secrets.AUTO_MAID_PRIVATE_KEY }} | |
| - uses: peter-evans/find-comment@v4 | |
| id: find-comment | |
| with: | |
| issue-number: ${{ steps.pr-metadata.outputs.pr_number }} | |
| comment-author: 'auto-maid[bot]' | |
| - uses: chuhlomin/render-template@v1.12 | |
| id: render-markdown | |
| with: | |
| template: .github/deployment_preview_template.md | |
| vars: | | |
| sha: ${{ steps.pr-metadata.outputs.pr_head_sha }} | |
| url: ${{ steps.publish-docs.outputs.preview-url }} | |
| - uses: peter-evans/create-or-update-comment@v5 | |
| with: | |
| token: ${{ steps.generate-token.outputs.token }} | |
| comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
| issue-number: ${{ steps.pr-metadata.outputs.pr_number }} | |
| body: ${{ steps.render-markdown.outputs.result }} | |
| edit-mode: replace | |
| # Check that all relative URLs are working | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.26' | |
| - run: go install github.com/raviqqe/muffet/v2@latest | |
| - run: muffet ${{ steps.publish-docs.outputs.preview-url }} --buffer-size=32768 --exclude="(\/cdn-cgi\/)|(github.com)|(pub.dev)|(shadcn.com)" |