Skip to content

Commit 49f20d2

Browse files
committed
Enhance GitHub release action
1 parent a76f45c commit 49f20d2

File tree

1 file changed

+72
-22
lines changed

1 file changed

+72
-22
lines changed

.github/workflows/release.yml

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,82 @@ on:
88
- 'v*'
99

1010
jobs:
11+
version:
12+
runs-on: ubuntu-latest
13+
14+
outputs:
15+
VERSION: ${{ steps.setver.outputs.VERSION }}
16+
17+
steps:
18+
- name: Determine version
19+
id: setver
20+
run: |
21+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
22+
RAW_TAG=${GITHUB_REF#refs/tags/}
23+
VERSION=${RAW_TAG#v}
24+
VERSION=${VERSION#V}
25+
else
26+
VERSION=1.0.0-SNAPSHOT
27+
fi
28+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
29+
1130
build:
1231
runs-on: ubuntu-latest
32+
needs: version
33+
1334
steps:
14-
# --- Checkout ---
1535
- name: Checkout code
1636
uses: actions/checkout@v4
37+
38+
- name: Setup JDK
39+
uses: actions/setup-java@v4
40+
with:
41+
java-version: '21'
42+
distribution: temurin
43+
44+
- name: Set version
45+
run: |
46+
mvn -B versions:set -DnewVersion=${{ needs.version.outputs.VERSION }}
47+
mvn -B versions:set-property -Dproperty=revision -DnewVersion=${{ needs.version.outputs.VERSION }}
48+
49+
- name: Build
50+
run: mvn -B -DskipTests package
51+
52+
test:
53+
runs-on: ubuntu-latest
54+
needs: version
55+
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@v4
59+
60+
- name: Set up JDK
61+
uses: actions/setup-java@v4
62+
with:
63+
java-version: '21'
64+
distribution: temurin
65+
66+
- name: Set version
67+
run: |
68+
mvn -B versions:set -DnewVersion=${{ needs.version.outputs.VERSION }}
69+
mvn -B versions:set-property -Dproperty=revision -DnewVersion=${{ needs.version.outputs.VERSION }}
70+
71+
- name: Run tests
72+
run: mvn -B test
73+
74+
deploy:
75+
runs-on: ubuntu-latest
76+
needs: [ version, test ]
77+
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
78+
79+
steps:
80+
- name: Checkout
81+
uses: actions/checkout@v4
1782
with:
1883
fetch-depth: 0
1984

20-
# --- Setup Java + GPG ---
21-
- name: Setup JDK
22-
uses: actions/setup-java@v3
85+
- name: Set up JDK + GPG
86+
uses: actions/setup-java@v4
2387
with:
2488
java-version: '21'
2589
distribution: temurin
@@ -29,26 +93,12 @@ jobs:
2993
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
3094
gpg-passphrase: GPG_PASSPHRASE
3195

32-
# --- Determine version ---
33-
- name: Determine version
34-
run: |
35-
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
36-
RAW_TAG=${GITHUB_REF#refs/tags/}
37-
VERSION=${RAW_TAG#v}
38-
VERSION=${VERSION#V}
39-
else
40-
VERSION=1.0.0-SNAPSHOT
41-
fi
42-
echo "VERSION=$VERSION" >> $GITHUB_ENV
43-
44-
# --- Set Maven project version ---
45-
- name: Set Maven version
96+
- name: Set version
4697
run: |
47-
mvn -B versions:set -DnewVersion=$VERSION
48-
mvn -B versions:set-property -Dproperty=revision -DnewVersion=$VERSION
98+
mvn -B versions:set -DnewVersion=${{ needs.version.outputs.VERSION }}
99+
mvn -B versions:set-property -Dproperty=revision -DnewVersion=${{ needs.version.outputs.VERSION }}
49100
50-
# --- Build and deploy ---
51-
- name: Build & Deploy
101+
- name: Deploy to Maven Central
52102
env:
53103
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
54104
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}

0 commit comments

Comments
 (0)