11name : Build and Preview Site
2+
23on :
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
716jobs :
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
0 commit comments