Skip to content

Commit 7deb844

Browse files
Enhance PR preview workflow with cleanup on close
Added cleanup step for PR preview on close and updated event types. Signed-off-by: Rajesh Nagarajan <139469505+Rajesh-Nagarajan-11@users.noreply.github.com>
1 parent 8b8af91 commit 7deb844

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

.github/workflows/deploy-preview.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: preview-deploy
44
on:
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,56 @@ defaults:
2424
shell: bash
2525

2626
jobs:
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

4751
- name: Install Node.js dependencies
52+
if: github.event.action != 'closed'
4853
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
4954

5055
- name: Build with Hugo
56+
if: github.event.action != 'closed'
5157
env:
52-
# For maximum backward compatibility with Hugo modules
5358
HUGO_ENVIRONMENT: production
5459
HUGO_ENV: production
5560
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
5961
REPO_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2)
6062
ORG_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f1)
61-
63+
6264
PR_BASE_URL="https://${ORG_NAME}.github.io/${REPO_NAME}/pr-preview/pr-${{ github.event.pull_request.number }}/"
63-
65+
6466
echo "Building for BaseURL: ${PR_BASE_URL}"
65-
67+
6668
hugo \
6769
--gc \
6870
--minify \
6971
--buildDrafts \
7072
--buildFuture \
71-
--baseURL "${PR_BASE_URL}"
72-
73+
--baseURL "${PR_BASE_URL}"
74+
7375
- name: Deploy PR Preview
76+
if: github.event.action != 'closed'
7477
id: deploy-preview
7578
uses: rossjrw/pr-preview-action@v1.6.3
7679
with:
@@ -81,8 +84,8 @@ jobs:
8184
comment: false
8285

8386
- name: Comment PR with Preview URL
87+
if: github.event.action != 'closed'
8488
uses: marocchino/sticky-pull-request-comment@v2
85-
if: github.event_name == 'pull_request_target'
8689
with:
8790
header: pr-preview
8891
message: |
@@ -91,3 +94,11 @@ jobs:
9194
🌐 **Preview URL**: ${{ steps.deploy-preview.outputs.preview-url }}
9295
9396
_This preview will be updated automatically when you push new commits to this PR._
97+
98+
- name: Cleanup PR Preview on Close
99+
if: github.event.action == 'closed'
100+
uses: rossjrw/pr-preview-action@v1.6.3
101+
with:
102+
preview-branch: gh-pages
103+
umbrella-dir: pr-preview
104+
action: remove

0 commit comments

Comments
 (0)