-
-
Notifications
You must be signed in to change notification settings - Fork 13
243 lines (230 loc) · 7.13 KB
/
release.yml
File metadata and controls
243 lines (230 loc) · 7.13 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
name: Release
on:
push:
branches:
- master
paths-ignore:
- CHANGELOG.md
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Lint the codebase
run: npm run lint:ci
test_and_report_coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Run tests
run: npm run test:ci
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: test_coverage
path: coverage
build_code:
name: Build code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build code
run: npm run build:ci
- name: Upload the dist folder
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
integration_tests:
name: Run integration tests
runs-on: ubuntu-latest
needs: build_code
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Download dist/ folder
uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Run integration tests
run: npm run test:integration:ci
build_docs:
name: Build Docs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build storybook
run: npm run docs:ci
- name: Upload the docs
uses: actions/upload-artifact@v4
with:
name: docs
path: docs
changelog:
name: Generate new changelog
runs-on: ubuntu-latest
outputs:
commit_hash: '${{ steps.committing.outputs.commit_hash }}'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
ssh-key: '${{ secrets.SSH_PRIVATE_KEY }}'
persist-credentials: 'true'
fetch-tags: 'true'
fetch-depth: 0
- name: Generate changelog
run: |
changelog=""
# Get tags newest to oldest
tags=($(git tag --sort=-version:refname))
# Untagged commits after latest tag
if [ "${#tags[@]}" -gt 0 ]; then
latest_tag="${tags[0]}"
untagged_commits=$(git --no-pager log --format="%s (%an) [%h]" "${latest_tag}..HEAD")
else
untagged_commits=$(git --no-pager log --format="%s (%an) [%h]")
fi
# Get future version from package.json
future_tag="$(awk -F'"' '/"version": ".+"/{ print $4; exit; }' package.json)"
if [ -n "$untagged_commits" ]; then
tag_log="### ${future_tag}\n"
while IFS= read -r commit; do
tag_log+="- ${commit}\n"
done <<< "$untagged_commits"
changelog="${tag_log}\n${changelog}"
fi
# Loop from i=0 to i <= tags.length (YES, intentionally +1)
for ((i=0; i<=${#tags[@]}; i++)); do
current="${tags[$i]}"
next="${tags[$((i+1))]}"
# Skip if current is empty (e.g., i == len)
if [ -z "$current" ]; then
continue
fi
if [ -n "$next" ]; then
commits=$(git --no-pager log --format="%s (%an) [%h]" "${next}..${current}")
else
# last tag (oldest), no previous one
commits=$(git --no-pager log --format="%s (%an) [%h]" "${current}")
fi
if [ -n "$commits" ]; then
tag_log="### ${current}\n"
while IFS= read -r commit; do
tag_log+="- ${commit}\n"
done <<< "$commits"
changelog="${changelog}\n${tag_log}"
fi
done
changelog="# Changelog\n${changelog}"
echo -e "$changelog"
printf '%b' "$changelog" > CHANGELOG.md
- name: Upload new changelog
uses: actions/upload-artifact@v4
with:
name: changelog
path: CHANGELOG.md
- name: Commit and push the new changelog
id: committing
run: |
if [ -z $(git status -uno --porcelain) ]; then
printf 'Changelogs are identical, nothing to commit\n'
else
printf 'Committing the updated changelog\n'
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -am "Update the project changelog"
commit_hash=$( git --no-pager log -1 --format=%H )
echo "commit_hash=${commit_hash}" >> "$GITHUB_OUTPUT"
fi
- name: Push changes
uses: ad-m/github-push-action@v0.8.0
with:
ssh: true
branch: '${{ github.ref }}'
maybe_tag:
name: Maybe tag the release
runs-on: ubuntu-latest
needs: [lint, test_and_report_coverage, build_code, build_docs, integration_tests, changelog]
outputs:
tagname: '${{ steps.tagging.outputs.tagname }}'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
ref: '${{ needs.changelog.outputs.commit_hash }}'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Maybe generate tag
uses: Klemensas/action-autotag@stable
id: tagging
with:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
tag_prefix: ''
tag_suffix: ''
changelog_structure: "**{{messageHeadline}}** {{author}}\n"
trigger_publish:
name: Maybe trigger publish
runs-on: ubuntu-latest
needs: [maybe_tag]
if: ${{ needs.maybe_tag.outputs.tagname != '' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
fetch-tags: 'true'
- name: Trigger the publish workflow
run: gh workflow run publish.yml --ref ${{ needs.maybe_tag.outputs.tagname }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
trigger_release:
name: Maybe trigger GitHub release
runs-on: ubuntu-latest
needs: [maybe_tag]
if: ${{ needs.maybe_tag.outputs.tagname != '' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
fetch-tags: 'true'
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
token: '${{ secrets.GITHUB_TOKEN }}'
tag: '${{ needs.maybe_tag.outputs.tagname }}'
generateReleaseNotes: true
allowUpdates: true
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'