@@ -4,7 +4,7 @@ name: preview-deploy
44on :
55 pull_request_target :
66 branches : [ "master" ]
7- types : [opened, synchronize, reopened]
7+ types : [opened, synchronize, reopened, closed ]
88
99 workflow_dispatch :
1010
@@ -24,53 +24,63 @@ defaults:
2424 shell : bash
2525
2626jobs :
27- # Build and Deploy job
2827 build-and-deploy :
2928 runs-on : ubuntu-latest
3029 env :
3130 HUGO_VERSION : 0.147.9
31+
3232 steps :
3333 - name : Install Hugo CLI
34+ if : github.event.action != 'closed'
3435 run : |
3536 wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
36- && sudo dpkg -i ${{ runner.temp }}/hugo.deb
37+ && sudo dpkg -i ${{ runner.temp }}/hugo.deb
38+
3739 - name : Install Dart Sass
40+ if : github.event.action != 'closed'
3841 run : sudo snap install dart-sass
3942
4043 - name : Checkout
44+ if : github.event.action != 'closed'
4145 uses : actions/checkout@v6
4246 with :
4347 ref : ${{ github.event.pull_request.head.sha }}
4448 submodules : recursive
4549 fetch-depth : 0
4650
51+ - name : Checkout for cleanup
52+ if : github.event.action == 'closed'
53+ uses : actions/checkout@v6
54+ with :
55+ ref : gh-pages
56+ fetch-depth : 0
57+
4758 - name : Install Node.js dependencies
59+ if : github.event.action != 'closed'
4860 run : " [[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
4961
5062 - name : Build with Hugo
63+ if : github.event.action != 'closed'
5164 env :
52- # For maximum backward compatibility with Hugo modules
5365 HUGO_ENVIRONMENT : production
5466 HUGO_ENV : production
5567 run : |
56- # Dynamically set BaseURL for PR preview
57- # Format: https://<ORG>.github.io/<REPO>/pr-preview/pr-<NUMBER>/
58- # We use github context to make it generic
5968 REPO_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2)
6069 ORG_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f1)
61-
70+
6271 PR_BASE_URL="https://${ORG_NAME}.github.io/${REPO_NAME}/pr-preview/pr-${{ github.event.pull_request.number }}/"
63-
72+
6473 echo "Building for BaseURL: ${PR_BASE_URL}"
65-
74+
6675 hugo \
6776 --gc \
6877 --minify \
6978 --buildDrafts \
7079 --buildFuture \
71- --baseURL "${PR_BASE_URL}"
72-
80+ --baseURL "${PR_BASE_URL}"
81+
7382 - name : Deploy PR Preview
83+ if : github.event.action != 'closed'
7484 id : deploy-preview
7585 uses : rossjrw/pr-preview-action@v1.6.3
7686 with :
8191 comment : false
8292
8393 - name : Comment PR with Preview URL
94+ if : github.event.action != 'closed'
8495 uses : marocchino/sticky-pull-request-comment@v2
85- if : github.event_name == 'pull_request_target'
8696 with :
8797 header : pr-preview
8898 message : |
@@ -91,3 +101,11 @@ jobs:
91101 🌐 **Preview URL**: ${{ steps.deploy-preview.outputs.preview-url }}
92102
93103 _This preview will be updated automatically when you push new commits to this PR._
104+
105+ - name : Cleanup PR Preview on Close
106+ if : github.event.action == 'closed'
107+ uses : rossjrw/pr-preview-action@v1.6.3
108+ with :
109+ preview-branch : gh-pages
110+ umbrella-dir : pr-preview
111+ action : remove
0 commit comments