Skip to content

Commit a6073e8

Browse files
authored
[citest skip] Add changelog_to_tag.yml to .github/workflows (linux-system-roles#55)
Description: When a new changelog section is added to CHANGELOG.md and pushed, changelog_to_tag.yml is triggered, which generates a new tag and a new release. Example of CHANGELOG.md changes: [9.9.9] - 2022-12-31 -------------------- ### New features - New feature A ### Bug fixes - Bug fix B Using this example, when the commit on CHANGELOG.md is pushed, a new tag "9.9.9" is added and Version 9.9.9 is released in github. If tag "9.9.9" already exists, the CHANGELOG.md push fails. Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
1 parent bc56175 commit a6073e8

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# yamllint disable rule:line-length
2+
name: Pushing CHANGELOG.md triggers tagging
3+
on: # yamllint disable-line rule:truthy
4+
push:
5+
branches:
6+
- main
7+
- master
8+
paths:
9+
- CHANGELOG.md
10+
env:
11+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
12+
jobs:
13+
tagging:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: checkout PR
17+
uses: actions/checkout@v2
18+
- name: Get tag and message from the latest CHANGELOG.md commit
19+
id: tag
20+
run: |
21+
set -euxo pipefail
22+
pat='\[[0-9]*\.[0-9]*\.[0-9]*\] - [0-9\-]*'
23+
print=false
24+
cat CHANGELOG.md | while read -r line; do
25+
if [[ $line =~ $pat ]] && [[ $print == false ]]; then
26+
echo $line
27+
print=true
28+
elif [[ $line =~ $pat ]] && [[ $print == true ]]; then
29+
break
30+
elif [[ $print == true ]]; then
31+
echo $line
32+
fi
33+
done > ./.tagmsg.txt
34+
_tagname=$( grep -m 1 "[0-9]*\.[0-9]*\.[0-9]*" CHANGELOG.md | sed -e "s/^.*\[\([0-9]*\.[0-9]*\.[0-9]*\)\].*/\1/" )
35+
git fetch --all --tags
36+
for t in $( git tag -l ); do
37+
if [[ $t == "$_tagname" ]]; then
38+
echo INFO: tag $t already exists
39+
exit 1
40+
fi
41+
done
42+
echo ::set-output name=tagname::"$_tagname"
43+
- name: Create tag
44+
uses: mathieudutour/github-tag-action@v6.0
45+
with:
46+
github_token: ${{ secrets.GITHUB_TOKEN }}
47+
custom_tag: ${{ steps.tag.outputs.tagname }}
48+
tag_prefix: ''
49+
- name: Create Release
50+
id: create_release
51+
uses: actions/create-release@v1
52+
with:
53+
tag_name: ${{ steps.tag.outputs.tagname }}
54+
release_name: Version ${{ steps.tag.outputs.tagname }}
55+
body_path: ./.tagmsg.txt
56+
draft: false
57+
prerelease: false

0 commit comments

Comments
 (0)