Skip to content

Commit 14ab562

Browse files
Add a gradle task to validate tag version
1 parent 5a8b5e4 commit 14ab562

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,7 @@ jobs:
2525
with:
2626
fetch-tags: true
2727
- name: "Validate version tag doesn't exist"
28-
run: |
29-
VERSION=$(grep '^version=' gradle.properties | cut -d'=' -f2)
30-
TAG="v${VERSION}"
31-
REPO_URL="https://github.com/${{ github.repository }}"
32-
if git ls-remote --tags "${REPO_URL}" | grep -q "refs/tags/${TAG}$"; then
33-
echo "============================================="
34-
echo "ERROR: Tag ${TAG} already exists!"
35-
echo ""
36-
echo "Please bump the version in gradle.properties"
37-
echo "============================================="
38-
exit 1
39-
fi
40-
echo "✓ Version ${VERSION} is valid (tag ${TAG} does not exist yet)"
28+
run: GRADLE_USER_HOME=$HOME/.gradle ./gradlew validateVersion --console=plain --no-daemon
4129
- name: "Gradle cache"
4230
uses: actions/cache@v4
4331
with:

build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,21 @@ task tagRelease {
168168
}
169169
}
170170
}
171+
172+
task validateVersion {
173+
doLast {
174+
def tagName = "v$version"
175+
def remoteTags = grgit.lsremote(tags: true).keySet().collect { it.toString() }
176+
def remoteHasTag = remoteTags.any { it.endsWith("/${tagName}") || it == tagName }
177+
if (remoteHasTag) {
178+
throw new GradleException("""
179+
|=============================================
180+
| ERROR: Tag ${tagName} already exists!
181+
|
182+
| Please bump the version in gradle.properties
183+
|=============================================
184+
""".stripMargin())
185+
}
186+
logger.lifecycle("✓ Version ${version} is valid (tag ${tagName} does not exist yet)")
187+
}
188+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=1.35.8-2
1+
version=1.35.8-1
22
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

0 commit comments

Comments
 (0)