1- name : Manual Release
1+ name : Release
22
33on :
44 workflow_dispatch :
5+ push :
6+ branches :
7+ - main
58
69permissions :
710 contents : write
@@ -13,32 +16,49 @@ jobs:
1316 - name : Checkout repository
1417 uses : actions/checkout@v4
1518
19+ - name : Get version from gradle.properties
20+ id : project_version
21+ run : echo "version=$(grep '^version=' gradle.properties | cut -d'=' -f2)" >> $GITHUB_OUTPUT
22+
23+ - name : Check if version already exists
24+ id : check_version
25+ run : |
26+ VERSION=${{ steps.project_version.outputs.version }}
27+ if git ls-remote --tags origin | grep -q "refs/tags/v${VERSION}$"; then
28+ echo "exists=true" >> $GITHUB_OUTPUT
29+ echo "Version v${VERSION} already exists, skipping release"
30+ else
31+ echo "exists=false" >> $GITHUB_OUTPUT
32+ echo "Version v${VERSION} is new, will create release"
33+ fi
34+
1635 - name : Set up JDK 21
36+ if : steps.check_version.outputs.exists == 'false'
1737 uses : actions/setup-java@v4
1838 with :
1939 java-version : " 21"
2040 distribution : " temurin"
2141
2242 - name : Setup Gradle
43+ if : steps.check_version.outputs.exists == 'false'
2344 uses : gradle/actions/setup-gradle@v4
2445 with :
2546 gradle-version : " 8.9"
2647
27- - name : Get version from gradle.properties
28- id : project_version
29- run : echo "version=$(grep '^version=' gradle.properties | cut -d'=' -f2)" >> $GITHUB_OUTPUT
30-
3148 - name : Package artifacts
49+ if : steps.check_version.outputs.exists == 'false'
3250 run : gradle package
3351
3452 - name : Delete existing tag if exists
53+ if : steps.check_version.outputs.exists == 'false'
3554 run : |
3655 VERSION=${{ steps.project_version.outputs.version }}
3756 git tag -d "v${VERSION}" 2>/dev/null || true
3857 git push origin ":refs/tags/v${VERSION}" 2>/dev/null || true
3958 continue-on-error : true
4059
4160 - name : Create and push tag
61+ if : steps.check_version.outputs.exists == 'false'
4262 run : |
4363 VERSION=${{ steps.project_version.outputs.version }}
4464 git config --local user.email "action@github.com"
4767 git push origin "v${VERSION}"
4868
4969 - name : Release
70+ if : steps.check_version.outputs.exists == 'false'
5071 uses : softprops/action-gh-release@v2
5172 with :
5273 tag_name : v${{ steps.project_version.outputs.version }}
0 commit comments