Skip to content

Commit a99a27e

Browse files
authored
feat: Cloudflare Pages preview deployments (#18)
Backported from #17
1 parent 92e5627 commit a99a27e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

.github/workflows/pkgdown.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
2323
permissions:
2424
contents: write
25+
deployments: write
26+
pull-requests: write
2527
steps:
2628
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
2729

@@ -40,10 +42,32 @@ jobs:
4042
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
4143
shell: Rscript {0}
4244

43-
- name: Deploy to GitHub pages 🚀
45+
- name: Deploy to GitHub pages (backup)
4446
if: github.event_name != 'pull_request'
4547
uses: JamesIves/github-pages-deploy-action@9d877eea73427180ae43cf98e8914934fe157a1a # v4.7.6
4648
with:
4749
clean: false
4850
branch: gh-pages
4951
folder: docs
52+
53+
- name: Deploy to Cloudflare Pages
54+
if: github.event_name == 'pull_request'
55+
uses: cloudflare/wrangler-action@v3
56+
id: cloudflare
57+
with:
58+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
59+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
60+
command: pages deploy docs --project-name=mobdb --branch=${{ github.head_ref || github.ref_name }} --commit-dirty=true
61+
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Comment preview URL on PR
64+
if: github.event_name == 'pull_request'
65+
uses: actions/github-script@v7
66+
with:
67+
script: |
68+
github.rest.issues.createComment({
69+
issue_number: context.issue.number,
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
body: `## Preview Deployment\n\n:rocket: Preview URL: ${{ steps.cloudflare.outputs.deployment-url }}\n\nBranch alias: ${{ steps.cloudflare.outputs.pages-deployment-alias-url }}`
73+
})

0 commit comments

Comments
 (0)