Skip to content

Commit

Permalink
feat: add task to verify if version is a release version
Browse files Browse the repository at this point in the history
  • Loading branch information
stempler committed Mar 30, 2024
1 parent 2561528 commit 1cebb6d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins:
- - "@semantic-release/exec"
- publishCmd: ./gradlew publishPlugins
prepareCmd: ./gradlew "-PnewVersion=${nextRelease.version}" setReleaseVersion
verifyReleaseCmd: ./gradlew verifyReleaseVersion
- - "@semantic-release/git"
- assets:
- CHANGELOG.md
Expand Down
28 changes: 25 additions & 3 deletions src/main/groovy/to/wetransform/gradle/version/VersionPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import org.gradle.api.Plugin;
import org.gradle.api.Project;

class VersionPlugin implements Plugin<Project> {

private static def SEM_VER_REGEX = /(\d+)\.(\d+)\.(\d+)/

void apply(Project project) {
//XXX not sure how to easiest use the service - instead the repo is opened manually
// project.apply(plugin: 'org.ajoberstar.grgit.service')
Expand Down Expand Up @@ -31,6 +34,19 @@ class VersionPlugin implements Plugin<Project> {
}
}

project.task('verifyReleaseVersion') {
group 'Version'
description 'Check if a release version is configured, otherwise (if the version is a -SNAPSHOT version) fail'

doLast {
def version = project.version

assert version
assert !version.endsWith('-SNAPSHOT')
assert version =~ SEM_VER_REGEX
}
}

// set version

project.afterEvaluate {
Expand All @@ -47,9 +63,15 @@ class VersionPlugin implements Plugin<Project> {
def releaseVersion = null
if (versionFile.exists()) {
releaseVersion = versionFile.text.trim()
}

//TODO parse/verify version
// verify version
if (releaseVersion) {
def matcher = releaseVersion =~ SEM_VER_REGEX
if (!matcher) {
throw new IllegalStateException("Provided version for last release is not a valid semantic version: $releaseVersion")
}
}
}

if (!releaseVersion) {
// assume initial snapshot
Expand Down Expand Up @@ -86,7 +108,7 @@ class VersionPlugin implements Plugin<Project> {
}
else {
// build snapshot version with next minor version
def matcher = releaseVersion =~ /(\d+)\.(\d+)\.(\d+)/
def matcher = releaseVersion =~ SEM_VER_REGEX
if (matcher) {
project.logger.info("Current commit is not tagged or repository is dirty, using snapshot version based on last release")

Expand Down

0 comments on commit 1cebb6d

Please sign in to comment.