-
Notifications
You must be signed in to change notification settings - Fork 4
197 lines (187 loc) · 7.1 KB
/
package-main-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
# Should run Main Release Package on pull request [opened, synchronize, reopened, labeled, unlabeled, review_requested]
# only if head branch is named release-...
name: Package Main Release
on:
pull_request:
# https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#pull_request
types: [opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
jobs:
# check if the incoming branch follows the naming conventions, otherwise skip the workflow because this is not a release PR!!!
checkHeadBranch:
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# check head (source) branch
if: ${{ 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:
runs-on: ubuntu-latest
needs: checkHeadBranch
steps:
# - uses: actions/checkout@v4
# needs uses: actions/checkout@ if script/module is required
- name: checkTitelTag
uses: actions/github-script@v6
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 }}
# check if the tag is already published - uses @dlr-eoc/core-ui for test
checkTagOnNpm:
runs-on: ubuntu-latest
needs: checkTitelTag
if: ${{ needs.checkTitelTag.outputs.VERSION_TAG != '' }}
steps:
- uses: actions/checkout@v4
- name: checkout tag
run: |
git fetch --all --tags
git checkout ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
- uses: actions/setup-node@v4
with:
node-version: 20.15.1
- run: rm -f .npmrc
- uses: ./.github/actions/check-tag-on-npm
with:
npmPackageName: "@dlr-eoc/core-ui"
tag: ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
# check out the tag, build packages and store them as artifacts
build:
needs: [checkHeadBranch, checkTitelTag, checkTagOnNpm]
runs-on: ubuntu-latest
if: ${{ needs.checkTitelTag.outputs.VERSION_TAG != '' }}
steps:
- uses: actions/checkout@v4
- name: checkout tag
run: |
git fetch --all --tags
git checkout ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
- uses: actions/setup-node@v4
with:
node-version: 20.15.1
- name: build
run: |
npm ci
npm run build
- name: Archive dist artifacts
uses: actions/upload-artifact@v3
with:
name: "dist"
path: dist
# if build works fine we can proceed, add a label and create the release
checkLabel:
runs-on: ubuntu-latest
needs: build
steps:
- name: checkLabel
uses: actions/github-script@v6
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}`);
}
# check out the tag and create GH release with tag_name (https://github.com/softprops/action-gh-release)
gh-release:
needs: [checkHeadBranch, checkTitelTag, checkTagOnNpm, build, checkLabel]
if: ${{ needs.checkTitelTag.outputs.VERSION_TAG != '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: checkout tag
run: |
git fetch --all --tags
git checkout ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
# download artifacts and publish packages
publish-gpr:
needs: [checkHeadBranch, checkTitelTag, checkTagOnNpm, build, checkLabel, gh-release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download dist result from job build
uses: actions/download-artifact@v3
with:
name: "dist"
path: dist
- uses: actions/setup-node@v4
with:
node-version: 20.15.1
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 [email protected]
- run: rm -f .npmrc
### for each module in dist update package.json and create .npmrc
- run: node scripts/library/index.js --update-package=https://npm.pkg.github.com/
### for each module in dist publish frontend-libraries to registry
- run: |
for dir in ./dist/*/
do
dir=${dir%*/}
npm publish "$dir"
done
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
publish-npm:
needs: [checkHeadBranch, checkTitelTag, checkTagOnNpm, build, checkLabel, gh-release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download dist result from job build
uses: actions/download-artifact@v3
with:
name: "dist"
path: dist
- uses: actions/setup-node@v4
with:
node-version: 20.15.1
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 [email protected]
- 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
done
env:
NODE_AUTH_TOKEN: ${{secrets.PUBLISH_NPM_TOKEN}}