-
Notifications
You must be signed in to change notification settings - Fork 4
350 lines (333 loc) · 11.9 KB
/
package-release.yml
File metadata and controls
350 lines (333 loc) · 11.9 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# lint action on https://rhysd.github.io/actionlint/
name: Package Release (Main + Pre)
on:
# MAIN RELEASE: PRs with release-vX.Y.Z title on branches
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches: [main]
# PRE-RELEASE: tags like v1.2.3-next.1
push:
branches-ignore:
- "*"
tags:
- 'v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-next.[0-9]+'
permissions:
# REQUIRED for npm trusted publishing
id-token: write
contents: read
jobs:
# MAIN RELEASE JOBS (only run for PRs)
checkHeadBranch_pr:
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# check head (source) branch - Only for PRs
if: github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-')
steps:
- run: echo "Run the jobs for the release pull_request"
# get the tag to release from the PR title
checkTitelTag_pr:
runs-on: ubuntu-latest
needs: checkHeadBranch_pr
if: github.event_name == 'pull_request' # Only for PRs
steps:
# - uses: actions/checkout@v6
# needs uses: actions/checkout@ if script/module is required
- name: checkTitelTag
uses: actions/github-script@v8
id: get-tag
with:
result-encoding: string
script: |
if (context.payload.pull_request && context.payload.pull_request.title) {
const title = context.payload.pull_request.title;
const parts = title.split('release-');
if (parts.length === 2) {
const versionTag = parts[1];
core.info(`title contains version ${versionTag}`);
if(versionTag.startsWith('v')){
return versionTag;
}else{
core.setFailed(`Your PR title does not follow the naming convention of the version with "release-v..." ${title}`)
}
} else {
core.setFailed(`Your PR title does not follow the naming convention "release-v[0-9]+.[0-9]+.[0-9]" ${title}`)
}
}else{
core.setFailed(`context.payload does not have a pull_request" ${context.payload}`)
}
- name: log output
run: echo "${{ steps.get-tag.outputs.result }}"
outputs:
VERSION_TAG: ${{ steps.get-tag.outputs.result }}
# SHARED JOBS (run for both PRs and tags) --------------------------------------------
# check if the tag is already published - uses @dlr-eoc/map-ol for test
checkTagOnNpm_pr:
runs-on: ubuntu-latest
needs: [checkHeadBranch_pr, checkTitelTag_pr]
if: github.event_name == 'pull_request' && needs.checkTitelTag_pr.outputs.VERSION_TAG != ''
steps:
- uses: actions/checkout@v6
- name: checkout tag
run: |
git fetch --all --tags
git checkout ${{ needs.checkTitelTag_pr.outputs.VERSION_TAG }}
- uses: actions/setup-node@v6
with:
node-version: 24
- run: rm -f .npmrc
- uses: ./.github/actions/check-tag-on-npm
with:
npmPackageName: "@dlr-eoc/map-ol"
tag: ${{ needs.checkTitelTag_pr.outputs.VERSION_TAG }}
build_pr:
needs: [checkHeadBranch_pr, checkTitelTag_pr, checkTagOnNpm_pr]
runs-on: ubuntu-latest
if: needs.checkTitelTag_pr.outputs.VERSION_TAG != ''
steps:
- uses: actions/checkout@v6
- name: checkout tag
run: |
git fetch --all --tags
git checkout ${{ needs.checkTitelTag_pr.outputs.VERSION_TAG }}
- uses: actions/setup-node@v6
with:
node-version: 24
- name: build
run: |
npm ci
npm run build
- name: Archive dist artifacts
uses: actions/upload-artifact@v4
with:
name: "dist"
path: dist
# if build works fine we can proceed, add a label and create the release
checkLabel_pr:
runs-on: ubuntu-latest
needs: [build_pr]
steps:
- name: checkLabel
uses: actions/github-script@v8
with:
script: |
if(context.payload.pull_request.labels){
const hasLabel = context.payload.pull_request.labels.find(i => i.name === 'RELEASE');
if(!hasLabel){
core.setFailed(`pull_request hasLabel 'RELEASE' === ${hasLabel}`)
}
}else{
core.setFailed(`context.payload does not have a pull_request" ${context.payload}`);
}
gh-release_pr:
runs-on: ubuntu-latest
needs: [build_pr, checkLabel_pr, checkTitelTag_pr]
permissions:
contents: write
actions: write
steps:
# Your existing gh-release logic, but dynamic tag:
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.checkTitelTag_pr.outputs.VERSION_TAG }}
# download artifacts and publish packages
publish-gpr_pr:
needs: [checkHeadBranch_pr, checkTitelTag_pr, checkTagOnNpm_pr, build_pr, checkLabel_pr, gh-release_pr]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v6
- name: Download dist result from job build
uses: actions/download-artifact@v4
with:
name: "dist"
path: dist
- uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://npm.pkg.github.com/
scope: "@dlr-eoc"
- run: npm ci
### update npm to >8.19 for publish https://github.com/npm/cli/issues/2453 https://github.com/npm/cli/issues/3573
- run: npm i -g npm@latest # Latest npm for trusted publishing
- name: Check if .npmrc is there and delete file if it exists
id: check_and_delete_npmrc
run: |
FILE_PATH=".npmrc"
if [ -f "$FILE_PATH" ]; then
echo "File exists: $FILE_PATH"
rm -f "$FILE_PATH"
echo "File deleted."
else
echo "File does not exist: $FILE_PATH"
fi
### for each module in dist update package.json and create .npmrc
- run: node scripts/library/index.js --update-package=https://npm.pkg.github.com/
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
### for each module in dist publish frontend-libraries to registry
- run: |
for dir in ./dist/*/;
do
dir=${dir%*/}
npm publish "$dir" --access public --tag "latest"
done
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
publish-npm_pr:
needs: [checkHeadBranch_pr, checkTitelTag_pr, checkTagOnNpm_pr, build_pr, checkLabel_pr, gh-release_pr]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Download dist result from job build
uses: actions/download-artifact@v4
with:
name: "dist"
path: dist
- uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org/
scope: "@dlr-eoc"
- run: npm ci
### update npm to >8.19 for publish https://github.com/npm/cli/issues/2453 https://github.com/npm/cli/issues/3573
- run: npm i -g npm@latest # Latest npm for trusted publishing
- run: rm -f .npmrc
### for each module in dist update package.json and create .npmrc
- run: node scripts/library/index.js --update-package=https://registry.npmjs.org/
### for each module in dist publish frontend-libraries to registry
- run: |
for dir in ./dist/*/;
do
dir=${dir%*/}
npm publish "$dir" --access public --tag "latest" --provenance
done
env:
AUTH_TOKEN: ${{secrets.NPM_TOKEN_FROM_OIDC}}
# Pre RELEASE JOBS (only run for tags push) -------------------------------------------
checkTagOnNpm_push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
# check out before using actions reference from the same repository!
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
- run: rm -f .npmrc
- uses: ./.github/actions/check-tag-on-npm
with:
npmPackageName: "@dlr-eoc/map-ol"
tag: "${{ github.ref }}"
build_push:
needs: [checkTagOnNpm_push]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
- uses: ./.github/actions/test
- name: build
run: |
npm ci
npm run build
- name: Archive dist artifacts
uses: actions/upload-artifact@v4
with:
name: "dist"
path: dist
# create Release on tag push https://github.com/softprops/action-gh-release
gh-release_push:
needs: [build_push]
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Release
uses: softprops/action-gh-release@v2
with:
prerelease: true
publish-gpr_push:
needs: [gh-release_push, build_push]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v6
- name: Download dist result from job build
uses: actions/download-artifact@v4
with:
name: "dist"
path: dist
- uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://npm.pkg.github.com/
scope: "@dlr-eoc"
- run: npm ci
### update npm to >8.19 for publish https://github.com/npm/cli/issues/2453 https://github.com/npm/cli/issues/3573
- run: npm i -g npm@latest # Latest npm for trusted publishing
- name: Check if .npmrc is there and delete file if it exists
id: check_and_delete_npmrc
run: |
FILE_PATH=".npmrc"
if [ -f "$FILE_PATH" ]; then
echo "File exists: $FILE_PATH"
rm -f "$FILE_PATH"
echo "File deleted."
else
echo "File does not exist: $FILE_PATH"
fi
### for each module in dist update package.json and create .npmrc
- run: node scripts/library/index.js --update-package=https://npm.pkg.github.com/
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
### for each module in dist publish frontend-libraries to registry
- run: |
# Pre-release: use tag next
for dir in ./dist/*/
do
dir=${dir%*/}
npm publish "$dir" --access public --tag "next"
done
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
publish-npm_push:
needs: [gh-release_push, build_push]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Download dist result from job build
uses: actions/download-artifact@v4
with:
name: "dist"
path: dist
- uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org/
scope: "@dlr-eoc"
- run: npm ci
### update npm to >8.19 for publish https://github.com/npm/cli/issues/2453 https://github.com/npm/cli/issues/3573
- run: npm i -g npm@latest # Latest npm for trusted publishing
- run: rm -f .npmrc
### for each module in dist update package.json and create .npmrc
- run: node scripts/library/index.js --update-package=https://registry.npmjs.org/
### for each module in dist publish frontend-libraries to registry
- run: |
# Pre-release: use tag next
for dir in ./dist/*/
do
dir=${dir%*/}
npm publish "$dir" --access public --tag "next" --provenance
done
env:
AUTH_TOKEN: ${{secrets.NPM_TOKEN_FROM_OIDC}}