-
Notifications
You must be signed in to change notification settings - Fork 0
289 lines (244 loc) · 9.27 KB
/
integrate.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
name: Integrate
# Run workflow when commits are pushed to pull requests or main branch
on:
pull_request: null
push:
branches:
- main
jobs:
# This job generates a new preview build of the website and makes it available to other jobs in the workflow.
build_preview:
name: Build preview assets
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
steps:
- uses: actions/checkout@v4
- name: Restore node_modules folder
id: cache-node
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-v2-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v2
- name: Install frontend dependencies
if: steps.cache-node.outputs.cache-hit != 'true'
run: npm ci
- name: Restore Composer dependencies
id: cache-php
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
# If no Composer cache exists, install Composer dependencies
- name: Install Composer dependencies
if: steps.cache-php.outputs.cache-hit != 'true'
run: composer install --no-dev --ignore-platform-reqs
- name: Create preview build of CSS and JS
run: npm run prod
- name: Create new preview build of website
run: ./vendor/bin/jigsaw build preview
env:
PREVIEW_URL: https://preview-${{ github.event.number }}.website.sven.luijten.dev
- name: Create zip file of preview build
run: zip -r build.zip build_preview/
- name: Keep ZIP file as artifact
uses: actions/upload-artifact@v4
with:
name: build_${{ github.event.number }}_zip
path: build.zip
retention-days: 1
# This job will deploy the website to a preview domain.
deploy_preview:
name: Deploy to preview
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
# The job is only run, when the `build`-job is finished.
needs:
- build_preview
steps:
- uses: actions/checkout@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build_${{ github.event.number }}_zip
path: ./build
- name: Unzip preview build
run: unzip ./build/build.zip -d ./build
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Restore node_modules folder
id: cache-node
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-v2-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v2
- name: Install frontend dependencies
if: steps.cache-node.outputs.cache-hit != 'true'
run: npm ci
# Start tracking the deployment status using GitHub deployments
- name: Start deployment
uses: bobheadxi/deployments@v1
id: deployment_pr
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: 'Pull Request #${{ github.event.number }} Preview'
# `head_ref` has to be used here, as otherwhise the deployments
# are not shown near the status overview inside a pull request.
ref: ${{ github.head_ref }}
# Deploy website as a preview to Vercel.
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
id: vercel_action_pr
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
# Disable GitHub comments. I don't need a comment telling me that a deployment is happening.
github-comment: false
# This is not a typo. This structure is created by unzipping the build artifact.
working-directory: ./build/build_preview
scope: team-svenluijten
alias-domains: |
preview-{{PR_NUMBER}}.website.sven.luijten.dev
# Set the deployment status in GitHub to finished.
- name: Update Deployment Status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
# We use the deployment ID of a previous step here
deployment_id: ${{ steps.deployment_pr.outputs.deployment_id }}
# We pass Vercel's own preview URL to the environment. This
# way we can easily visit the deployed site from the pull
# request.
env_url: ${{ steps.vercel_action_pr.outputs.preview-url }}
env: 'Pull Request #${{ github.event.number }} Preview'
- name: Delete build artifact
uses: geekyeggo/delete-artifact@v5
if: always()
with:
name: build_${{ github.event.number }}_zip
# This job generates a new production build of the website and makes it available to other jobs in the workflow.
build_production:
name: Build production assets
runs-on: ubuntu-latest
if: github.event.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Restore node_modules folder
id: cache-node
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-v2-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v2
- name: Install frontend dependencies
if: steps.cache-node.outputs.cache-hit != 'true'
run: npm ci
- name: Restore Composer dependencies
id: cache-php
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
# If no Composer cache exists, install Composer dependencies
- name: Install Composer dependencies
if: steps.cache-php.outputs.cache-hit != 'true'
run: composer install --no-dev --ignore-platform-reqs
- name: Create production build of CSS and JS
run: npm run prod
- name: Create new production build of website
run: ./vendor/bin/jigsaw build production
- name: Create ZIP file of production build
run: zip -r build.zip build_production/
- name: Keep ZIP file as artifact
uses: actions/upload-artifact@v4
with:
name: build_zip
path: build.zip
retention-days: 1
# This job will deploy the website to production.
deploy_production:
name: Deploy to production
runs-on: ubuntu-latest
if: github.event.ref == 'refs/heads/main'
# The job is only run, when the `build`-job is finished.
needs:
- build_production
steps:
- uses: actions/checkout@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build_zip
path: ./build
- name: Unzip production build
run: unzip ./build/build.zip -d ./build
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Restore node_modules folder
id: cache-node
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-v2-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v2
- name: Install frontend dependencies
if: steps.cache-node.outputs.cache-hit != 'true'
run: npm ci
# Start tracking the deployment status using GitHub deployments.
# Instead of using a dynamic environment name, we use production
- name: Start Deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: Production
# Deploy website for production to Vercel.
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
id: vercel-action
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
github-comment: false
working-directory: ./build/build_production
scope: team-svenluijten
# This argument tells the Vercel Action to mark the deployment for production.
vercel-args: '--prod'
# Set the deployment status in GitHub to finished.
- name: Update Deployment Status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ steps.vercel-action.outputs.preview-url }}
env: production
- name: Delete production build artifact
uses: geekyeggo/delete-artifact@v5
if: always()
with:
name: build_zip