Repository navigation
306 lines (268 loc) · 12.8 KB
/
Copy pathbuild.yml
File metadata and controls
306 lines (268 loc) · 12.8 KB
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# This is a basic workflow to help you get started with Actions
name: BUILD
env:
NX_CACHE_DIRECTORY: .nx/cache
# Branch pushes deploy development and UAT builds. Release tags deploy
# production builds: `v<version>` releases all applications and
# `<app>/v<version>` releases one application. `mobile.yml` uses the
# `mobile/v<version>` tags.
on:
push:
branches: [develop, rc/**]
tags: ['v[0-9]*', '*/v[0-9]*', '!mobile/v[0-9]*']
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
install_deps:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
# A full checkout fetches all branches, so the check can see
# which branches contain the tagged commit.
- name: Check release tag source
if: ${{ github.ref_type == 'tag' }}
run: .github/scripts/check-release-source.sh
- name: Cache node modules
id: cache
uses: actions/cache@v5
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/bun.lock') }}
- name: Setup Node.js environment
uses: actions/setup-node@v6
with:
node-version: '26'
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.4.3'
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
- name: Get short hash
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Extract build configuration
shell: bash
id: build_ext
run: |
if [[ "$GITHUB_REF_TYPE" == "tag" ]]
then
echo "configuration=production" >> $GITHUB_OUTPUT
echo "deploy_branch=prod" >> $GITHUB_OUTPUT
elif [[ "$GITHUB_REF_NAME" == rc/* ]]
then
echo "configuration=staging" >> $GITHUB_OUTPUT
echo "deploy_branch=uat" >> $GITHUB_OUTPUT
else
echo "configuration=staging" >> $GITHUB_OUTPUT
echo "deploy_branch=dev" >> $GITHUB_OUTPUT
fi
- name: Find affected base commit
id: affected_base
env:
GH_TOKEN: ${{ github.token }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
base="$(.github/scripts/get-affected-base.sh)"
echo "sha=${base}" >> $GITHUB_OUTPUT
- name: List affected applications
id: affected_apps
env:
NX_BASE: ${{ steps.affected_base.outputs.sha }}
run: |
affected_apps="$(node ./tools/get-affected.js ${{ github.ref }})"
affected_units="$(node ./tools/get-affected.js ${{ github.ref }} test)"
echo "affected_apps=${affected_apps}" >> $GITHUB_OUTPUT
echo "affected_units=${affected_units}" >> $GITHUB_OUTPUT
- name: Print affected applications
run: |
echo "Base: ${{ steps.affected_base.outputs.sha }}"
echo ${{ steps.affected_apps.outputs.affected_apps }}
- name: Install git-cliff
if: ${{ fromJSON(steps.affected_apps.outputs.affected_apps)[0] != null }}
uses: taiki-e/install-action@v2
with:
tool: git-cliff@2.13.1
fallback: none
- name: Generate application changelogs
id: changelogs
continue-on-error: true
if: ${{ fromJSON(steps.affected_apps.outputs.affected_apps)[0] != null }}
env:
AFFECTED_APPS: ${{ steps.affected_apps.outputs.affected_apps }}
CHANGELOG_DIR: ${{ runner.temp }}/changelogs
GITHUB_REPO: ${{ github.repository }}
MAX_PARALLEL: 2
run: .github/scripts/generate-changelogs.sh
- name: Upload application changelogs
if: ${{ steps.changelogs.outcome == 'success' }}
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: changelogs-${{ github.run_attempt }}
path: ${{ runner.temp }}/changelogs
retention-days: 1
outputs:
affected_apps: ${{ steps.affected_apps.outputs.affected_apps }}
affected_units: ${{ steps.affected_apps.outputs.affected_units }}
configuration: ${{ steps.build_ext.outputs.configuration }}
deploy_branch: ${{ steps.build_ext.outputs.deploy_branch }}
short_sha: ${{ steps.vars.outputs.short_sha }}
test:
runs-on: ubuntu-latest
needs: install_deps
if: ${{ fromJSON(needs.install_deps.outputs.affected_units)[0] != null }}
strategy:
matrix:
package: ${{ fromJSON(needs.install_deps.outputs.affected_units) }}
steps:
- uses: actions/checkout@v6
- name: Cache node modules
id: cache
uses: actions/cache@v5
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/bun.lock') }}
- name: Cache nx build cache
id: cache-nx
uses: actions/cache@v5
with:
path: .nx/cache
key: ${{ runner.os }}-nx-${{matrix.package}}-${{ hashFiles('**/bun.lock') }}
restore-keys: |
${{ runner.os }}-nx-${{matrix.package}}-
${{ runner.os }}-nx-
# Match install_deps. The runner image default (Node 22) differs
# from local runs in web APIs such as Response.blob().
- name: Setup Node.js environment
uses: actions/setup-node@v6
with:
node-version: '26'
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.4.3'
- name: Setup version
run: bun run postinstall
- name: Test affected code units
run: |
bunx nx test ${{ matrix.package }}
build:
runs-on: ubuntu-latest
needs: install_deps
if: ${{ fromJSON(needs.install_deps.outputs.affected_apps)[0] != null }}
# Deploys of one app to one branch wait for each other. Otherwise a
# `v<version>` and an `<app>/v<version>` run can race on the push.
concurrency:
group: deploy-${{ matrix.package }}-${{ needs.install_deps.outputs.deploy_branch }}
cancel-in-progress: false
strategy:
matrix:
package: ${{ fromJSON(needs.install_deps.outputs.affected_apps) }}
env:
configuration: ${{ needs.install_deps.outputs.configuration }}
deploy_branch: ${{ needs.install_deps.outputs.deploy_branch }}
short_sha: ${{ needs.install_deps.outputs.short_sha }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v6
# The concurrency group above makes this run after an earlier
# deploy of this app, so it compares with the newest build.
- name: Check release order
if: ${{ github.ref_type == 'tag' }}
run: .github/scripts/check-release-order.sh
env:
BRANCH: build/${{ matrix.package }}/${{ env.deploy_branch }}
GH_TOKEN: ${{ github.token }}
- name: Cache node modules
id: cache
uses: actions/cache@v5
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/bun.lock') }}
- name: Cache nx build cache
id: cache-nx
uses: actions/cache@v5
with:
path: .nx/cache
key: ${{ runner.os }}-nx-${{matrix.package}}-${{ hashFiles('**/bun.lock') }}
restore-keys: |
${{ runner.os }}-nx-${{matrix.package}}-
${{ runner.os }}-nx-
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.4.3'
- name: Setup version
run: bun run postinstall
- name: Initialise Pipeline Chat Status
run: |
curl --fail-with-body --silent --show-error --max-time 5 \
--request POST \
--header 'Content-Type: application/json' \
--data "$REQUEST_DATA" \
"$STATUS_URL"
continue-on-error: true
env:
STATUS_URL: ${{ secrets.STATUS_URL }}
REQUEST_DATA: '{ "chat_url": "${{ secrets.CHAT_URL }}", "name": "${{ github.repository }}", "commit": "${{ github.sha }}", "pipeline_name": "${{ matrix.package }}", "branch": "${{ github.ref }}", "status": "processing", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'
- name: Build affected applications
run: |
bunx nx build ${{ matrix.package }} --verbose --configuration=${{ env.configuration }}
# The build writes a debug ID into each script and its source map.
# The script registers the IDs at runtime for the Sentry SDK. An
# upload failure does not block the deployment.
- name: Upload source maps to Sentry
run: |
if [[ -z "$SENTRY_AUTH_TOKEN" ]]; then
echo "SENTRY_AUTH_TOKEN is not set. Skipping source map upload."
exit 0
fi
bun .github/scripts/register-sentry-debug-ids.mjs "$FOLDER"
bunx sentry-cli sourcemaps upload "$FOLDER" ||
echo "::warning::Source map upload to Sentry failed."
env:
FOLDER: dist/apps/${{ matrix.package }}/browser
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: place-technology
SENTRY_PROJECT: placeos-dev
- name: Remove source maps from production builds
if: ${{ env.configuration == 'production' }}
run: find "dist/apps/${{ matrix.package }}/browser" -name '*.map' -delete
- name: Download application changelogs
id: download_changelogs
continue-on-error: true
uses: actions/download-artifact@v4
with:
name: changelogs-${{ github.run_attempt }}
path: ${{ runner.temp }}/changelogs
- name: Add application changelog to build
if: ${{ steps.download_changelogs.outcome == 'success' }}
continue-on-error: true
run: |
cp \
"${RUNNER_TEMP}/changelogs/${{ matrix.package }}/CHANGELOG.md" \
"dist/apps/${{ matrix.package }}/browser/CHANGELOG.md"
- name: Deploy the application(${{ matrix.package }})
run: .github/scripts/publish-subdir.sh
env:
BRANCH: build/${{ matrix.package }}/${{ env.deploy_branch }} # The branch name where you want to push the assets
FOLDER: dist/apps/${{ matrix.package }}/browser # The directory where your assets are generated
MESSAGE: 'build(${{ matrix.package }}): [{sha}] CI build' # The commit message
- name: Update Pipeline Chat Status
run: |
curl --fail-with-body --silent --show-error --max-time 5 \
--request POST \
--header 'Content-Type: application/json' \
--data "$REQUEST_DATA" \
"$STATUS_URL"
continue-on-error: true
env:
STATUS_URL: ${{ secrets.STATUS_URL }}
REQUEST_DATA: '{ "name": "${{ github.repository }}", "commit": "${{ github.sha }}", "pipeline_name": "${{ matrix.package }}", "branch": "${{ github.ref }}", "status": "${{ job.status }}", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'
if: ${{ always() }}