diff --git a/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy b/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy index 0c174cdd..958912e2 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy @@ -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 (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") + 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 { + 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 ?") } } }