@@ -2,14 +2,22 @@ name: Build and Preview Site
22on :
33 pull_request :
44 branches : [master]
5- types : [opened, synchronize, reopened]
5+ types : [opened, synchronize, reopened, closed]
6+
7+ concurrency :
8+ group : ${{ github.workflow }}-${{ github.ref }}
9+ cancel-in-progress : true
10+
11+ permissions :
12+ contents : write
13+ pull-requests : write
614
715jobs :
8- site-preview :
16+ build :
917 runs-on : ubuntu-latest
1018 steps :
1119 - name : Checkout 🛎️
12- uses : actions/checkout@master
20+ uses : actions/checkout@v6
1321
1422 - name : Install and Build 🔧
1523 run : |
3139 with :
3240 name : public-dir
3341 path : public-dir.zip
34- retention-days : 1
42+ retention-days : 1
43+
44+ preview :
45+ needs : build
46+ runs-on : ubuntu-latest
47+ if : github.event_name == 'pull_request'
48+ steps :
49+ - name : Checkout 🛎️
50+ uses : actions/checkout@v6
51+
52+ - name : Download pre-built site
53+ if : github.event_name == 'pull_request'
54+ uses : actions/download-artifact@v4
55+ with :
56+ name : public-dir
57+ path : .
58+
59+ - name : Extract site
60+ if : github.event_name == 'pull_request'
61+ run : |
62+ unzip -q public-dir.zip
63+ # Ensure the extracted folder has the static files in a 'public' dir for the action
64+ if [ -d "public-dir" ] && [ ! -d "public" ]; then
65+ mv public-dir public
66+ elif [ ! -d "public" ]; then
67+ echo "Warning: Neither public nor public-dir found after extraction"
68+ fi
69+
70+ - name : Deploy Preview
71+ if : github.event_name == 'pull_request' && github.event.action != 'closed'
72+ 73+ with :
74+ source-dir : public
75+
76+ - name : Remove Preview on Close
77+ if : github.event_name == 'pull_request' && github.event.action == 'closed'
78+ 79+ with :
80+ source-dir : public
81+ remove : true
0 commit comments