11name : Build and Preview Site
22on :
3- pull_request :
3+ pull_request_target :
44 branches : [master]
55 types : [opened, synchronize, reopened, closed]
66
1818 steps :
1919 - name : Checkout 🛎️
2020 uses : actions/checkout@v6
21+ with :
22+ ref : ${{ github.event.pull_request.head.sha }}
2123
2224 - name : Install and Build 🔧
2325 env :
@@ -46,23 +48,23 @@ jobs:
4648 preview :
4749 needs : build
4850 runs-on : ubuntu-latest
49- if : github.event_name == 'pull_request '
51+ if : github.event_name == 'pull_request_target '
5052 permissions :
5153 contents : write
5254 pull-requests : write
5355 steps :
5456 - name : Checkout 🛎️
5557 uses : actions/checkout@v6
58+ with :
59+ ref : ${{ github.event.pull_request.base.ref }}
5660
5761 - name : Download pre-built site
58- if : github.event_name == 'pull_request'
5962 uses : actions/download-artifact@v4
6063 with :
6164 name : public-dir
6265 path : .
6366
6467 - name : Extract site
65- if : github.event_name == 'pull_request'
6668 run : |
6769 unzip -q public-dir.zip
6870 # Ensure the extracted folder has the static files in a 'public' dir for the action
@@ -73,14 +75,14 @@ jobs:
7375 fi
7476
7577 - name : Deploy Preview
76- if : github.event_name == 'pull_request' && github. event.action != 'closed'
78+ if : github.event.action != 'closed'
77797880 with :
7981 source-dir : public
8082 token : ${{ secrets.GITHUB_TOKEN }}
8183
8284 - name : Remove Preview on Close
83- if : github.event_name == 'pull_request' && github. event.action == 'closed'
85+ if : github.event.action == 'closed'
84868587 with :
8688 source-dir : public
0 commit comments