Skip to content

Commit

Permalink
feat: support to force using release version
Browse files Browse the repository at this point in the history
...using an environment variable.

Set the environment variable `RELEASE` to `true` to force the release
version to be used, even if the repository is dirty or no tag exists at
the current commit.
  • Loading branch information
stempler committed Mar 25, 2024
1 parent fd6f5d1 commit 6d730bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ The plugin works based on the following assumptions:
3. If the git repository is not clean or HEAD does not point to a tag, the project version is a SNAPSHOT version that increases the minor version compared to the last release version
4. If no release version is configured or the version file is missing, the project version is `1.0.0-SNAPSHOT`

If the environment variable `RELEASE` is set to `true`, the release version is used, even if the repository is not clean or there is no tag.
This is intended for use cases where the release version was set, but the repository is dirty or no tag was created.

By default the version file is assumed to be the file `version.txt` in the root project.
17 changes: 14 additions & 3 deletions src/main/groovy/to/wetransform/gradle/version/VersionPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ class VersionPlugin implements Plugin<Project> {

String determineVersion(Project project, File versionFile, File gitDir) {
// read version from file
if (!versionFile.exists()) {
def releaseVersion = null
if (versionFile.exists()) {
releaseVersion = versionFile.text.trim()
}

//TODO parse/verify version

if (!releaseVersion) {
// assume initial snapshot
project.logger.info("Version file does not exists, assuming 1.0.0-SNAPSHOT")
project.logger.info("Version file does not exist or contains no version, assuming 1.0.0-SNAPSHOT")
return '1.0.0-SNAPSHOT'
}
def releaseVersion = versionFile.text.trim()

if ('true'.equalsIgnoreCase(System.getenv('RELEASE'))) {
// force release version (e.g if repo is dirty during release in CI)
return releaseVersion
}

def dirty = false
def tagOnCurrentCommit = false
Expand Down

0 comments on commit 6d730bb

Please sign in to comment.