Fix README example: use wrangler directly, not deploy action
The cloudflare-pages-preview/deploy action reads context.payload.pull_request.number unconditionally in its comment step, which throws on workflow_dispatch. The previous example would crash. Updated to call wrangler-action directly and post the comment manually.
This commit is contained in:
parent
9fccbf5d69
commit
38a01a9736
1 changed files with 28 additions and 17 deletions
|
|
@ -172,37 +172,48 @@ jobs:
|
||||||
|
|
||||||
# ... your blog build steps → output to blog/public ...
|
# ... your blog build steps → output to blog/public ...
|
||||||
|
|
||||||
- id: deploy
|
# cloudflare-pages-preview/deploy cannot be used here — its comment
|
||||||
uses: modelcontextprotocol/actions/cloudflare-pages-preview/deploy@main
|
# step reads context.payload.pull_request.number, which is undefined
|
||||||
with:
|
# on workflow_dispatch and will throw. Call wrangler directly:
|
||||||
directory: blog/public
|
- name: Inject noindex
|
||||||
project-name: mcp-blog-preview
|
run: |
|
||||||
api-token: ${{ secrets.CF_PAGES_PREVIEW_API_TOKEN }}
|
echo -e '/*\n X-Robots-Tag: noindex, nofollow, noarchive, nosnippet' > blog/public/_headers
|
||||||
account-id: ${{ secrets.CF_PAGES_PREVIEW_ACCOUNT_ID }}
|
find blog/public -name '*.html' -print0 | \
|
||||||
branch: pr-${{ inputs.pr_number }}
|
xargs -0 -r sed -i 's|<head>|<head><meta name="robots" content="noindex, nofollow">|'
|
||||||
|
|
||||||
|
- id: deploy
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
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 }}
|
||||||
|
|
||||||
# NOTE: cloudflare-pages-preview/deploy reads the PR number from
|
|
||||||
# context.payload.pull_request, which is undefined on workflow_dispatch.
|
|
||||||
# Post the preview comment yourself:
|
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v8
|
||||||
env:
|
env:
|
||||||
PR_NUMBER: ${{ inputs.pr_number }}
|
PR_NUMBER: ${{ inputs.pr_number }}
|
||||||
PREVIEW_URL: ${{ steps.deploy.outputs.url }}
|
HEAD_SHA: ${{ inputs.head_sha }}
|
||||||
|
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
|
ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
issue_number: Number(process.env.PR_NUMBER),
|
issue_number: Number(process.env.PR_NUMBER),
|
||||||
body: `Blog preview: ${process.env.PREVIEW_URL}`,
|
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._`,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Known limitation:** `cloudflare-pages-preview/deploy` currently assumes
|
> **Known limitation:** `cloudflare-pages-preview/deploy` currently reads
|
||||||
> `context.payload.pull_request` exists for its sticky-comment step, which is
|
> `context.payload.pull_request.number` unconditionally in its comment step,
|
||||||
> not the case on `workflow_dispatch`. Until the deploy action accepts an
|
> which throws on `workflow_dispatch`. Until the deploy action accepts an
|
||||||
> explicit `pr-number` input, post the preview comment from the caller
|
> explicit `pr-number` input, bypass it and call `cloudflare/wrangler-action`
|
||||||
> workflow as shown above. (Fixing deploy is a follow-up.)
|
> directly as shown above. (Fixing deploy is a follow-up.)
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue