From b47fd1f6b481460ff0db88b39934243ecb251092 Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Thu, 4 Dec 2025 17:37:51 +0100 Subject: [PATCH] feat(ci): add version linter --- Makefile | 1 + build.gradle | 2 ++ .../src/main/groovy/VersionCheckTask.groovy | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 buildSrc/src/main/groovy/VersionCheckTask.groovy diff --git a/Makefile b/Makefile index 686a63b..1605671 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ fmt: lint: @./gradlew pmdMain + @./gradlew lintProjectVersion test: @./gradlew test diff --git a/build.gradle b/build.gradle index 07e2e25..52d45de 100644 --- a/build.gradle +++ b/build.gradle @@ -113,6 +113,8 @@ subprojects { logger.warn("VERSION file not found in project '${project.path}'. Skipping version setting.") } + tasks.register('lintProjectVersion', VersionCheckTask) {} + java { withSourcesJar() withJavadocJar() diff --git a/buildSrc/src/main/groovy/VersionCheckTask.groovy b/buildSrc/src/main/groovy/VersionCheckTask.groovy new file mode 100644 index 0000000..8b9abc4 --- /dev/null +++ b/buildSrc/src/main/groovy/VersionCheckTask.groovy @@ -0,0 +1,24 @@ +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.Input +import org.gradle.api.GradleException + +class VersionCheckTask extends DefaultTask { + @Input + def versionRegex = ~/^[0-1]\.\d+\.\d+$/ + + @TaskAction + def checkVersion() { + File versionFile = project.file('VERSION') + + if (!versionFile.exists()) { + logger.quiet("VERSION file not found in subproject: ${project.name}") + return + } + + def version = versionFile.text.trim() + if (!(version =~ versionRegex)) { + throw new GradleException("Version '${version}' in project '${project.name}' does not match regex: ${versionRegex}") + } + } +}