Skip to content

Commit 0de672f

Browse files
committed
Use version correctly
1 parent 9be9beb commit 0de672f

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Diff for: .github/workflows/on-master.yml

+29-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,35 @@ jobs:
2222
java-version: 17
2323
cache: 'gradle'
2424

25+
- id: get-snapshot-version
26+
name: Generate snapshot version
27+
shell: bash
28+
run: |
29+
version=$(git describe --tag --abbrev=0 | cut -c 2-)
30+
regex="^([0-9]+).([0-9]+).([0-9]+)$"
31+
if [[ $version =~ $regex ]]; then
32+
major="${BASH_REMATCH[1]}"
33+
minor="${BASH_REMATCH[2]}"
34+
patch="${BASH_REMATCH[3]}"
35+
36+
patch=$(($patch + 1))
37+
38+
snapshot_version="${major}.${minor}.${patch}"
39+
40+
if ! [[ $snapshot_version =~ $regex ]]; then
41+
echo "SNAPSHOT version $snapshot_version is not a valid SemVer"
42+
exit 1
43+
fi
44+
45+
echo "${snapshot_version}-SNAPSHOT"
46+
echo "snapshot-version=${snapshot_version}-SNAPSHOT" >> $GITHUB_OUTPUT
47+
else
48+
echo "Version $version is not a valid SemVer"
49+
exit 1
50+
fi
51+
2552
- name: Build with Gradle
26-
run: ./gradlew build
53+
run: ./gradlew -Pversion=${{ steps.get-snapshot-version.outputs.snapshot-version }} build
2754

2855
- name: Upload snapshot artifacts to Sonatype
2956
id: upload_snapshot_artifacts
@@ -32,4 +59,4 @@ jobs:
3259
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
3360
GPG_KEY: ${{ secrets.GPG_KEY }}
3461
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
35-
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
62+
run: ./gradlew -Pversion=${{ steps.get-snapshot-version.outputs.snapshot-version }} publishToSonatype closeAndReleaseSonatypeStagingRepository

Diff for: build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "com.github.gavlyukovskiy"
9-
version = "0.1.0-SNAPSHOT"
9+
version = version.takeUnless { it == "unspecified" } ?: "0.1.0-SNAPSHOT"
1010

1111
val sonatypeUser: String? = project.properties["sonatype_user"]?.toString()
1212
?: System.getenv("SONATYPE_USER")

0 commit comments

Comments
 (0)