Skip to content

Commit 1bfb5a6

Browse files
committed
chore: add Cloudflare Pages deploy workflow for fork previews
1 parent b6c4767 commit 1bfb5a6

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
on: [push]
1+
on:
2+
push:
3+
pull_request_target:
4+
types: [opened, synchronize, reopened]
25

36
jobs:
47
deploy:
@@ -7,12 +10,15 @@ jobs:
710
permissions:
811
contents: read
912
deployments: write
13+
pull-requests: write
1014

1115
name: Deploy to Cloudflare Pages
1216

1317
steps:
1418
- name: Checkout
15-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
1622

1723
- name: Setup Ruby
1824
uses: ruby/setup-ruby@v1
@@ -25,11 +31,27 @@ jobs:
2531
JEKYLL_ENV: production
2632

2733
- name: Publish
34+
id: cloudflare
2835
uses: cloudflare/pages-action@v1.5.0
2936
with:
3037
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
3138
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
3239
projectName: ruby-uy
3340
directory: _site
34-
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
3541
wranglerVersion: '3'
42+
branch: ${{ github.event.pull_request.head.ref || github.ref_name }}
43+
44+
- name: Comment preview URL on PR
45+
if: github.event_name == 'pull_request_target'
46+
uses: actions/github-script@v7
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
script: |
50+
github.rest.issues.createComment({
51+
issue_number: context.issue.number,
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
body: `🔍 Preview: ${process.env.DEPLOY_URL}`
55+
})
56+
env:
57+
DEPLOY_URL: ${{ steps.cloudflare.outputs.url }}

0 commit comments

Comments
 (0)