From 2d456b4883c36f91fe280ad3460243aed21cd99a Mon Sep 17 00:00:00 2001 From: MiguelDuque Date: Tue, 21 Apr 2020 14:59:06 +0200 Subject: [PATCH 1/2] Add project version to versionFile and versionDisplay task --- README.md | 4 ++ .../tasks/VersionDisplayTask.groovy | 1 + .../versioning/tasks/VersionFileTask.groovy | 1 + .../GitVersionReleaseBuildFalseTest.groovy | 3 ++ .../git/GitVersionReleaseBuildTrueTest.groovy | 3 ++ .../versioning/git/GitVersionTest.groovy | 48 +++++++++++++++++++ .../versioning/svn/SVNVersionTest.groovy | 47 ++++++++++++++++++ 7 files changed, 107 insertions(+) diff --git a/README.md b/README.md index 95be0df..ae921e7 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ Displays the version information in the standard output. For example: [version] full = release-0.3-da50c50 [version] base = 0.3 [version] build = da50c50 +[version] gradle = 0.3.0 [version] display = 0.3.0 [version] tag = [version] lastTag = 0.2.0 @@ -180,6 +181,7 @@ VERSION_BASE=0.3 VERSION_BRANCHID=release-0.3 VERSION_BRANCHTYPE=release VERSION_COMMIT=da50c50567073d3d3a7756829926a9590f2644c6 +VERSION_GRADLE=0.3.0 VERSION_DISPLAY=0.3.0 VERSION_FULL=release-0.3-da50c50 VERSION_SCM=git @@ -210,6 +212,8 @@ versionFile { } ``` +In addition to the versioning information, `versionDisplay` and `versionFile` commands also display the `version gradle`, which represents the current version of the project. + ## Customisation The collection of the versioning info can be customised by setting some properties in the `versioning` extension. diff --git a/src/main/groovy/net/nemerosa/versioning/tasks/VersionDisplayTask.groovy b/src/main/groovy/net/nemerosa/versioning/tasks/VersionDisplayTask.groovy index 1fecda6..b0a1021 100644 --- a/src/main/groovy/net/nemerosa/versioning/tasks/VersionDisplayTask.groovy +++ b/src/main/groovy/net/nemerosa/versioning/tasks/VersionDisplayTask.groovy @@ -30,6 +30,7 @@ class VersionDisplayTask extends DefaultTask { println "[version] full = ${info.full}" println "[version] base = ${info.base}" println "[version] build = ${info.build}" + println "[version] gradle = ${project.version == 'unspecified' ? '' : project.version}" println "[version] display = ${info.display}" println "[version] tag = ${info.tag ?: ''}" println "[version] lastTag = ${info.lastTag ?: ''}" diff --git a/src/main/groovy/net/nemerosa/versioning/tasks/VersionFileTask.groovy b/src/main/groovy/net/nemerosa/versioning/tasks/VersionFileTask.groovy index d56f3d7..08ffff7 100644 --- a/src/main/groovy/net/nemerosa/versioning/tasks/VersionFileTask.groovy +++ b/src/main/groovy/net/nemerosa/versioning/tasks/VersionFileTask.groovy @@ -41,6 +41,7 @@ ${prefix}BASE=${info.base} ${prefix}BRANCHID=${info.branchId} ${prefix}BRANCHTYPE=${info.branchType} ${prefix}COMMIT=${info.commit} +${prefix}GRADLE=${project.version == 'unspecified' ? '' : project.version} ${prefix}DISPLAY=${info.display} ${prefix}FULL=${info.full} ${prefix}SCM=${info.scm} diff --git a/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildFalseTest.groovy b/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildFalseTest.groovy index 1a5b96d..508960b 100644 --- a/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildFalseTest.groovy +++ b/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildFalseTest.groovy @@ -274,6 +274,7 @@ VERSION_BASE=\n\ VERSION_BRANCHID=master VERSION_BRANCHTYPE=master VERSION_COMMIT=${head} +VERSION_GRADLE= VERSION_DISPLAY=master-${headAbbreviated} VERSION_FULL=master-${headAbbreviated} VERSION_SCM=git @@ -323,6 +324,7 @@ CUSTOM_BASE=\n\ CUSTOM_BRANCHID=master CUSTOM_BRANCHTYPE=master CUSTOM_COMMIT=${head} +CUSTOM_GRADLE= CUSTOM_DISPLAY=master-${headAbbreviated} CUSTOM_FULL=master-${headAbbreviated} CUSTOM_SCM=git @@ -372,6 +374,7 @@ VERSION_BASE=\n\ VERSION_BRANCHID=master VERSION_BRANCHTYPE=master VERSION_COMMIT=${head} +VERSION_GRADLE= VERSION_DISPLAY=master-${headAbbreviated} VERSION_FULL=master-${headAbbreviated} VERSION_SCM=git diff --git a/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildTrueTest.groovy b/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildTrueTest.groovy index 7253585..71402dd 100644 --- a/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildTrueTest.groovy +++ b/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildTrueTest.groovy @@ -274,6 +274,7 @@ VERSION_BASE=\n\ VERSION_BRANCHID=master VERSION_BRANCHTYPE=master VERSION_COMMIT=${head} +VERSION_GRADLE= VERSION_DISPLAY=master-${headAbbreviated} VERSION_FULL=master-${headAbbreviated} VERSION_SCM=git @@ -323,6 +324,7 @@ CUSTOM_BASE=\n\ CUSTOM_BRANCHID=master CUSTOM_BRANCHTYPE=master CUSTOM_COMMIT=${head} +CUSTOM_GRADLE= CUSTOM_DISPLAY=master-${headAbbreviated} CUSTOM_FULL=master-${headAbbreviated} CUSTOM_SCM=git @@ -372,6 +374,7 @@ VERSION_BASE=\n\ VERSION_BRANCHID=master VERSION_BRANCHTYPE=master VERSION_COMMIT=${head} +VERSION_GRADLE= VERSION_DISPLAY=master-${headAbbreviated} VERSION_FULL=master-${headAbbreviated} VERSION_SCM=git diff --git a/src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy b/src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy index fec2b7f..9850b7f 100644 --- a/src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy +++ b/src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy @@ -256,6 +256,52 @@ VERSION_BASE=\n\ VERSION_BRANCHID=master VERSION_BRANCHTYPE=master VERSION_COMMIT=${head} +VERSION_GRADLE= +VERSION_DISPLAY=master-${headAbbreviated} +VERSION_FULL=master-${headAbbreviated} +VERSION_SCM=git +VERSION_TAG= +VERSION_LAST_TAG= +VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= +""" as String + } finally { + repo.close() + } + } + + @Test + void 'Git version file - project version'() { + GitRepo repo = new GitRepo() + try { + // Git initialisation + repo.with { + (1..4).each { commit it } + } + def head = repo.commitLookup('Commit 4') + def headAbbreviated = repo.commitLookup('Commit 4', true) + + def project = ProjectBuilder.builder().withProjectDir(repo.dir).build() + project.version = '0.0.1' + new VersioningPlugin().apply(project) + def task = project.tasks.getByName('versionFile') as DefaultTask + task.execute() + + // Checks the file + def file = new File(project.buildDir, 'version.properties') + assert file.exists(): "File ${file} must exist." + assert file.text == """\ +VERSION_BUILD=${headAbbreviated} +VERSION_BRANCH=master +VERSION_BASE=\n\ +VERSION_BRANCHID=master +VERSION_BRANCHTYPE=master +VERSION_COMMIT=${head} +VERSION_GRADLE=0.0.1 VERSION_DISPLAY=master-${headAbbreviated} VERSION_FULL=master-${headAbbreviated} VERSION_SCM=git @@ -302,6 +348,7 @@ CUSTOM_BASE=\n\ CUSTOM_BRANCHID=master CUSTOM_BRANCHTYPE=master CUSTOM_COMMIT=${head} +CUSTOM_GRADLE= CUSTOM_DISPLAY=master-${headAbbreviated} CUSTOM_FULL=master-${headAbbreviated} CUSTOM_SCM=git @@ -348,6 +395,7 @@ VERSION_BASE=\n\ VERSION_BRANCHID=master VERSION_BRANCHTYPE=master VERSION_COMMIT=${head} +VERSION_GRADLE= VERSION_DISPLAY=master-${headAbbreviated} VERSION_FULL=master-${headAbbreviated} VERSION_SCM=git diff --git a/src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy b/src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy index 165ac36..235e667 100644 --- a/src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy +++ b/src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy @@ -129,6 +129,51 @@ VERSION_BASE=\n\ VERSION_BRANCHID=trunk VERSION_BRANCHTYPE=trunk VERSION_COMMIT=4 +VERSION_GRADLE= +VERSION_DISPLAY=trunk-4 +VERSION_FULL=trunk-4 +VERSION_SCM=svn +VERSION_TAG= +VERSION_LAST_TAG= +VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= +""" + } + + @Test + void 'SVN version file - project version'() { + // SVN + repo.mkdir 'project/trunk', 'Trunk' + repo.mkdir 'project/trunk/1', 'Commit for TEST-1' + repo.mkdir 'project/trunk/2', 'Commit for TEST-2' + def dir = repo.checkout('project/trunk') + ignore dir, '.gradle' + // Project + def project = ProjectBuilder.builder().withProjectDir(dir).build() + project.version = '0.0.1' + new VersioningPlugin().apply(project) + project.versioning { + scm = 'svn' + } + // version file task + def task = project.tasks.getByName('versionFile') as DefaultTask + task.execute() + + // Checks the file + def file = new File(project.buildDir, 'version.properties') + assert file.exists(): "File ${file} must exist." + assert file.text == """\ +VERSION_BUILD=4 +VERSION_BRANCH=trunk +VERSION_BASE=\n\ +VERSION_BRANCHID=trunk +VERSION_BRANCHTYPE=trunk +VERSION_COMMIT=4 +VERSION_GRADLE=0.0.1 VERSION_DISPLAY=trunk-4 VERSION_FULL=trunk-4 VERSION_SCM=svn @@ -174,6 +219,7 @@ CUSTOM_BASE=\n\ CUSTOM_BRANCHID=trunk CUSTOM_BRANCHTYPE=trunk CUSTOM_COMMIT=4 +CUSTOM_GRADLE= CUSTOM_DISPLAY=trunk-4 CUSTOM_FULL=trunk-4 CUSTOM_SCM=svn @@ -219,6 +265,7 @@ VERSION_BASE=\n\ VERSION_BRANCHID=trunk VERSION_BRANCHTYPE=trunk VERSION_COMMIT=4 +VERSION_GRADLE= VERSION_DISPLAY=trunk-4 VERSION_FULL=trunk-4 VERSION_SCM=svn From c3566a763d7dee1cbf5d93f257722cc3d023ffd4 Mon Sep 17 00:00:00 2001 From: MiguelDuque Date: Tue, 21 Apr 2020 15:42:20 +0200 Subject: [PATCH 2/2] Readme - Add gradle version to Versioning info table --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index ae921e7..9e896ba 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ Property | Description | Git: `master` | Git: `feature/great` | Git: `release/2. `build` | Short commit/revision indicator, suitable for a build number | `09ef629` | `09ef629` | `09ef629` `full` | Branch ID and build | `master-09ef629` | `feature-great-09ef629` | `release-2.0-09ef629` `base` | Base version for the display version | `` | `great` | `2.0` +`gradle` | Project's version | | | `display` | Display version | `master` | `great` | `2.0.0`, `2.0.1`, ... `tag` (1) | Current tag | (2) | (2) | (2) `lastTag` (1) | Last tag | (4) | (4) | (4) @@ -212,8 +213,6 @@ versionFile { } ``` -In addition to the versioning information, `versionDisplay` and `versionFile` commands also display the `version gradle`, which represents the current version of the project. - ## Customisation The collection of the versioning info can be customised by setting some properties in the `versioning` extension.