Skip to content

Commit 29e240e

Browse files
authored
CloudFlare Pages add Preview URL to PR (#156)
Co-authored-by: Hien To <[email protected]>
1 parent 0e993b6 commit 29e240e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
- main
7-
tags: ['v*.*.*']
7+
tags: ["v[0-9]+.[0-9]+.[0-9]+"]
88
paths: ['.github/scripts/**','.github/workflows/build.yml', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cc', '**/*.cxx', '!docs/**', '!.gitignore']
99
pull_request:
1010
types: [opened, synchronize, reopened]

.github/workflows/docs.yml

+26-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
- main
77
paths:
88
- 'docs/**'
9+
- '.github/workflows/docs.yml'
10+
tags: ["v[0-9]+.[0-9]+.[0-9]+-docs"]
911
pull_request:
1012
branches:
1113
- main
@@ -18,6 +20,9 @@ on:
1820
jobs:
1921
deploy:
2022
name: Deploy to GitHub Pages
23+
env:
24+
CLOUDFLARE_ACCOUNT_ID: 9707100ef42a1a25bd70e3ee2137bd0e
25+
CLOUDFLARE_PROJECT_NAME: nitro
2126
runs-on: ubuntu-latest
2227
steps:
2328
- uses: actions/checkout@v3
@@ -50,15 +55,33 @@ jobs:
5055
- name: Build website
5156
run: sed -i '/process.env.DEBUG = namespaces;/c\// process.env.DEBUG = namespaces;' ./node_modules/debug/src/node.js && yarn build
5257
working-directory: docs
53-
58+
59+
- name: Publish to Cloudflare Pages PR Preview and Staging
60+
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main')
61+
uses: cloudflare/pages-action@v1
62+
with:
63+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
64+
accountId: ${{ env.CLOUDFLARE_ACCOUNT_ID }}
65+
projectName: ${{ env.CLOUDFLARE_PROJECT_NAME }}
66+
directory: ./docs/build
67+
# Optional: Enable this if you want to have GitHub Deployments triggered
68+
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
69+
id: deployCloudflarePages
70+
71+
- uses: mshick/add-pr-comment@v2
72+
if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main'
73+
with:
74+
message: |
75+
Preview URL: ${{ steps.deployCloudflarePages.outputs.url }}
76+
5477
- name: Add Custome Domain file
55-
if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository
78+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
5679
run: echo "${{ vars.DOCUSAURUS_DOMAIN }}" > ./docs/build/CNAME
5780

5881
# Popular action to deploy to GitHub Pages:
5982
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
6083
- name: Deploy to GitHub Pages
61-
if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository
84+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
6285
uses: peaceiris/actions-gh-pages@v3
6386
with:
6487
github_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)