Skip to content

Commit 346a427

Browse files
committed
add release steps to github actions
1 parent 71ae12e commit 346a427

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

.github/workflows/default.yml

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ on:
1010
jobs:
1111

1212
# ---------------------------------------------------------------------------
13-
build-and-publish:
13+
build-and-test:
1414
runs-on: ubuntu-latest
15+
permissions:
16+
id-token: write
17+
contents: write
18+
outputs:
19+
version: ${{ steps.extract-version.outputs.version }}
1520

1621
steps:
1722
- name: Checkout repository
@@ -31,6 +36,32 @@ jobs:
3136
java-version: 11
3237
distribution: corretto
3338

39+
- name: Extract Version
40+
id: extract-version
41+
run: |
42+
if [[ "${{ github.event_name == 'release'}}" = "true" ]]; then
43+
VERSION=$(git describe --tags | cut -d v -f2)
44+
else
45+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout);
46+
fi
47+
echo "Detected version = $VERSION"
48+
echo "version=$VERSION" >> $GITHUB_OUTPUT
49+
50+
- name: Set Release Version
51+
if: ${{ github.event_name == 'release' }}
52+
run: |
53+
git config user.email "[email protected]"
54+
git config user.name "GitHub Actions"
55+
56+
RELEASE_VERSION="${{ steps.extract-version.outputs.version }}"
57+
mvn -B versions:set "-DnewVersion=$RELEASE_VERSION" versions:commit
58+
git commit -am "[skip ci] set release version $RELEASE_VERSION"
59+
git push origin HEAD:master
60+
61+
TAG_NAME="v$RELEASE_VERSION"
62+
git tag -f $TAG_NAME
63+
git push origin -f --tags
64+
3465
- name: Maven Build
3566
run: mvn -B verify -Pci
3667

@@ -40,3 +71,42 @@ jobs:
4071
name: target
4172
path: target/*.jar
4273
retention-days: 2
74+
75+
76+
prepare-next-snapshot:
77+
needs: build-and-test
78+
runs-on: ubuntu-latest
79+
if: ${{ github.event_name == 'release' }}
80+
steps:
81+
- name: Checkout Source
82+
uses: actions/checkout@v4
83+
84+
- name: Download Maven Cache
85+
uses: actions/cache@v4
86+
with:
87+
path: ~/.m2/repository
88+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
89+
restore-keys: |
90+
${{ runner.os }}-maven-
91+
92+
- name: Setup JDK 11
93+
uses: actions/setup-java@v4
94+
with:
95+
java-version: 11
96+
distribution: corretto
97+
98+
- name: Prepare next Snapshot Version
99+
run: |
100+
git config user.email "[email protected]"
101+
git config user.name "GitHub Actions"
102+
git pull origin HEAD
103+
104+
VERSION="${{ needs.build-and-test.outputs.version }}"
105+
MAJOR_VERSION=$(echo "$VERSION" | cut -d . -f1)
106+
MINOR_VERSION=$(echo "$VERSION" | cut -d . -f2)
107+
INCREMENT_VERSION=$(echo "$VERSION" | cut -d . -f3)
108+
NEXT_INCREMENT_VERSION=$((INCREMENT_VERSION + 1))
109+
NEXT_SNAPSHOT_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$NEXT_INCREMENT_VERSION-SNAPSHOT"
110+
mvn -B versions:set "-DnewVersion=$NEXT_SNAPSHOT_VERSION" versions:commit
111+
git commit -am "[skip ci] set development version $NEXT_SNAPSHOT_VERSION"
112+
git push origin HEAD:master

0 commit comments

Comments
 (0)