refactor: improve version checking logic in SemanticReleasingExecutor
Signed-off-by: zhenyus <zhenyus@mathmast.com>
This commit is contained in:
parent
733a559222
commit
64a4d5b02e
@ -29,6 +29,15 @@ class SemanticReleasingExecutor {
|
||||
steps.writeFile file: '.releaserc.json', text: steps.libraryResource(config)
|
||||
steps.sh "git config --global --add safe.directory ${steps.env.workroot}"
|
||||
steps.env.GIT_LOCAL_BRANCH = "${branch}"
|
||||
|
||||
// Store the version before semantic release
|
||||
def previousVersion = ""
|
||||
def versionFileExistsBefore = steps.sh(script: 'test -f "VERSION"', returnStatus: true) == 0
|
||||
if (versionFileExistsBefore) {
|
||||
previousVersion = steps.readFile('VERSION').trim()
|
||||
steps.log.info("SemanticReleasingExecutor", "Previous version: ${previousVersion}")
|
||||
}
|
||||
|
||||
steps.sh """
|
||||
#!/bin/bash
|
||||
semantic-release
|
||||
@ -37,21 +46,20 @@ class SemanticReleasingExecutor {
|
||||
|
||||
// check if VERSION file exists
|
||||
def versionFileExists = steps.sh(script: 'test -f "VERSION"', returnStatus: true) == 0
|
||||
def recentlyModified = false
|
||||
if (versionFileExists) {
|
||||
// check if VERSION file was modified recently (within last minute)
|
||||
def modTime = steps.sh(script: 'stat -c %Y "VERSION"', returnStdout: true).trim() as Long
|
||||
def currentTime = System.currentTimeMillis() / 1000
|
||||
recentlyModified = (currentTime - modTime) < 60
|
||||
}
|
||||
def released = false
|
||||
|
||||
def released = versionFileExists && recentlyModified
|
||||
if (versionFileExists) {
|
||||
def currentVersion = steps.readFile('VERSION').trim()
|
||||
released = !versionFileExistsBefore || (currentVersion != previousVersion)
|
||||
if (released) {
|
||||
steps.env.LATEST_VERSION = steps.readFile('VERSION').trim()
|
||||
steps.env.SEMANTIC_RELEASED = true
|
||||
steps.log.info("SemanticReleasingExecutor", "Semantic release completed, version: ${steps.env.LATEST_VERSION}")
|
||||
} else if (versionFileExists) {
|
||||
steps.log.warn("SemanticReleasingExecutor", "VERSION file exists but was not modified recently, skipping release")
|
||||
} else {
|
||||
steps.log.warn("SemanticReleasingExecutor", "No new version released, current version remains: ${currentVersion}")
|
||||
}
|
||||
} else {
|
||||
steps.log.warn("SemanticReleasingExecutor", "VERSION file not found, semantic release may have failed ?")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user