Skip to content

Commit cda3b72

Browse files
Merge pull request #156 from Oluwatunmise-olat/ci/pr-preview-links
[CI] Add deployment preview link yaml
2 parents 8dcfc04 + 08c34b9 commit cda3b72

3 files changed

Lines changed: 81 additions & 80 deletions

File tree

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
name: Build and Deploy Site
2+
23
on:
34
push:
45
branches: [master]
56
workflow_dispatch:
67
workflow_call:
7-
8+
9+
permissions:
10+
contents: write
11+
12+
concurrency:
13+
group: "pages-deployment"
14+
cancel-in-progress: true
15+
816
jobs:
917
build-and-deploy:
10-
permissions:
11-
contents: write
12-
runs-on: ubuntu-latest
18+
runs-on: ubuntu-24.04
1319
steps:
1420
- name: Checkout 🛎️
15-
uses: actions/checkout@master
21+
uses: actions/checkout@v6
1622
with:
17-
fetch-depth: 1
23+
fetch-depth: 0
1824

1925
- name: Install and Build 🔧
2026
run: |
2127
make setup
2228
make build
2329
24-
- name: Deploy 🚀
25-
uses: JamesIves/github-pages-deploy-action@v4.7.3
30+
- name: Deploy to GitHub Pages 🚀
31+
uses: peaceiris/actions-gh-pages@v4
2632
with:
27-
branch: site # The branch the action should deploy to.
28-
folder: site/public # The folder the action should deploy.
29-
clean: true
33+
github_token: ${{ secrets.GITHUB_TOKEN }}
34+
publish_dir: ./site/public
35+
publish_branch: gh-pages
36+
keep_files: true
Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,78 @@
11
name: Build and Preview Site
2+
23
on:
3-
pull_request:
4+
pull_request_target:
45
branches: [master]
5-
types: [opened, synchronize, reopened]
6+
types: [opened, synchronize, reopened, closed]
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
concurrency:
13+
group: "preview-${{ github.event.pull_request.number || github.run_id }}"
14+
cancel-in-progress: true
615

716
jobs:
8-
site-preview:
9-
runs-on: ubuntu-latest
17+
build-and-deploy-preview:
18+
runs-on: ubuntu-24.04
1019
steps:
11-
- name: Checkout 🛎️
12-
uses: actions/checkout@master
20+
- name: Checkout PR
21+
if: github.event.action != 'closed'
22+
uses: actions/checkout@v6
1323
with:
24+
repository: ${{ github.event.pull_request.head.repo.full_name }}
25+
ref: ${{ github.event.pull_request.head.sha }}
1426
persist-credentials: false
15-
fetch-depth: 1
27+
fetch-depth: 0
1628

17-
- name: Install and Build 🔧
29+
- name: Checkout for cleanup
30+
if: github.event.action == 'closed'
31+
uses: actions/checkout@v6
32+
with:
33+
ref: gh-pages
34+
fetch-depth: 0
35+
36+
- name: Install and Build
37+
if: github.event.action != 'closed'
1838
run: |
1939
make setup
2040
make build
2141
22-
- name: Zip Site
23-
run: bash ./script.sh
42+
- name: Add robots.txt for previews
43+
if: github.event.action != 'closed'
44+
run: |
45+
cat > site/public/robots.txt <<'EOF'
46+
User-agent: *
47+
Disallow: /
48+
EOF
49+
50+
- name: Deploy PR preview
51+
if: github.event.action != 'closed'
52+
uses: rossjrw/pr-preview-action@v1.6.3
53+
with:
54+
source-dir: ./site/public
55+
preview-branch: gh-pages
56+
umbrella-dir: pr-preview
57+
action: auto
58+
comment: false
59+
60+
- name: Comment PR with Preview URL
61+
if: github.event.action != 'closed'
62+
uses: marocchino/sticky-pull-request-comment@v2
63+
with:
64+
header: pr-preview
65+
message: |
66+
🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}**
67+
68+
🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/
69+
70+
_This preview is updated automatically when commits are pushed to this PR._
2471
25-
- name: Upload files
26-
uses: actions/upload-artifact@v4
72+
- name: Cleanup PR preview on close
73+
if: github.event.action == 'closed'
74+
uses: rossjrw/pr-preview-action@v1.6.3
2775
with:
28-
name: public-dir
29-
path: public-dir.zip
30-
retention-days: 1
31-
- name: Trigger Inner workflow
32-
run: echo "triggering inner workflow"
76+
preview-branch: gh-pages
77+
umbrella-dir: pr-preview
78+
action: remove

.github/workflows/preview-site.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)