Skip to content

Modern typeset — Geist headings (A/B vs #46) #90

Modern typeset — Geist headings (A/B vs #46)

Modern typeset — Geist headings (A/B vs #46) #90

Workflow file for this run

name: Post preview link
# Cloudflare Pages reports previews as a Check Run, not a GitHub Deployment, so
# deployment_status never fires here. Instead we key off the comment Cloudflare
# posts on the PR — it carries the branch preview URL — and reply with the exact
# post URL (branch preview + /blog/<slug>/). Free: GitHub's built-in token, no secrets.
on:
issue_comment:
types: [created, edited]
permissions:
pull-requests: write
contents: read
jobs:
comment:
# Only Cloudflare's deploy comment, and only on pull requests.
if: >
github.event.issue.pull_request &&
startsWith(github.event.comment.user.login, 'cloudflare-workers-and-pages') &&
contains(github.event.comment.body, 'Deploy successful')
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const cf = context.payload.comment.body || '';
// Prefer the branch preview URL (stable across redeploys of this branch);
// fall back to the per-deploy hash URL if only that is present.
const branch = cf.match(/Branch Preview URL:[\s\S]*?(https:\/\/[a-z0-9-]+\.[a-z0-9-]+\.pages\.dev)/i);
const hash = cf.match(/Preview URL:[\s\S]*?(https:\/\/[a-z0-9-]+\.[a-z0-9-]+\.pages\.dev)/i);
const base = (branch && branch[1]) || (hash && hash[1]);
if (!base) return;
const pr = context.payload.issue;
const match = (pr.body || '').match(/<!--\s*post-slug:\s*([a-z0-9-]+)\s*-->/);
const link = match ? `${base}/blog/${match[1]}` : base;
const marker = '<!-- preview-link-bot -->';
const body = `${marker}\n> [!TIP]\n> 📄 **[Preview your post →](${link})**`;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});
const existing = comments.data.find((c) => (c.body || '').includes(marker));
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: pr.number,
body,
});
}