Skip to content

Instantly share code, notes, and snippets.

@kyrsideris
Created January 29, 2021 12:27
Show Gist options
  • Save kyrsideris/fe8600bdbcb4e9750025672f0d3cca85 to your computer and use it in GitHub Desktop.
Save kyrsideris/fe8600bdbcb4e9750025672f0d3cca85 to your computer and use it in GitHub Desktop.
CI/CD logic that determines if package with python version should be uploaded to artefact repository
def checkUploadability(String branch, String version) {
Boolean isReleaseVersion = "${version}" ==~ /([0-9]+)\.([0-9]+)\.([0-9]+)/
Boolean isSnapshotVersion = "${version}" ==~ /([0-9]+)\.([0-9]+)\.([0-9]+)(\.(dev|rc)\d+){1}/
Boolean isMasterBranch = "${branch}" == "master"
Boolean isUploadable = (isReleaseVersion && isMasterBranch) || (isSnapshotVersion && !isMasterBranch)
return isUploadable;
}
BRANCH_NAME = "master"
PROJECT_VERSION = "0.1.4"
println("Is version '${PROJECT_VERSION}' on branch '${BRANCH_NAME}' uploadable: " + checkUploadability("${BRANCH_NAME}", "${PROJECT_VERSION}"))
// Is version '0.1.4' on branch 'master' uploadable: true
BRANCH_NAME = "master"
PROJECT_VERSION = "0.1.4.rc1"
println("Is version '${PROJECT_VERSION}' on branch '${BRANCH_NAME}' uploadable: " + checkUploadability("${BRANCH_NAME}", "${PROJECT_VERSION}"))
// Is version '0.1.4.rc1' on branch 'master' uploadable: false
BRANCH_NAME = "master"
PROJECT_VERSION = "0.1.4.dev1"
println("Is version '${PROJECT_VERSION}' on branch '${BRANCH_NAME}' uploadable: " + checkUploadability("${BRANCH_NAME}", "${PROJECT_VERSION}"))
// Is version '0.1.4.dev1' on branch 'master' uploadable: false
BRANCH_NAME = "develop"
PROJECT_VERSION = "0.1.4"
println("Is version '${PROJECT_VERSION}' on branch '${BRANCH_NAME}' uploadable: " + checkUploadability("${BRANCH_NAME}", "${PROJECT_VERSION}"))
// Is version '0.1.4' on branch 'develop' uploadable: false
BRANCH_NAME = "develop"
PROJECT_VERSION = "0.1.4.rc1"
println("Is version '${PROJECT_VERSION}' on branch '${BRANCH_NAME}' uploadable: " + checkUploadability("${BRANCH_NAME}", "${PROJECT_VERSION}"))
// Is version '0.1.4.rc1' on branch 'develop' uploadable: true
BRANCH_NAME = "develop"
PROJECT_VERSION = "0.1.4.dev1"
println("Is version '${PROJECT_VERSION}' on branch '${BRANCH_NAME}' uploadable: " + checkUploadability("${BRANCH_NAME}", "${PROJECT_VERSION}"))
// Is version '0.1.4.dev1' on branch 'develop' uploadable: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment