Skip to content

Commit d2550ba

Browse files
jimisolalfvjimisolaslawekjaranowski
authored
Add goal for Dynamic Versioning from SCM tag (#1082)
Co-authored-by: Jimisola Laursen <[email protected]> Co-authored-by: Slawomir Jaranowski <[email protected]>
1 parent cbcf394 commit d2550ba

File tree

40 files changed

+861
-0
lines changed

40 files changed

+861
-0
lines changed

Diff for: versions-maven-plugin/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@
169169
<artifactId>javax.inject</artifactId>
170170
</dependency>
171171

172+
<!-- other -->
173+
174+
<dependency>
175+
<groupId>org.eclipse.jgit</groupId>
176+
<artifactId>org.eclipse.jgit</artifactId>
177+
<version>5.13.3.202401111512-r</version>
178+
</dependency>
179+
172180
<!-- testing -->
173181
<dependency>
174182
<groupId>commons-codec</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm
2+
invoker.buildResult = failure
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>localhost</groupId>
6+
<artifactId>it-dynamic-versioning-scm-tag-0-commits-0-tags</artifactId>
7+
<version>${revision}</version>
8+
<packaging>pom</packaging>
9+
<name>ranges-update-report</name>
10+
<url>http://localhost/</url>
11+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try {
2+
// smoke test if we have a needed tools
3+
def gitVersion = "git --version".execute()
4+
gitVersion.consumeProcessOutput(System.out, System.out)
5+
gitVersion.waitFor()
6+
return gitVersion.exitValue() == 0
7+
} catch (Exception e) {
8+
// some error occurs - we skip a test
9+
return false
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
void exec(String command) {
2+
def proc = command.execute(null, basedir)
3+
proc.consumeProcessOutput(System.out, System.out)
4+
proc.waitFor()
5+
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
6+
}
7+
8+
def testFile = new File(basedir, 'test.txt')
9+
testFile << 'content'
10+
11+
exec('git init')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check that property was set
2+
3+
def mavenLogFile = new File(basedir, 'build.log')
4+
assert mavenLogFile.exists() : "Maven log file does not exist"
5+
6+
// Read the log file
7+
def logContent = mavenLogFile.text
8+
9+
// Define a pattern to match the version output
10+
def versionPattern = /Caused by: org.apache.maven.plugin.MojoExecutionException: SCM repo has no head\/commits\./
11+
def matcher = (logContent =~ versionPattern)
12+
assert matcher.find() : "SCM repo should have no head/commits"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>localhost</groupId>
6+
<artifactId>it-dynamic-versioning-scm-tag-1-commit-0-tags</artifactId>
7+
<version>${revision}</version>
8+
<packaging>pom</packaging>
9+
<name>ranges-update-report</name>
10+
<url>http://localhost/</url>
11+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try {
2+
// smoke test if we have a needed tools
3+
def gitVersion = "git --version".execute()
4+
gitVersion.consumeProcessOutput(System.out, System.out)
5+
gitVersion.waitFor()
6+
return gitVersion.exitValue() == 0
7+
} catch (Exception e) {
8+
// some error occurs - we skip a test
9+
return false
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
void exec(String command) {
2+
def proc = command.execute(null, basedir)
3+
proc.consumeProcessOutput(System.out, System.out)
4+
proc.waitFor()
5+
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
6+
}
7+
8+
def testFile = new File(basedir, 'test.txt')
9+
testFile << 'content'
10+
11+
exec('git init')
12+
exec('git config user.email "[email protected]"')
13+
exec('git config user.name "Your Name"')
14+
15+
exec('git add test.txt')
16+
exec('git commit -m initial-commit')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check that property was set
2+
3+
def mavenLogFile = new File(basedir, 'build.log')
4+
assert mavenLogFile.exists() : "Maven log file does not exist"
5+
6+
// Read the log file
7+
def logContent = mavenLogFile.text
8+
9+
// Define a pattern to match the version output
10+
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
11+
def matcher = (logContent =~ versionPattern)
12+
assert matcher.find() : "Version information not found in log file"
13+
14+
// Extract the version from the matched group
15+
def actualVersion = matcher[0][1]
16+
17+
def expectedVersion = '0.0.1-1-SNAPSHOT'
18+
19+
assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=-X ${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>localhost</groupId>
6+
<artifactId>it-dynamic-versioning-scm-tag-4-commits-1-vtag</artifactId>
7+
<version>${revision}</version>
8+
<packaging>pom</packaging>
9+
<name>ranges-update-report</name>
10+
<url>http://localhost/</url>
11+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try {
2+
// smoke test if we have a needed tools
3+
def gitVersion = "git --version".execute()
4+
gitVersion.consumeProcessOutput(System.out, System.out)
5+
gitVersion.waitFor()
6+
return gitVersion.exitValue() == 0
7+
} catch (Exception e) {
8+
// some error occurs - we skip a test
9+
return false
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
void exec(String command) {
2+
def proc = command.execute(null, basedir)
3+
proc.consumeProcessOutput(System.out, System.out)
4+
proc.waitFor()
5+
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
6+
}
7+
8+
def testFile = new File(basedir, 'test.txt')
9+
testFile << 'content'
10+
11+
exec('git init')
12+
exec('git config user.email "[email protected]"')
13+
exec('git config user.name "Your Name"')
14+
15+
exec('git add test.txt')
16+
exec('git commit -m initial-commit')
17+
exec('git tag 1.1.1')
18+
exec('git tag')
19+
20+
testFile << 'content2'
21+
exec('git add test.txt')
22+
exec('git commit -m commit_no2')
23+
24+
testFile << 'content3'
25+
exec('git add test.txt')
26+
exec('git commit -m commit_no3')
27+
28+
testFile << 'content4'
29+
exec('git add test.txt')
30+
exec('git commit -m commit_no4')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check that property was set
2+
3+
def mavenLogFile = new File(basedir, 'build.log')
4+
assert mavenLogFile.exists() : "Maven log file does not exist"
5+
6+
// Read the log file
7+
def logContent = mavenLogFile.text
8+
9+
// Define a pattern to match the version output
10+
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
11+
def matcher = (logContent =~ versionPattern)
12+
assert matcher.find() : "Version information not found in log file"
13+
14+
// Extract the version from the matched group
15+
def actualVersion = matcher[0][1]
16+
17+
def expectedVersion = '1.1.2-4-SNAPSHOT'
18+
19+
assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>localhost</groupId>
6+
<artifactId>it-dynamic-versioning-scm-tag-latest-commit</artifactId>
7+
<version>${revision}</version>
8+
<packaging>pom</packaging>
9+
<name>ranges-update-report</name>
10+
<url>http://localhost/</url>
11+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try {
2+
// smoke test if we have a needed tools
3+
def gitVersion = "git --version".execute()
4+
gitVersion.consumeProcessOutput(System.out, System.out)
5+
gitVersion.waitFor()
6+
return gitVersion.exitValue() == 0
7+
} catch (Exception e) {
8+
// some error occurs - we skip a test
9+
return false
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
void exec(String command) {
2+
def proc = command.execute(null, basedir)
3+
proc.consumeProcessOutput(System.out, System.out)
4+
proc.waitFor()
5+
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
6+
}
7+
8+
def testFile = new File(basedir, 'test.txt')
9+
testFile << 'content'
10+
11+
exec('git init')
12+
exec('git config user.email "[email protected]"')
13+
exec('git config user.name "Your Name"')
14+
15+
exec('git add test.txt')
16+
exec('git commit -m initial-commit')
17+
exec('git tag v1.1.1')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check that property was set
2+
3+
def mavenLogFile = new File(basedir, 'build.log')
4+
assert mavenLogFile.exists() : "Maven log file does not exist"
5+
6+
// Read the log file
7+
def logContent = mavenLogFile.text
8+
9+
// Define a pattern to match the version output
10+
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
11+
def matcher = (logContent =~ versionPattern)
12+
assert matcher.find() : "Version information not found in log file"
13+
14+
// Extract the version from the matched group
15+
def actualVersion = matcher[0][1]
16+
17+
def expectedVersion = '1.1.1'
18+
19+
assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm -DappendSnapshot=false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>localhost</groupId>
6+
<artifactId>it-dynamic-versioning-scm-tag-param-append-snapshot</artifactId>
7+
<version>${revision}</version>
8+
<packaging>pom</packaging>
9+
<name>ranges-update-report</name>
10+
<url>http://localhost/</url>
11+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try {
2+
// smoke test if we have a needed tools
3+
def gitVersion = "git --version".execute()
4+
gitVersion.consumeProcessOutput(System.out, System.out)
5+
gitVersion.waitFor()
6+
return gitVersion.exitValue() == 0
7+
} catch (Exception e) {
8+
// some error occurs - we skip a test
9+
return false
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
void exec(String command) {
2+
def proc = command.execute(null, basedir)
3+
proc.consumeProcessOutput(System.out, System.out)
4+
proc.waitFor()
5+
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
6+
}
7+
8+
def testFile = new File(basedir, 'test.txt')
9+
testFile << 'content'
10+
11+
exec('git init')
12+
exec('git config user.email "[email protected]"')
13+
exec('git config user.name "Your Name"')
14+
15+
exec('git add test.txt')
16+
exec('git commit -m initial-commit')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check that property was set
2+
3+
def mavenLogFile = new File(basedir, 'build.log')
4+
assert mavenLogFile.exists() : "Maven log file does not exist"
5+
6+
// Read the log file
7+
def logContent = mavenLogFile.text
8+
9+
// Define a pattern to match the version output
10+
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
11+
def matcher = (logContent =~ versionPattern)
12+
assert matcher.find() : "Version information not found in log file"
13+
14+
// Extract the version from the matched group
15+
def actualVersion = matcher[0][1]
16+
17+
def expectedVersion = '0.0.1-1'
18+
19+
assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm -DuseVersion=9.9.9-9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>localhost</groupId>
6+
<artifactId>it-dynamic-versioning-scm-tag-param-use-versions</artifactId>
7+
<version>${revision}</version>
8+
<packaging>pom</packaging>
9+
<name>ranges-update-report</name>
10+
<url>http://localhost/</url>
11+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try {
2+
// smoke test if we have a needed tools
3+
def gitVersion = "git --version".execute()
4+
gitVersion.consumeProcessOutput(System.out, System.out)
5+
gitVersion.waitFor()
6+
return gitVersion.exitValue() == 0
7+
} catch (Exception e) {
8+
// some error occurs - we skip a test
9+
return false
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
void exec(String command) {
2+
def proc = command.execute(null, basedir)
3+
proc.consumeProcessOutput(System.out, System.out)
4+
proc.waitFor()
5+
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
6+
}
7+
8+
def testFile = new File(basedir, 'test.txt')
9+
testFile << 'content'
10+
11+
exec('git init')
12+
exec('git config user.email "[email protected]"')
13+
exec('git config user.name "Your Name"')
14+
15+
exec('git add test.txt')
16+
exec('git commit -m initial-commit')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check that property was set
2+
3+
def mavenLogFile = new File(basedir, 'build.log')
4+
assert mavenLogFile.exists() : "Maven log file does not exist"
5+
6+
// Read the log file
7+
def logContent = mavenLogFile.text
8+
9+
// Define a pattern to match the version output
10+
def versionPattern = /\[INFO\] Property 'revision' set to: (.+)/
11+
def matcher = (logContent =~ versionPattern)
12+
assert matcher.find() : "Version information not found in log file"
13+
14+
// Extract the version from the matched group
15+
def actualVersion = matcher[0][1]
16+
17+
def expectedVersion = '9.9.9-9'
18+
19+
assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-dynamic-version-from-scm -DpropertyName=version_from_scm

0 commit comments

Comments
 (0)