Skip to content

Commit 045f62b

Browse files
committed
Filtering pr - building preview only on specific labels
1 parent 71c6b2e commit 045f62b

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

Diff for: .github/workflows/preview.yml

+59-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
name: Preview Deployment
22

33
on:
4-
push:
5-
branches:
6-
- vercel-preview
74
pull_request:
8-
types: [opened, synchronize]
5+
types: [opened, synchronize, labeled]
96

107
concurrency:
11-
group: vercel
8+
group: netlify
129
cancel-in-progress: false
1310

1411
jobs:
1512
run:
13+
if: contains(github.event.pull_request.labels.*.name, 'preview')
1614
runs-on: ubuntu-latest
15+
concurrency:
16+
group: netlify-${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
1718
env:
1819
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
1920
APP_ENV: prod
2021

2122
steps:
23+
24+
- name: Find PR Preview Comment
25+
if: github.event_name == 'pull_request'
26+
uses: peter-evans/find-comment@v1
27+
id: deploy-preview-comment
28+
with:
29+
issue-number: ${{ github.event.pull_request.number }}
30+
comment-author: "github-actions[bot]"
31+
body-includes: "Preview this PR"
32+
33+
- name: Update Comment if exists
34+
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0
35+
uses: peter-evans/[email protected]
36+
with:
37+
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }}
38+
edit-mode: replace
39+
body: |
40+
## Preview Deployment
41+
Waiting for deployment to complete...
42+
2243
- uses: actions/checkout@v4
2344

2445
- uses: actions/setup-node@v4
@@ -43,18 +64,18 @@ jobs:
4364
id: gatsby-cache-folder
4465
with:
4566
path: .cache
46-
key: ${{ runner.os }}-cache-gatsbyV2-vercel-${{ github.sha }}
67+
key: ${{ runner.os }}-cache-gatsbyV2-${{ github.sha }}
4768
restore-keys: |
48-
${{ runner.os }}-cache-gatsbyV2-vercel-
69+
${{ runner.os }}-cache-gatsbyV2-
4970
5071
- name: Gatsby Public Folder
5172
uses: actions/cache@v4
5273
id: gatsby-public-folder
5374
with:
5475
path: public/
55-
key: ${{ runner.os }}-public-gatsbyV2-vercel-${{ github.sha }}
76+
key: ${{ runner.os }}-public-gatsbyV2-${{ github.sha }}
5677
restore-keys: |
57-
${{ runner.os }}-public-gatsbyV2-vercel-
78+
${{ runner.os }}-public-gatsbyV2-
5879
5980
- run: npm install
6081
- run: npm run build
@@ -69,4 +90,32 @@ jobs:
6990
--dir public \
7091
--site ${{ secrets.NETLIFY_SITE_ID }} \
7192
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
72-
--json
93+
--json \
94+
> deploy_output.json
95+
96+
- name: Generate URL Preview
97+
id: url_preview
98+
run: |
99+
NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json)
100+
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT"
101+
102+
- name: Create PR Preview Comment
103+
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id == 0
104+
uses: peter-evans/[email protected]
105+
with:
106+
issue-number: ${{ github.event.pull_request.number }}
107+
body: |
108+
## Preview Deployment
109+
🚀 Preview this PR: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }}
110+
📍 Commit SHA: ${{ github.sha }}
111+
112+
- name: Update PR Preview Comment
113+
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0
114+
uses: peter-evans/[email protected]
115+
with:
116+
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }}
117+
edit-mode: replace
118+
body: |
119+
## Preview Deployment
120+
🚀 Preview this PR: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }}
121+
📍 Commit SHA: ${{ github.sha }}

0 commit comments

Comments
 (0)