Génération automatique de version avec incrément piloté par git
This commit is contained in:
parent
45ff14ce10
commit
bcf34404a2
|
@ -61,7 +61,16 @@ def call(Map params = [:]) {
|
|||
|
||||
println("Last version number is '${lastVersionNumber}'")
|
||||
|
||||
def versionNumber = incrementVersionNumber(lastVersionNumber)
|
||||
def versionNumber = sh(
|
||||
script: "git describe --always ${currentRef}",
|
||||
returnStdout: true,
|
||||
).trim()
|
||||
|
||||
def isCommitRef = !versionNumber.matches(/^[0-9]+\.[0-9]+\.[0-9]+.*$/)
|
||||
|
||||
if (isCommitRef) {
|
||||
versionNumber = "0.0.0-${versionNumber}"
|
||||
}
|
||||
|
||||
println("New version number will be '${versionNumber}'")
|
||||
result['newVersionNumber'] = versionNumber
|
||||
|
@ -107,21 +116,3 @@ def call(Map params = [:]) {
|
|||
|
||||
return result
|
||||
}
|
||||
|
||||
def incrementVersionNumber(String versionNumber) {
|
||||
// Split versionNumber (typical pattern: <major>.<minor>.<patch>)
|
||||
def versionNumberParts = versionNumber.split(/\./)
|
||||
|
||||
// Extract path number
|
||||
def patchNumber = versionNumberParts.last()
|
||||
|
||||
// Split patch number (typical pattern: <patch>-<build>)
|
||||
def patchNumberParts = patchNumber.split('-')
|
||||
|
||||
// If version number matches pattern <major>.<minor>.<patch>-<build>
|
||||
if (patchNumberParts.size() > 1) {
|
||||
return versionNumberParts[0..-2].join('.') + '.' + patchNumberParts[0..-2].join('-') + '-' + (patchNumberParts.last().toInteger() + 1)
|
||||
} else { // Else version number matches pattern <major>.<minor>.<patch>
|
||||
return versionNumberParts[0..-2].join('.') + '.' + (patchNumber.toInteger() + 1)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue