-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (184 loc) · 7.17 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
name: Release
on:
push:
tags:
- '*'
pull_request:
# Only following types are handled by the action, but one can default to all as well
types: [opened, reopened, synchronize, edited, labeled, unlabeled]
branches:
- main
workflow_call:
inputs:
config-release-path:
required: false
default: '.github/config/release-config.json'
type: string
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:
release_notes:
name: Release Notes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
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: "Update changelog config"
id: update_changelog_config
env:
PR: ${{ 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@v4
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@v4
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@v4
with:
branch: ${{github.event.pull_request.head.ref}}
commit_message: 'docs(release_notes): update RELEASE_NOTES.md'
file_pattern: RELEASE_NOTES.md
- name: Commit updated CHANGELOG
if: startsWith(github.ref, 'refs/tags/')
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: 'docs(release_notes): update RELEASE_NOTES.md'
file_pattern: RELEASE_NOTES.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
name: Release
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
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@v4
with:
configuration: ${{env.CONFIGURATION}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: mikepenz/[email protected]
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 }}