Add pr-number input to cloudflare-pages-preview actions
Both deploy and cleanup previously read context.payload.pull_request.number directly, which throws on workflow_dispatch and other non-PR triggers. New optional inputs: - deploy: pr-number (default: event PR number), commit-sha (default: github.sha) - cleanup: pr-number (default: event PR number) If pr-number resolves to empty/0, the comment step is skipped gracefully instead of crashing. This lets /stageblog's companion workflow_dispatch receiver call the composite deploy action directly instead of inlining wrangler + noindex injection. The noindex logic staying in the actions repo (rather than in a script file inside the caller repo that gets checked out at the fork's SHA) is also the secure path — fork authors can't tamper with it. The slash-commands README example is updated to use the deploy action with the new inputs. The earlier commit on this branch (which rewrote the example to call wrangler directly) is effectively superseded.
This commit is contained in:
parent
38a01a9736
commit
a4bb78216a
1 changed files with 48 additions and 43 deletions
|
|
@ -172,49 +172,19 @@ jobs:
|
|||
|
||||
# ... your blog build steps → output to blog/public ...
|
||||
|
||||
# cloudflare-pages-preview/deploy cannot be used here — its comment
|
||||
# step reads context.payload.pull_request.number, which is undefined
|
||||
# on workflow_dispatch and will throw. Call wrangler directly:
|
||||
- name: Inject noindex
|
||||
run: |
|
||||
echo -e '/*\n X-Robots-Tag: noindex, nofollow, noarchive, nosnippet' > blog/public/_headers
|
||||
find blog/public -name '*.html' -print0 | \
|
||||
xargs -0 -r sed -i 's|<head>|<head><meta name="robots" content="noindex, nofollow">|'
|
||||
|
||||
- id: deploy
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
- uses: modelcontextprotocol/actions/cloudflare-pages-preview/deploy@main
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_PAGES_PREVIEW_API_TOKEN }}
|
||||
accountId: ${{ secrets.CF_PAGES_PREVIEW_ACCOUNT_ID }}
|
||||
command: pages deploy blog/public --project-name=mcp-blog-preview --branch=pr-${{ inputs.pr_number }}
|
||||
|
||||
- uses: actions/github-script@v8
|
||||
env:
|
||||
PR_NUMBER: ${{ inputs.pr_number }}
|
||||
HEAD_SHA: ${{ inputs.head_sha }}
|
||||
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
|
||||
ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
|
||||
with:
|
||||
script: |
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: Number(process.env.PR_NUMBER),
|
||||
body: `## Blog Preview (staged via /stageblog)\n\n` +
|
||||
`| | |\n|---|---|\n` +
|
||||
`| **Preview (stable)** | ${process.env.ALIAS_URL} |\n` +
|
||||
`| **This commit** | ${process.env.DEPLOY_URL} |\n` +
|
||||
`| **Commit** | \`${process.env.HEAD_SHA.slice(0,7)}\` |\n\n` +
|
||||
`_Includes drafts and future-dated posts. noindex headers set._`,
|
||||
});
|
||||
directory: blog/public
|
||||
project-name: mcp-blog-preview
|
||||
api-token: ${{ secrets.CF_PAGES_PREVIEW_API_TOKEN }}
|
||||
account-id: ${{ secrets.CF_PAGES_PREVIEW_ACCOUNT_ID }}
|
||||
branch: pr-${{ inputs.pr_number }}
|
||||
pr-number: ${{ inputs.pr_number }}
|
||||
commit-sha: ${{ inputs.head_sha }}
|
||||
comment-title: "Blog Preview (staged via /stageblog)"
|
||||
comment-marker: "<!-- stage-blog-comment -->"
|
||||
```
|
||||
|
||||
> **Known limitation:** `cloudflare-pages-preview/deploy` currently reads
|
||||
> `context.payload.pull_request.number` unconditionally in its comment step,
|
||||
> which throws on `workflow_dispatch`. Until the deploy action accepts an
|
||||
> explicit `pr-number` input, bypass it and call `cloudflare/wrangler-action`
|
||||
> directly as shown above. (Fixing deploy is a follow-up.)
|
||||
|
||||
## Inputs
|
||||
|
||||
| Input | Required | Default | Description |
|
||||
|
|
|
|||
Loading…
Reference in a new issue