1
1
name : Preview Deployment
2
2
3
3
on :
4
- push :
5
- branches :
6
- - vercel-preview
7
4
pull_request :
8
- types : [opened, synchronize]
5
+ types : [opened, synchronize, labeled ]
9
6
10
7
concurrency :
11
- group : vercel
8
+ group : netlify
12
9
cancel-in-progress : false
13
10
14
11
jobs :
15
12
run :
13
+ if : contains(github.event.pull_request.labels.*.name, 'preview')
16
14
runs-on : ubuntu-latest
15
+ concurrency :
16
+ group : netlify-${{ github.workflow }}-${{ github.ref }}
17
+ cancel-in-progress : true
17
18
env :
18
19
REPO_ACCESS_TOKEN : ${{ secrets.REPO_ACCESS_TOKEN }}
19
20
APP_ENV : prod
20
21
21
22
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
+
22
43
- uses : actions/checkout@v4
23
44
24
45
- uses : actions/setup-node@v4
@@ -43,18 +64,18 @@ jobs:
43
64
id : gatsby-cache-folder
44
65
with :
45
66
path : .cache
46
- key : ${{ runner.os }}-cache-gatsbyV2-vercel- ${{ github.sha }}
67
+ key : ${{ runner.os }}-cache-gatsbyV2-${{ github.sha }}
47
68
restore-keys : |
48
- ${{ runner.os }}-cache-gatsbyV2-vercel-
69
+ ${{ runner.os }}-cache-gatsbyV2-
49
70
50
71
- name : Gatsby Public Folder
51
72
uses : actions/cache@v4
52
73
id : gatsby-public-folder
53
74
with :
54
75
path : public/
55
- key : ${{ runner.os }}-public-gatsbyV2-vercel- ${{ github.sha }}
76
+ key : ${{ runner.os }}-public-gatsbyV2-${{ github.sha }}
56
77
restore-keys : |
57
- ${{ runner.os }}-public-gatsbyV2-vercel-
78
+ ${{ runner.os }}-public-gatsbyV2-
58
79
59
80
- run : npm install
60
81
- run : npm run build
69
90
--dir public \
70
91
--site ${{ secrets.NETLIFY_SITE_ID }} \
71
92
--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