Skip to content

Commit ff35f7a

Browse files
committed
Release on pom version changes
1 parent 973c065 commit ff35f7a

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

.github/workflows/main.yml

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ on:
44
push:
55
branches:
66
- master
7-
tags:
8-
- 'v*'
7+
8+
permissions:
9+
contents: write
910

1011
jobs:
1112
build-java:
@@ -20,7 +21,9 @@ jobs:
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 }}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>w</groupId>
66
<artifactId>swapper</artifactId>
7-
<version>0.0.1-SNAPSHOT</version>
7+
<version>0.0.1</version>
88
<name>swapper</name>
99
<description>swapper</description>
1010
<properties>

0 commit comments

Comments
 (0)