openpencil/.github/workflows/preview.yml
Danila Poyarkov 86d201b29e Split preview deploy into pull_request_target workflow
Fork PRs can't access repo secrets with pull_request trigger.
pull_request_target runs in the base repo context so Cloudflare
secrets are available for all PRs.
2026-03-14 18:18:35 +03:00

69 lines
2 KiB
YAML

name: Preview
on:
pull_request_target:
branches: [master]
paths-ignore:
- 'packages/docs/**'
- 'openspec/**'
- '*.md'
concurrency:
group: preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
preview:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
environment:
name: preview
url: ${{ steps.deploy.outputs.deployment-url }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: oven-sh/setup-bun@v2
- uses: actions/cache@v4
with:
path: ~/.bun/install/cache
key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }}
restore-keys: bun-${{ runner.os }}-
- run: bun install --frozen-lockfile
- run: bun run build
- uses: cloudflare/wrangler-action@v3
id: deploy
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=openpencil-app --branch=${{ github.event.pull_request.head.ref }}
- name: Comment preview URL
uses: actions/github-script@v7
with:
script: |
const url = '${{ steps.deploy.outputs.deployment-url }}';
const marker = '<!-- preview-deploy -->';
const body = `${marker}\n🔗 Preview: ${url}`;
const { data: comments } = await github.rest.issues.listComments({
...context.repo, issue_number: context.issue.number
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
...context.repo, comment_id: existing.id, body
});
} else {
await github.rest.issues.createComment({
...context.repo, issue_number: context.issue.number, body
});
}