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:
Den Delimarsky 2026-03-11 20:25:04 +00:00
commit a4bb78216a
No known key found for this signature in database

View file

@ -40,6 +40,20 @@ inputs:
description: GitHub token for posting/updating the PR comment
required: false
default: ${{ github.token }}
pr-number:
description: >-
PR number to comment on. Only needed on triggers where
context.payload.pull_request is unavailable (e.g. workflow_dispatch).
Defaults to the event payload's PR number.
required: false
default: ${{ github.event.pull_request.number }}
commit-sha:
description: >-
Commit SHA shown in the sticky comment. Useful when the checked-out
ref differs from github.sha (e.g. building a pinned head SHA on
workflow_dispatch). Defaults to github.sha.
required: false
default: ${{ github.sha }}
outputs:
deployment-url:
@ -93,11 +107,17 @@ runs:
COMMENT_MARKER: ${{ inputs.comment-marker }}
COMMENT_TITLE: ${{ inputs.comment-title }}
INJECT_NOINDEX: ${{ inputs.inject-noindex }}
PR_NUMBER: ${{ inputs.pr-number }}
COMMIT_SHA: ${{ inputs.commit-sha }}
with:
github-token: ${{ inputs.github-token }}
script: |
const { owner, repo } = context.repo;
const prNumber = context.payload.pull_request.number;
const prNumber = Number(process.env.PR_NUMBER);
if (!prNumber) {
core.info('No PR number available — skipping comment.');
return;
}
const deployUrl = process.env.DEPLOY_URL;
const aliasUrl = process.env.ALIAS_URL || deployUrl;
const marker = process.env.COMMENT_MARKER;
@ -115,7 +135,7 @@ runs:
|---|---|
| **Preview (stable)** | ${aliasUrl} |
| **This commit** | ${deployUrl} |
| **Commit** | \`${context.sha.slice(0, 7)}\` |
| **Commit** | \`${process.env.COMMIT_SHA.slice(0, 7)}\` |
_Includes drafts and future-dated posts.${noindexNote}_`;