Merge pull request #3 from modelcontextprotocol/den/stageblog-command
Add pr-number input to cloudflare-pages-preview for workflow_dispatch
This commit is contained in:
commit
df3720fc27
4 changed files with 43 additions and 27 deletions
|
|
@ -139,6 +139,8 @@ Cloudflare API and GitHub API.
|
|||
| `comment-marker` | | `<!-- cf-pages-preview -->` | Sticky-comment identifier |
|
||||
| `comment-title` | | `Preview Deployed` | Heading in PR comment |
|
||||
| `github-token` | | `${{ github.token }}` | Token for PR commenting |
|
||||
| `pr-number` | | `${{ github.event.pull_request.number }}` | PR number to comment on — override when running on `workflow_dispatch` or other triggers without `payload.pull_request` |
|
||||
| `commit-sha` | | `${{ github.sha }}` | SHA shown in the sticky comment — override when the checked-out ref differs from `github.sha` |
|
||||
|
||||
### `cleanup`
|
||||
|
||||
|
|
@ -150,6 +152,7 @@ Cloudflare API and GitHub API.
|
|||
| `branch` | | `pr-<PR number>` | CF Pages branch alias to delete |
|
||||
| `comment-marker` | | `<!-- cf-pages-preview -->` | Sticky-comment identifier |
|
||||
| `github-token` | | `${{ github.token }}` | Token for PR commenting |
|
||||
| `pr-number` | | `${{ github.event.pull_request.number }}` | PR number to update the sticky comment on — override when running on `workflow_dispatch` or other triggers without `payload.pull_request` |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,13 @@ inputs:
|
|||
description: GitHub token for updating the PR comment
|
||||
required: false
|
||||
default: ${{ github.token }}
|
||||
pr-number:
|
||||
description: >-
|
||||
PR number to update the sticky 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 }}
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
|
|
@ -65,11 +72,16 @@ runs:
|
|||
uses: actions/github-script@v8
|
||||
env:
|
||||
COMMENT_MARKER: ${{ inputs.comment-marker }}
|
||||
PR_NUMBER: ${{ inputs.pr-number }}
|
||||
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 update.');
|
||||
return;
|
||||
}
|
||||
const marker = process.env.COMMENT_MARKER;
|
||||
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
|
|
|
|||
|
|
@ -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}_`;
|
||||
|
||||
|
|
|
|||
|
|
@ -172,38 +172,19 @@ jobs:
|
|||
|
||||
# ... your blog build steps → output to blog/public ...
|
||||
|
||||
- id: deploy
|
||||
uses: modelcontextprotocol/actions/cloudflare-pages-preview/deploy@main
|
||||
- uses: modelcontextprotocol/actions/cloudflare-pages-preview/deploy@main
|
||||
with:
|
||||
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 }}
|
||||
|
||||
# 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
|
||||
env:
|
||||
PR_NUMBER: ${{ inputs.pr_number }}
|
||||
PREVIEW_URL: ${{ steps.deploy.outputs.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: ${process.env.PREVIEW_URL}`,
|
||||
});
|
||||
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 assumes
|
||||
> `context.payload.pull_request` exists for its sticky-comment step, which is
|
||||
> not the case on `workflow_dispatch`. Until the deploy action accepts an
|
||||
> explicit `pr-number` input, post the preview comment from the caller
|
||||
> workflow as shown above. (Fixing deploy is a follow-up.)
|
||||
|
||||
## Inputs
|
||||
|
||||
| Input | Required | Default | Description |
|
||||
|
|
|
|||
Loading…
Reference in a new issue