Skip to content

Commit 4b43d89

Browse files
authored
Merge pull request #285 from CodexRaunak/add-deployment-gh-pages
Add preview deployment gh pages
2 parents b3037b5 + 3fd6a59 commit 4b43d89

2 files changed

Lines changed: 131 additions & 10 deletions

File tree

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
11
name: Build and Deploy Site
2+
23
on:
34
push:
45
branches: [ master ]
6+
paths:
7+
- 'site/**'
8+
- 'Makefile'
9+
- 'CNAME'
10+
- '.github/workflows/build-and-deploy-site.yml'
11+
- '.github/workflows/build-and-preview-site.yml'
12+
13+
permissions:
14+
contents: write
15+
16+
defaults:
17+
run:
18+
shell: bash
519

620
jobs:
721
build-and-deploy:
8-
runs-on: ubuntu-latest
22+
runs-on: ubuntu-24.04
923
steps:
10-
- name: Checkout 🛎️
11-
uses: actions/checkout@v3.5.3
12-
- name: Install and Build 🔧
24+
- name: Checkout site source
25+
uses: actions/checkout@v6
26+
27+
- name: Setup Node
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: "20"
31+
cache: "npm"
32+
cache-dependency-path: site/package-lock.json
33+
34+
- name: Install and Build
1335
run: |
14-
make setup-libs
36+
make setup
1537
make build
38+
cp CNAME site/build/CNAME
39+
touch site/build/.nojekyll
1640
17-
- name: Deploy 🚀
18-
uses: JamesIves/github-pages-deploy-action@v4.4.3
41+
- name: Deploy site
42+
uses: peaceiris/actions-gh-pages@v4
1943
with:
20-
branch: site # The branch the action should deploy to.
21-
folder: site/build # The folder the action should deploy.
22-
clean: true
44+
github_token: ${{ secrets.GITHUB_TOKEN }}
45+
publish_branch: gh-pages
46+
publish_dir: ./site/build
47+
keep_files: true
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Build and Preview Site
2+
3+
on:
4+
pull_request_target:
5+
branches: [master]
6+
types: [opened, synchronize, reopened, closed]
7+
paths:
8+
- '!**'
9+
- 'site/**'
10+
- 'Makefile'
11+
- 'CNAME'
12+
- '.github/workflows/build-and-preview-site.yml'
13+
- '.github/workflows/build-and-deploy-site.yml'
14+
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
concurrency:
20+
group: preview-${{ github.event.pull_request.number || github.run_id }}
21+
cancel-in-progress: true
22+
23+
defaults:
24+
run:
25+
shell: bash
26+
27+
jobs:
28+
build-and-deploy-preview:
29+
runs-on: ubuntu-24.04
30+
31+
steps:
32+
- name: Checkout PR code
33+
if: github.event.action != 'closed'
34+
uses: actions/checkout@v6
35+
with:
36+
repository: ${{ github.event.pull_request.head.repo.full_name }}
37+
ref: ${{ github.event.pull_request.head.sha }}
38+
persist-credentials: false
39+
fetch-depth: 0
40+
41+
- name: Checkout for cleanup
42+
if: github.event.action == 'closed'
43+
uses: actions/checkout@v6
44+
with:
45+
ref: gh-pages
46+
fetch-depth: 0
47+
48+
- name: Setup Node
49+
if: github.event.action != 'closed'
50+
uses: actions/setup-node@v4
51+
with:
52+
node-version: "20"
53+
cache: "npm"
54+
cache-dependency-path: site/package-lock.json
55+
56+
- name: Install and Build PR preview
57+
if: github.event.action != 'closed'
58+
run: |
59+
make setup
60+
make build
61+
touch site/build/.nojekyll
62+
cat > site/build/robots.txt <<'EOF'
63+
User-agent: *
64+
Disallow: /
65+
EOF
66+
perl -0pi -e 's|<meta property="og:url" content="[^"]*" />|<meta property="og:url" content="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/" />|; s|</head>| <meta name="robots" content="noindex, nofollow" />\n</head>|' site/build/index.html
67+
68+
- name: Deploy PR preview
69+
if: github.event.action != 'closed'
70+
uses: rossjrw/pr-preview-action@v1.6.3
71+
with:
72+
source-dir: ./site/build
73+
preview-branch: gh-pages
74+
umbrella-dir: pr-preview
75+
action: auto
76+
comment: false
77+
78+
- name: Comment PR with Preview URL
79+
if: github.event.action != 'closed'
80+
uses: marocchino/sticky-pull-request-comment@v2
81+
with:
82+
header: pr-preview
83+
message: |
84+
🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}**
85+
86+
🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/
87+
88+
_This preview will be updated automatically when you push new commits to this PR._
89+
90+
- name: Cleanup PR preview on close
91+
if: github.event.action == 'closed'
92+
uses: rossjrw/pr-preview-action@v1.6.3
93+
with:
94+
preview-branch: gh-pages
95+
umbrella-dir: pr-preview
96+
action: remove

0 commit comments

Comments
 (0)