-
Notifications
You must be signed in to change notification settings - Fork 0
280 lines (273 loc) · 10.3 KB
/
release-notes.yaml
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
# Copyright 2024 Zaphiro Technologies
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Release
on:
push:
tags:
- '*'
pull_request_review:
pull_request:
types:
- labeled
- unlabeled
- edited
- synchronize
branches:
- main
release:
types:
- published
workflow_call:
inputs:
config-release-path:
required: false
default: '.github/config/release-config.json'
type: string
skip-sbom:
required: false
default: false
type: boolean
description: True to skip sbom exec
concurrency:
group: ${{ github.ref_name }}-release
cancel-in-progress: true
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# updated CHANGELOG back to the repository.
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
contents: write
pull-requests: write
jobs:
check_reviews:
runs-on: ubuntu-latest
outputs:
reviews: ${{ steps.reviews.outputs.state }}
steps:
- name: PR approval check
if: ${{ github.event_name == 'pull_request' }}
id: reviews
env:
pr: ${{ github.event.number }}
GH_TOKEN: ${{ github.token }}
run: |
state=$(gh pr view "$pr" \
--repo "$GITHUB_REPOSITORY" \
--json reviewDecision \
--jq '.reviewDecision')
echo "state=$state" >> "$GITHUB_OUTPUT"
release_notes:
needs: check_reviews
name: Release Notes
runs-on: ubuntu-latest
if: ${{ ( github.event_name == 'pull_request' && needs.check_reviews.outputs.reviews == 'APPROVED') || github.event.review.state == 'approved' || startsWith(github.ref, 'refs/tags/') }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.REPO_PAT }}
fetch-depth: 0
- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
fallback: 0.0.0 # Optional fallback tag to use when no tag can be found
- name: 'Get next minor version'
id: semvers
uses: "WyriHaximus/github-action-next-semvers@v1"
with:
version: ${{ steps.previoustag.outputs.tag }}
- name: Select configuration
if: ${{ github.event_name == ' workflow_call' }}
run: echo "CONFIGURATION=${{ inputs.config-release-path }}" >> $GITHUB_ENV
- name: Select configuration
if: ${{ github.event_name != ' workflow_call' }}
run: echo "CONFIGURATION='.github/config/release-config.json'" >> $GITHUB_ENV
- name: Get Pull Request Number
if: ${{ github.event.review.state == 'approved' }}
run: echo "PULL_NUMBER=$(echo "$GITHUB_REF" | awk -F / '{print $3}')" >> $GITHUB_ENV
shell: bash
- name: "Update changelog config"
id: update_changelog_config
env:
PR: ${{ github.event.review.state == 'approved' && env.PULL_NUMBER || github.event.number }}
run : |
jq --arg match "myPR" \
--arg replace "$PR" \
'walk(if . == $match then $replace else . end)' < ${{ env.CONFIGURATION }} > .github/config/release-config-temp.json
more .github/config/release-config-temp.json
- name: "Build Changelog"
id: build_changelog_1
uses: mikepenz/release-changelog-builder-action@v5
if: ${{ steps.previoustag.outputs.tag != '0.0.0' }}
with:
configuration: '.github/config/release-config-temp.json'
failOnError: true
includeOpen: true
fromTag: ${{ steps.previoustag.outputs.tag }}
toTag: ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Build Changelog"
id: build_changelog_2
uses: mikepenz/release-changelog-builder-action@v5
if: ${{ steps.previoustag.outputs.tag == '0.0.0' }}
with:
configuration: '.github/config/release-config-temp.json'
failOnError: true
includeOpen: true
toTag: ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clean log
if: ${{ startsWith(github.ref, 'refs/tags/') == false }}
run: |
if [ -f "RELEASE_NOTES.md" ]; then
# more RELEASE_NOTES.md
export line_start=$(grep -m1 -n "## ${{ steps.semvers.outputs.patch }}" RELEASE_NOTES.md | head -n1 |sed 's/:.*//')
# echo $line_start
export line_end=$(grep -m2 -n "^## " RELEASE_NOTES.md | head -2 | tail -1 | sed 's/:.*//')
# echo $line_end
if [[ $line_end -eq $line_start ]] || [[ -z "${line_end}" ]]; then export line_end=$(wc -l < RELEASE_NOTES.md); else export line_end=$(echo $line_end-1 | bc); fi
# echo $line_end
export PATTERN=${line_start},${line_end}d
# echo $PATTERN
if [[ -z "${line_start}" ]]; then echo "Empty"; else sed -i -e $PATTERN RELEASE_NOTES.md; fi
echo "cleaned release note:"
more RELEASE_NOTES.md
rm .github/config/release-config-temp.json
else
echo -en "# ${GITHUB_REPOSITORY#*/} Release Notes\n" > RELEASE_NOTES.md
fi
- name: Clean log
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
if [ -f "RELEASE_NOTES.md" ]; then
more RELEASE_NOTES.md
TAG=${{ steps.previoustag.outputs.tag }}
echo "VERSION=${TAG#v}"
export SEARCH=$VERSION-dev
export REPLACE=$VERSION
sed -i "s/$SEARCH/$REPLACE/g" RELEASE_NOTES.md
echo "cleaned release note:"
more RELEASE_NOTES.md
rm .github/config/release-config-temp.json
else
echo -en "# ${GITHUB_REPOSITORY#*/} Release Notes\n" > RELEASE_NOTES.md
fi
- name: Update Changelog (tag)
uses: stefanzweifel/changelog-updater-action@v1
if: ${{ steps.previoustag.outputs.tag != '0.0.0' }}
with:
latest-version: ${{ steps.semvers.outputs.patch }}-dev
release-notes: ${{ steps.build_changelog_1.outputs.changelog }}
path-to-changelog: RELEASE_NOTES.md
- name: Update Changelog (no tag)
uses: stefanzweifel/changelog-updater-action@v1
if: ${{ steps.previoustag.outputs.tag == '0.0.0' }}
with:
latest-version: ${{ steps.semvers.outputs.patch }}-dev
release-notes: ${{ steps.build_changelog_2.outputs.changelog }}
path-to-changelog: RELEASE_NOTES.md
- name: Prettify RELEASE_NOTES.md
uses: zaphiro-technologies/prettier_action@main
with:
prettier_options: --prose-wrap always --write RELEASE_NOTES.md
dry: true
dry_no_fail: true
- name: Commit updated CHANGELOG
if: startsWith(github.ref, 'refs/tags/') == false
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{github.event.pull_request.head.ref}}
commit_message: 'docs(release_notes): update RELEASE_NOTES.md [dependabot skip]'
file_pattern: RELEASE_NOTES.md
- name: Commit updated CHANGELOG
if: startsWith(github.ref, 'refs/tags/')
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: 'docs(release_notes): update RELEASE_NOTES.md'
file_pattern: RELEASE_NOTES.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- if: ${{ ! inputs.skip-sbom || inputs.skip-sbom == '' }}
name: Generate SBOM
uses: aquasecurity/trivy-action@master
with:
scan-type: fs
scan-ref: '.'
format: 'cyclonedx'
output: 'cyclonedx-sbom.json'
- if: ${{ ! inputs.skip-sbom || inputs.skip-sbom == '' }}
name: Upload SBOM as a Github artifact
uses: actions/upload-artifact@v4
with:
name: trivy-sbom-report
path: '${{ github.workspace }}/cyclonedx-sbom.json'
retention-days: 20 # 90 is the default
release:
name: Release
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Select configuration
if: ${{ github.event_name == ' workflow_call' }}
run: echo "CONFIGURATION=${{ inputs.config-release-path }}" >> $GITHUB_ENV
- name: Select configuration
if: ${{ github.event_name != ' workflow_call' }}
run: echo "CONFIGURATION=.github/config/release-config.json" >> $GITHUB_ENV
- name: "Build Changelog"
id: github_release
uses: mikepenz/release-changelog-builder-action@v5
with:
configuration: ${{env.CONFIGURATION}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: mikepenz/action-gh-release@v1
with:
body: ${{steps.github_release.outputs.changelog}}
prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-b') || contains(github.ref, '-a') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release-sbom:
name: Release SBOM
if: ${{ github.event_name == 'release' && (! inputs.skip-sbom || inputs.skip-sbom == '') }}
runs-on: ubuntu-latest
steps:
- name: Generate SBOM
uses: aquasecurity/trivy-action@master
with:
scan-type: fs
scan-ref: '.'
format: 'cyclonedx'
output: 'cyclonedx-sbom.json'
- name: Get Release
id: release
uses: bruceadams/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Attach SBOM to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: cyclonedx-sbom.json
asset_name: 'cyclonedx-sbom.json'
asset_content_type: application/json