Skip to content

Commit

Permalink
Add goal for Dynamic Versioning from SCM tag (#1082)
Browse files Browse the repository at this point in the history
Co-authored-by: Jimisola Laursen <jimisola.laursen@lfv.se>
Co-authored-by: Slawomir Jaranowski <s.jaranowski@gmail.com>
  • Loading branch information
3 people committed Jun 25, 2024
1 parent cbcf394 commit d2550ba
Show file tree
Hide file tree
Showing 40 changed files with 861 additions and 0 deletions.
8 changes: 8 additions & 0 deletions versions-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@
<artifactId>javax.inject</artifactId>
</dependency>

<!-- other -->

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.13.3.202401111512-r</version>
</dependency>

<!-- testing -->
<dependency>
<groupId>commons-codec</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm
invoker.buildResult = failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-dynamic-versioning-scm-tag-0-commits-0-tags</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /Caused by: org.apache.maven.plugin.MojoExecutionException: SCM repo has no head\/commits\./
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "SCM repo should have no head/commits"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-dynamic-versioning-scm-tag-1-commit-0-tags</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git config user.email "you@example.com"')
exec('git config user.name "Your Name"')

exec('git add test.txt')
exec('git commit -m initial-commit')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '0.0.1-1-SNAPSHOT'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=-X ${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-dynamic-versioning-scm-tag-4-commits-1-vtag</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git config user.email "you@example.com"')
exec('git config user.name "Your Name"')

exec('git add test.txt')
exec('git commit -m initial-commit')
exec('git tag 1.1.1')
exec('git tag')

testFile << 'content2'
exec('git add test.txt')
exec('git commit -m commit_no2')

testFile << 'content3'
exec('git add test.txt')
exec('git commit -m commit_no3')

testFile << 'content4'
exec('git add test.txt')
exec('git commit -m commit_no4')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '1.1.2-4-SNAPSHOT'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-dynamic-versioning-scm-tag-latest-commit</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git config user.email "you@example.com"')
exec('git config user.name "Your Name"')

exec('git add test.txt')
exec('git commit -m initial-commit')
exec('git tag v1.1.1')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '1.1.1'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm -DappendSnapshot=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-dynamic-versioning-scm-tag-param-append-snapshot</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git config user.email "you@example.com"')
exec('git config user.name "Your Name"')

exec('git add test.txt')
exec('git commit -m initial-commit')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '0.0.1-1'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm -DuseVersion=9.9.9-9
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-dynamic-versioning-scm-tag-param-use-versions</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git config user.email "you@example.com"')
exec('git config user.name "Your Name"')

exec('git add test.txt')
exec('git commit -m initial-commit')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '9.9.9-9'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm -DpropertyName=version_from_scm
Loading

0 comments on commit d2550ba

Please sign in to comment.