fix: normalize hyphenated search terms, fixes #602 #16
Workflow file for this run
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
| # Deploy job for fork PRs. Triggered by workflow_run after the build completes. | |
| # This job has access to secrets but never checks out or executes any fork code. | |
| name: Cloudflare Pages preview (forked PRs) - Deploy | |
| on: | |
| workflow_run: | |
| workflows: ["Cloudflare Pages preview (forked PRs) - Build"] | |
| types: [completed] | |
| pull_request_target: | |
| types: [closed] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| deploy: | |
| name: Deploy preview to Cloudflare Pages | |
| # Only run when the build succeeded and the PR came from a fork (not same repo). | |
| if: | | |
| github.event_name == 'workflow_run' && | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.head_repository.full_name != github.repository | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Load secrets | |
| uses: 1password/load-secrets-action@v4 | |
| with: | |
| export-env: true | |
| env: | |
| OP_SERVICE_ACCOUNT_TOKEN: "${{ secrets.TESTS_SERVICE_ACCOUNT_TOKEN }}" | |
| CF_API_TOKEN: "op://test-secrets/CF_API_TOKEN/credential" | |
| - name: Check required variables | |
| env: | |
| CF_ACCOUNT_ID: ${{ vars.CF_ACCOUNT_ID }} | |
| CF_PAGES_PROJECT: ${{ vars.CF_PAGES_PROJECT }} | |
| run: | | |
| missing=0 | |
| for v in CF_API_TOKEN CF_ACCOUNT_ID CF_PAGES_PROJECT; do | |
| if [ -z "${!v}" ]; then | |
| echo "::error::Missing variable '$v'." | |
| missing=1 | |
| fi | |
| done | |
| [ "$missing" -ne 0 ] && exit 1 || true | |
| - name: Download built artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: site-dist | |
| path: site-dist | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get PR number | |
| id: pr | |
| run: echo "number=$(cat site-dist/pr-number.txt)" >> "$GITHUB_OUTPUT" | |
| - name: Deploy to Cloudflare Pages | |
| id: pages | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ env.CF_API_TOKEN }} | |
| accountId: ${{ vars.CF_ACCOUNT_ID }} | |
| command: pages deploy site-dist --project-name=${{ vars.CF_PAGES_PROJECT }} --branch=pr-${{ steps.pr.outputs.number }} | |
| gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Comment preview URL | |
| if: always() | |
| uses: actions/github-script@v8 | |
| env: | |
| DEPLOYMENT_URL: ${{ steps.pages.outputs.deployment-url }} | |
| BRANCH_URL: ${{ steps.pages.outputs.pages-deployment-alias-url }} | |
| PR_NUMBER: ${{ steps.pr.outputs.number }} | |
| with: | |
| script: | | |
| const url = process.env.BRANCH_URL || process.env.DEPLOYMENT_URL || ''; | |
| if (!url) return; | |
| const prNumber = Number(process.env.PR_NUMBER); | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const existing = comments.find(c => | |
| (c.user?.login === 'github-actions[bot]' || c.user?.type === 'Bot') && | |
| c.body?.includes('Fork Preview for PR') | |
| ); | |
| const body = `🌐 **Fork Preview for PR #${prNumber}**\n\n${url}\n\n*This preview updates automatically when you push changes to your fork.*`; | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body, | |
| }); | |
| } | |
| closed-note: | |
| name: Note on PR close | |
| # pull_request_target is safe here: no code from the fork is checked out or executed. | |
| if: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.fork == true && github.event.action == 'closed' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: 'PR closed. The Cloudflare Pages preview is no longer updated.', | |
| }); |