Skip to content

Commit

Permalink
Merge pull request #76 from miguelduque/feature/project-version-to-ve…
Browse files Browse the repository at this point in the history
…rsionFile-versionDisplay

Add project version to versionFile and versionDisplay task
  • Loading branch information
dcoraboeuf authored Apr 21, 2020
2 parents 7a50c9e + c3566a7 commit d89e3c4
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -156,6 +157,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
Expand All @@ -180,6 +182,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?: ''}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d89e3c4

Please sign in to comment.