Génération automatique de version avec incrément piloté par git

This commit is contained in:
wpetit 2022-09-08 10:57:30 +02:00
parent 45ff14ce10
commit bcf34404a2
1 changed files with 11 additions and 20 deletions

View File

@ -44,7 +44,7 @@ def call(Map params = [:]) {
} else {
println("Skipping push. Set skipPush param to 'true' to enable remote repository update.")
}
// Retrieve last tag matching pattern pkg/${distRepo}/${dist}-${distVersion}/*
def lastTag = sh(
script: "git tag -l 'pkg/${distRepo}/${dist}-${distVersion}/*' --sort=v:refname | tail -n 1",
@ -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
@ -106,22 +115,4 @@ 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)
}
}