Skip to content

Commit 4e8d01a

Browse files
Create create-release.yaml
1 parent 3ce6938 commit 4e8d01a

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Create tag and release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches: [ "main" ]
9+
jobs:
10+
check-version:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
release-tag: ${{ steps.version-step.outputs.newTag }}
14+
should_run_next_job: ${{ steps.check-tag.outputs.should_continue }}
15+
steps:
16+
- name: Set up JDK 21
17+
uses: actions/setup-java@v4
18+
with:
19+
distribution: 'temurin'
20+
java-version: '21'
21+
22+
- name: Checkout repo
23+
uses: actions/checkout@v4
24+
25+
- name: Get source version
26+
id: version-step
27+
run: echo "newTag=v$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT
28+
29+
- name: Print source version
30+
run: echo ${{ steps.version-step.outputs.newTag }}
31+
32+
- uses: mukunku/tag-exists-action@v1.6.0
33+
name: Check tag existence
34+
id: check-tag-exists
35+
with:
36+
tag: ${{ steps.version-step.outputs.newTag }}
37+
38+
- name: Tag verification
39+
id: check-tag
40+
run: |
41+
if [[ "${{ steps.check-tag-exists.outputs.exists }}" == "true" ]]; then
42+
echo "Nothing to tag/release, the tag ${{ steps.version-step.outputs.newTag }} already exists"
43+
echo "should_continue=false" >> $GITHUB_OUTPUT
44+
elif ! [[ "${{ steps.version-step.outputs.newTag }}" =~ ^v[0-9]+.[0-9]+.[0-9]+$ ]]; then
45+
echo "Nothing to tag/release, the tag ${{ steps.version-step.outputs.newTag }} is not in correct format X.Y.Z"
46+
echo "should_continue=false" >> $GITHUB_OUTPUT
47+
else
48+
echo "should_continue=true" >> $GITHUB_OUTPUT
49+
fi
50+
51+
create-release:
52+
needs: [ check-version ]
53+
if: needs.check-version.outputs.should_run_next_job == 'true'
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
with:
58+
ref: ${{ github.ref }}
59+
fetch-depth: 0
60+
61+
- name: Get previous final release tag
62+
id: previousTag
63+
run: echo "previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep "^v[0-9]\+\.[0-9]\+\.[0-9]\+$" | tail -1)" >> $GITHUB_OUTPUT
64+
65+
- name: Extract content between titles
66+
id: changeLogContent
67+
run: |
68+
FILE_PATH='CHANGELOG.md'
69+
TITLE1="$(sed -n '/^## [0-9]/{p;}' $FILE_PATH | awk 'NR==1' | sed 's/^## //')"
70+
TITLE2="$(sed -n '/^## [0-9]/{p;}' $FILE_PATH | awk 'NR==2' | sed 's/^## //')"
71+
inprogress=false
72+
while read line; do
73+
if [[ $line == "## "* ]] ;
74+
then
75+
if [[ $inprogress == true ]] ;
76+
then
77+
# new block encountered, stop
78+
break
79+
else
80+
# change block encounter, begin writing change block
81+
inprogress=true
82+
fi
83+
fi
84+
if [[ $inprogress == true ]] ;
85+
then
86+
changes+=$line' \n'
87+
fi
88+
done < $FILE_PATH
89+
echo "TITLE1=${TITLE1}" >> $GITHUB_OUTPUT
90+
echo "changes=${changes}" >> $GITHUB_OUTPUT
91+
92+
- uses: softprops/action-gh-release@v2
93+
with:
94+
tag_name: ${{ needs.check-version.outputs.release-tag }}
95+
target_commitish: ${{ github.head_ref || github.ref }}
96+
name: ${{steps.changeLogContent.outputs.TITLE1 }}
97+
body: ${{steps.changeLogContent.outputs.changes}}
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)