-
-
Notifications
You must be signed in to change notification settings - Fork 12
258 lines (235 loc) · 12 KB
/
version-and-changelog-update.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
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
name: Version and changelog update
on:
pull_request:
types: [ opened, edited, synchronize, closed ]
pull_request_target:
types: [ opened, edited, synchronize, closed ]
jobs:
find-linked-issues-and-copy-labels-to-pull-request:
name: Copy labels from issue to pull request
runs-on: ubuntu-latest
outputs:
labelNames: ${{ steps.find-linked-issues.outputs.pull-request-labels }}
steps:
- uses: actions/[email protected]
- name: Print GitHub context
run: echo "$GITHUB_CONTEXT"
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Find linked issues
id: find-linked-issues
uses: Ismoh-Games/[email protected]
with:
token: ${{ secrets.WORKFLOW_PAT }}
repository: ${{ github.repository }}
pull-request-number: ${{ github.event.pull_request.number }}
pull-request-body: ${{ github.event.pull_request.body }}
copy-issues-labels: true
include-closed-issues: true
- name: Echo output
run: |
echo "is-pull-request-linked-to-issues: ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues }}"
echo "linked-issues: ${{ steps.find-linked-issues.outputs.linked-issues }}"
echo "pull-request-labels: ${{ steps.find-linked-issues.outputs.pull-request-labels }}"
- name: Linked issue found?
run: |
commentListResponse=`curl -u Ismoh:${{ secrets.WORKFLOW_PAT }} -H 'Accept: application/vnd.github+json' https://api.github.com/repos/Ismoh/NoitaMP/issues/${{github.event.number}}/comments`
echo "commentListResponse="$commentListResponse
# https://jqplay.org/s/WsuVZ8f-YiB
commentIds=$(echo $commentListResponse | jq '.[] | select(.body | contains("pull request is not linked to any issue")) | .id')
echo "commentIds="$commentIds
for commentId in $commentIds
do
echo "commentId="$commentId
statusCode=`curl -u Ismoh:${{ secrets.WORKFLOW_PAT }} -X DELETE -H 'Accept: application/vnd.github+json' https://api.github.com/repos/Ismoh/NoitaMP/issues/comments/$commentId`
echo "statusCode="$statusCode
if [[ $statusCode != "" ]]
then
echo "Unable to delete comment with id "$commentId
fi
done
if [ ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues }} == 'False' ]
then
body=":robot: _meep moop beep boop_<br/><br/>Hi @${{ github.event.pull_request.user.login }}, <br/>your pull request is not linked to any issue, please make the corresponding changes in the **very first comment** by adding<br/>\`Fixes #issue-number\` or \`Resolves #issue-number\`.<br/>If your pull request isn't linked to any issue, **ignore** this comment!"
echo "body="$body
#json=$(jq --arg body "$body" '{ $body }')
json=$(printf '%s\n' "$body" | jq -R '{ body: . }')
echo "json="$json
statusCode=`curl -X POST -H 'Accept: application/vnd.github+json' -H 'Authorization: token ${{ github.token }}' https://api.github.com/repos/Ismoh/NoitaMP/issues/${{github.event.number}}/comments -d "$json"`
echo "statusCode="$statusCode
id=$(echo $statusCode | jq '.id')
echo "id="$id
if [[ "$id" == "" ]]
then
echo "Unable to add comment to pull request!"
exit 1
fi
fi
update-version:
needs: find-linked-issues-and-copy-labels-to-pull-request
env:
LABEL_NAMES: ${{ needs.find-linked-issues-and-copy-labels-to-pull-request.outputs.labelNames }}
VERSION_FILE_NAME: 'mods/noita-mp/.version'
VERSION_FRAGMENT: 'will be fetched by file'
name: Increase version and create a tag, when merged
outputs:
futureRelease: ${{ steps.extend_version.outputs.futureRelease }}
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Increase version depending on labels
uses: HardNorth/[email protected]
with:
version-source: file
version-file: ${{ env.VERSION_FILE_NAME }}
version-file-extraction-pattern: '{"version":"v([^"]+)"}'
next-version-increment-major: ${{ contains(env.LABEL_NAMES, 'rework') }}
next-version-increment-minor: ${{ contains(env.LABEL_NAMES, 'enhancement') }}
next-version-increment-patch: ${{ contains(env.LABEL_NAMES, 'bug') }}
next-version-cut-build-metadata: false
next-version-put-build-metadata: true
#- name: Update LuaRocks rockspec
#shell: bash
#run: |
#sudo apt-get install rename
#git fetch
#git checkout ${{ github.base_ref }}
#git pull origin ${{ github.base_ref }}
#git config --local user.email "[email protected]"
#git config --local user.name "github-actions"
#currentVersionShort="$CURRENT_VERSION_MAJOR.$CURRENT_VERSION_MINOR.$CURRENT_VERSION_PATCH"
#nextVersionShort="$NEXT_VERSION_MAJOR.$NEXT_VERSION_MINOR.$NEXT_VERSION_PATCH"
#cd ${{github.workspace}}/mods/noita-mp/
#oldFilename=$(basename *.rockspec)
#echo "$oldFilename"
#newFilename=echo "${oldFilename//[/d./d./d]/"$nextVersionShort"}"
#ls -R
#cat ${{github.workspace}}/mods/noita-mp/*.rockspec
#git commit -m "Updated *.rockspec to $NEXT_VERSION in https://github.com/${{github.repository}}/pull/${{github.event.number}}"
#git push origin ${{ github.base_ref }}
- name: Extend version with custom build numbers
id: extend_version
run: |
nextVersion="v$NEXT_VERSION+$(git log --oneline | wc -l)"
echo "nextVersion="$nextVersion
echo "NEXT_VERSION=${nextVersion}" >> $GITHUB_ENV
echo "{futureRelease}={$nextVersion}" >> $GITHUB_OUTPUT
- name: Add comment to pull request
run: |
commentListResponse=`curl -H 'Accept: application/vnd.github+json' -H 'Authorization: token ${{ github.token }}' https://api.github.com/repos/Ismoh/NoitaMP/issues/${{github.event.number}}/comments`
echo "commentListResponse="$commentListResponse
# https://jqplay.org/s/WsuVZ8f-YiB
commentIds=$(echo $commentListResponse | jq '.[] | select(.body | contains("will be automatically increase to")) | .id')
echo "commentIds="$commentIds
for commentId in $commentIds
do
echo "commentId="$commentId
statusCode=`curl -X DELETE -H 'Accept: application/vnd.github+json' -H 'Authorization: token ${{ github.token }}' https://api.github.com/repos/Ismoh/NoitaMP/issues/comments/$commentId`
echo "statusCode="$statusCode
if [[ $statusCode != "" ]]
then
echo "Unable to delete comment with id "$commentId
fi
done
body=":robot: _meep moop beep boop_<br/><br/>:information_source: When this pull request was merged,<br/> the current version **v$CURRENT_VERSION** will be automatically increase to **$NEXT_VERSION** in **${{ github.base_ref }}**<br/>and a new tag with **$NEXT_VERSION** will be created to the specific commit."
echo "body="$body
json=$(printf '%s\n' "$body" | jq -R '{ body: . }')
echo "json="$json
statusCode=`curl -X POST -H 'Accept: application/vnd.github+json' -H 'Authorization: token ${{ github.token }}' https://api.github.com/repos/Ismoh/NoitaMP/issues/${{github.event.number}}/comments -d "$json"`
echo "statusCode="$statusCode
id=$(echo $statusCode | jq '.id')
echo "id="$id
if [[ "$id" == "" ]]
then
echo "Unable to add comment to pull request!"
exit 1
fi
- name: Commit and push version changes and tag it, when merged
env:
MERGED: ${{ github.event.pull_request.merged }}
run: |
if [ $MERGED == true ]
then
git fetch
git checkout ${{ github.base_ref }}
git pull origin ${{ github.base_ref }}
echo "{\"version\":\"$NEXT_VERSION\"}" > $VERSION_FILE_NAME
git config --local user.email "[email protected]"
git config --local user.name "github-actions"
git add $VERSION_FILE_NAME
git commit -m "Updated version to $NEXT_VERSION in https://github.com/${{github.repository}}/pull/${{github.event.number}}"
git tag -a "$NEXT_VERSION" -m "Automatic tag creation, do not consider tags as releases. For further technical information, see https://github.com/${{github.repository}}/pull/${{github.event.number}}"
git push origin ${{ github.base_ref }} --tags
else
echo "Pull request is not merged yet, therefore '$VERSION_FILE_NAME' will not be increased."
fi
update-changelog:
needs: update-version
env:
FUTURE_RELEASE: ${{ needs.update-version.outputs.futureRelease }}
name: Update CHANGELOG.md
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Generate CHANGELOG.md
id: generate_changelog
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
dateFormat: "%d.%m.%Y"
output: "CHANGELOG.md"
issueLineLabels: "ALL"
breakingLabels: "backwards-incompatible,breaking,rework,refactor"
futureRelease: ${{ env.FUTURE_RELEASE }}
- name: Commit and push CHANGELOG.md, when merged
env:
CHANGELOG: ${{ steps.generate_changelog.outputs.changelog }}
MERGED: ${{ github.event.pull_request.merged }}
run: |
commentListResponse=`curl -H 'Accept: application/vnd.github+json' -H 'Authorization: token ${{ github.token }}' https://api.github.com/repos/Ismoh/NoitaMP/issues/${{github.event.number}}/comments`
echo "commentListResponse="$commentListResponse
# https://jqplay.org/s/WsuVZ8f-YiB
commentIds=$(echo $commentListResponse | jq '.[] | select(.body | contains("# Changelog")) | .id')
echo "commentIds="$commentIds
for commentId in $commentIds
do
echo "commentId="$commentId
statusCode=`curl -X DELETE -H 'Accept: application/vnd.github+json' -H 'Authorization: token ${{ github.token }}' https://api.github.com/repos/Ismoh/NoitaMP/issues/comments/$commentId`
echo "statusCode="$statusCode
if [[ $statusCode != "" ]]
then
echo "Unable to delete comment with id "$commentId
fi
done
echo ""
echo "CHANGELOG="$CHANGELOG
echo ""
body=":robot: _meep moop beep boop_<br/><br/> "$CHANGELOG
echo "body="$body
json=$(printf '%s\n' "$body" | jq -Rsa '{ body: . }')
echo "json="$json
statusCode=`curl -X POST -H 'Accept: application/vnd.github+json' -H 'Authorization: token ${{ github.token }}' https://api.github.com/repos/${{github.repository}}/issues/${{github.event.number}}/comments -d "$json"`
echo "statusCode="$statusCode
id=$(echo $statusCode | jq '.id')
echo "id="$id
if [[ "$id" == "" ]]
then
echo "Unable to add comment to pull request!"
fi
if [ $MERGED == true ]
then
git fetch
git checkout ${{ github.base_ref }}
git pull origin ${{ github.base_ref }}
git config --local user.email "[email protected]"
git config --local user.name "github-actions"
git add CHANGELOG.md
git commit -m "Updated CHANGELOG.md in https://github.com/${{github.repository}}/pull/${{github.event.number}}"
git push origin ${{ github.base_ref }}
else
echo "Pull request is not merged yet, therefore CHANGELOG.md will not be updated."
fi