-
Notifications
You must be signed in to change notification settings - Fork 7
293 lines (255 loc) · 12.7 KB
/
bump-version-release.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
290
291
292
293
name: "Bump version and release"
# Run only on closed Pull Requests targeting the main branch, and has changes in files or folders in the packages folders.
on:
pull_request:
branches:
- main
types:
- closed
paths:
- packages/midt/**
- packages/components/**
- packages/map-template/**
- .github/workflows/bump-version-release.yml
jobs:
check-labels:
name: "Check Pull Requst Labels"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: mheap/github-action-required-labels@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# This workflow fails if there is not exactly one label of the ones listed here (both zero and multiple will cause a failure).
with:
mode: exactly
count: 1
labels: "major, minor, patch"
midt-release-npm:
name: Release MIDT to npm
needs: check-labels
outputs:
has_changed_files: ${{ steps.changed-files-midt.outputs.any_changed }}
runs-on: ubuntu-latest
# This ensures the job only runs for Pull Requests that are merged.
if: github.event.pull_request.merged == true
env:
token: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files in the midt folder
id: changed-files-midt
uses: tj-actions/changed-files@v41
with:
files: packages/midt/**
- name: Run step if any file(s) in the midt folder change
if: steps.changed-files-midt.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-midt.outputs.all_changed_files }}
run: |
echo "One or more files in the midt folder has changed."
echo "List all the files that have changed: $ALL_CHANGED_FILES"
# Check out the repository code.
- uses: actions/checkout@v3
if: steps.changed-files-midt.outputs.any_changed == 'true'
# Set up a node environment in the container.
- uses: actions/setup-node@v3
if: steps.changed-files-midt.outputs.any_changed == 'true'
with:
node-version: 16
registry-url: https://registry.npmjs.org/
# Despite the package name including this scope, it's also necessary to set here
scope: "@mapsindoors"
# Build the project to ensure it's up to date. If this steps fails, the job fails.
- name: Build
if: steps.changed-files-midt.outputs.any_changed == 'true'
run: cd packages/midt && npm ci && npm run build
# Set the git config in order to commit the changes later.
# The name and email here is for the GitHub Actions user.
- name: Set git config
if: steps.changed-files-midt.outputs.any_changed == 'true'
run: git config user.name github-actions[bot] && git config user.email 41898282+github-actions[bot]@users.noreply.github.com
# The following steps will determine, based on a label, what version to bump to.
- name: Major version bump
if: contains(github.event.pull_request.labels.*.name, 'major') && steps.changed-files-midt.outputs.any_changed == 'true'
run: npm -w @mapsindoors/midt run release -- major
- name: Minor version bump
if: contains(github.event.pull_request.labels.*.name, 'minor') && steps.changed-files-midt.outputs.any_changed == 'true'
run: npm -w @mapsindoors/midt run release -- minor
- name: Patch version bump
if: contains(github.event.pull_request.labels.*.name, 'patch') && steps.changed-files-midt.outputs.any_changed == 'true'
run: npm -w @mapsindoors/midt run release -- patch
- name: Publish to npm
if: steps.changed-files-midt.outputs.any_changed == 'true'
run: npm -w @mapsindoors/midt publish --access public
components-release-npm:
name: Release Components to npm
runs-on: ubuntu-latest
outputs:
has_files_changed: ${{ steps.changed-files-components.outputs.any_changed }}
# This ensures the job only runs for Pull Requests that are merged.
if: github.event.pull_request.merged == true
needs: ["midt-release-npm"]
env:
token: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files in the components folder
id: changed-files-components
uses: tj-actions/changed-files@v41
with:
files: packages/components/**
- name: Run step if any file(s) in the components folder change
if: steps.changed-files-components.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-components.outputs.all_changed_files }}
run: |
echo "One or more files in the components folder has changed."
echo "List all the files that have changed: $ALL_CHANGED_FILES"
# Check out the repository code.
- uses: actions/checkout@v3
if: steps.changed-files-components.outputs.any_changed == 'true'
# Set up a node environment in the container.
- uses: actions/setup-node@v3
if: steps.changed-files-components.outputs.any_changed == 'true'
with:
node-version: 16
registry-url: https://registry.npmjs.org/
# Despite the package name including this scope, it's also necessary to set here
scope: "@mapsindoors"
# Build the project to ensure it's up to date. If this steps fails, the job fails.
- name: Build
if: steps.changed-files-components.outputs.any_changed == 'true'
run: npm ci && npx lerna run build
# Set the git config in order to commit the changes later.
# The name and email here is for the GitHub Actions user.
- name: Set git config
if: steps.changed-files-components.outputs.any_changed == 'true'
run: git config user.name github-actions[bot] && git config user.email 41898282+github-actions[bot]@users.noreply.github.com
# The following steps will determine, based on a label, what version to bump to.
- name: Major version bump
if: contains(github.event.pull_request.labels.*.name, 'major') && steps.changed-files-components.outputs.any_changed == 'true'
run: npm -w @mapsindoors/components run release -- major
- name: Minor version bump
if: contains(github.event.pull_request.labels.*.name, 'minor') && steps.changed-files-components.outputs.any_changed == 'true'
run: npm -w @mapsindoors/components run release -- minor
- name: Patch version bump
if: contains(github.event.pull_request.labels.*.name, 'patch') && steps.changed-files-components.outputs.any_changed == 'true'
run: npm -w @mapsindoors/components run release -- patch
- name: Publish to npm
if: steps.changed-files-components.outputs.any_changed == 'true'
run: npm -w @mapsindoors/components publish --access public
# This job will release the Component documentation
components-docs-release:
name: Release Components Docs
needs: components-release-npm
runs-on: ubuntu-latest
if: ${{needs.components-release-npm.outputs.has_files_changed}} == 'true'
# Check out the repository code, but only the latest version.
steps:
- uses: actions/checkout@v3
with:
ref: refs/heads/main
fetch-depth: 1
# Set up a node environment in the container.
- uses: actions/setup-node@v3
with:
node-version: 16.x
- run: npm ci
# It is absolutely essential to use "CI=" as the first part of the lerna command, or it won't build properly.
- run: CI= npx lerna run build && cd packages/components && npm run build && npm run docs.build
- name: "Authenticate on Google Cloud Storage"
uses: google-github-actions/auth@v1
with:
service_account: ${{ secrets.GCP_SA_EMAIL }}
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
# This command uses gsutil CLI to sync the local folder with the one on the bucket.
# "-m" ensures parallel upload of files, "-d" mirrors the folders, "-c" compares checksums to avoid unnecessary uploads, "-r" is for a recursive sync into all folders.
- run: gsutil -m rsync -d -c -r packages/components/docs gs://mi-components-documentation
# This is to control cache and set it as low as possible so new changes are instantly available.
- run: gsutil -m setmeta -h "Cache-Control:public, max-age=0"
gs://mi-components-documentation/**/*.html
- run: gsutil -m setmeta -h "Cache-Control:public, max-age=0"
gs://mi-components-documentation/**/*.js
- run: gsutil -m setmeta -h "Cache-Control:public, max-age=0"
gs://mi-components-documentation/**/*.css
map-template-release-npm:
name: Release Map Template to npm
runs-on: ubuntu-latest
# This ensures the job only runs for Pull Requests that are merged.
if: github.event.pull_request.merged == true
needs: ["components-release-npm"]
env:
token: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files in the map-template folder
id: changed-files-map-template
uses: tj-actions/changed-files@v41
with:
files: packages/map-template/**
- name: Run step if any file(s) in the map-template folder change
if: steps.changed-files-map-template.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-map-template.outputs.all_changed_files }}
run: |
echo "One or more files in the map-template folder has changed."
echo "List all the files that have changed: $ALL_CHANGED_FILES"
# Check out the repository code.
- uses: actions/checkout@v3
if: steps.changed-files-map-template.outputs.any_changed == 'true'
# Set up a node environment in the container.
- uses: actions/setup-node@v3
if: steps.changed-files-map-template.outputs.any_changed == 'true'
with:
node-version: 16
registry-url: https://registry.npmjs.org/
# Despite the package name including this scope, it's also necessary to set here
scope: "@mapsindoors"
# Build the project to ensure it's up to date. If this steps fails, the job fails.
- name: Build
if: steps.changed-files-map-template.outputs.any_changed == 'true'
run: npm ci && npx lerna run build && cd packages/map-template && npm run build-for-npm
# Set the git config in order to commit the changes later.
# The name and email here is for the GitHub Actions user.
- name: Set git config
if: steps.changed-files-map-template.outputs.any_changed == 'true'
run: git config user.name github-actions[bot] && git config user.email 41898282+github-actions[bot]@users.noreply.github.com
# The following steps will determine, based on a label, what version to bump to.
- name: Major version bump
if: contains(github.event.pull_request.labels.*.name, 'major') && steps.changed-files-map-template.outputs.any_changed == 'true'
run: npm -w @mapsindoors/map-template run release -- major
- name: Minor version bump
if: contains(github.event.pull_request.labels.*.name, 'minor') && steps.changed-files-map-template.outputs.any_changed == 'true'
run: npm -w @mapsindoors/map-template run release -- minor
- name: Patch version bump
if: contains(github.event.pull_request.labels.*.name, 'patch') && steps.changed-files-map-template.outputs.any_changed == 'true'
run: npm -w @mapsindoors/map-template run release -- patch
- name: Publish to npm
if: steps.changed-files-map-template.outputs.any_changed == 'true'
run: npm -w @mapsindoors/map-template publish --access public
# Using jsDelivr as the CDN, it will cache even @latest for up to 7 days. Specific versions are cached for up to a year, so we need to purge the CDN manually.
purge-jsdelivr-cache:
name: Purge jsDelivr cache
runs-on: ubuntu-latest
# This ensures the job only runs for Pull Requests that are merged.
if: github.event.pull_request.merged == true
needs: ["map-template-release-npm"]
steps:
- name: Purge @latest version
run: |
curl -X PURGE "https://purge.jsdelivr.net/npm/@mapsindoors/map-template@latest"
- name: Purge @stable version
run: |
curl -X PURGE "https://purge.jsdelivr.net/npm/@mapsindoors/map-template@stable"