44 push :
55 branches :
66 - master
7- tags :
8- - ' v*'
7+
8+ permissions :
9+ contents : write
910
1011jobs :
1112 build-java :
2021 distribution : ' adopt'
2122 - name : Build Java with Maven
2223 run : |
23- mvn package && cp target/swapper-0.0.1-SNAPSHOT.jar swapper.jar
24+ VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
25+ mvn package
26+ cp "target/swapper-${VERSION}.jar" swapper.jar
2427 shell : bash
2528 - name : Upload Jar
2629 uses : actions/upload-artifact@v4
@@ -40,28 +43,60 @@ jobs:
4043
4144
4245 release :
43- if : startsWith(github.ref, 'refs/tags/')
4446 needs : ["build-java"]
4547 runs-on : ubuntu-latest
4648 steps :
49+ - uses : actions/checkout@v3
50+ with :
51+ fetch-depth : 0
52+ - name : Set up JDK 8
53+ uses : actions/setup-java@v3
54+ with :
55+ java-version : ' 8'
56+ distribution : ' adopt'
57+ - name : Check Version Change
58+ id : version
59+ run : |
60+ CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
61+ PREVIOUS_VERSION=""
62+ BEFORE_SHA="${{ github.event.before }}"
63+
64+ if [ -n "$BEFORE_SHA" ] && [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ] && git show "${BEFORE_SHA}:pom.xml" > previous-pom.xml 2>/dev/null; then
65+ PREVIOUS_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -f previous-pom.xml)
66+ fi
67+
68+ echo "current=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
69+ echo "previous=${PREVIOUS_VERSION}" >> "$GITHUB_OUTPUT"
70+
71+ if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
72+ echo "changed=true" >> "$GITHUB_OUTPUT"
73+ else
74+ echo "changed=false" >> "$GITHUB_OUTPUT"
75+ fi
76+ shell : bash
4777 - name : Download Artifacts
78+ if : steps.version.outputs.changed == 'true'
4879 uses : actions/download-artifact@v4
4980 - name : tree
81+ if : steps.version.outputs.changed == 'true'
5082 run : |
5183 tree artifacts
5284 - name : Create Release
85+ if : steps.version.outputs.changed == 'true'
5386 id : create_release
5487 uses : actions/create-release@v1
5588 env :
5689 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5790 with :
58- tag_name : ${{ github.ref }}
59- release_name : Release ${{ github.ref }}
91+ tag_name : v ${{ steps.version.outputs.current }}
92+ release_name : Release v ${{ steps.version.outputs.current }}
6093 draft : false
6194 prerelease : false
6295 - name : Upload Release Assets
96+ if : steps.version.outputs.changed == 'true'
6397 uses : softprops/action-gh-release@v1
6498 with :
99+ tag_name : v${{ steps.version.outputs.current }}
65100 files : artifacts/*
66101 env :
67102 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments