This container exposes a calculate_semver
script that will automatically calculate the next incremental semantic version for a GitHub repository by analyzing the existing releases and the labels on pull requests closed since.
Expected Labels on Pull Requests:
patch
minor
major
To use, run the container with your github repository mounted to it (or using the docker.inside
functionality in Jenkins) and just run calculate_semver
. It will simply output the next semantic version that should be used. Non-master branches will generate a "build" tag, formatted as VERSION-BRANCH.SHORTHASH
.
** Jenkins Example: **
withCredentials([usernamePassword(credentialsId: '<your_github_credentials_id>', passwordVariable: 'GH_TOKEN', usernameVariable: 'GH_USER')]) {
withEnv(['GH_ORG=<your_github_org>', 'GH_REPO=<your_github_repo>']) {
docker.image('laiello/automatic-semver:latest').inside('-u 0') {
checkout scm
NEXT_VERSION = sh (
script: 'calculate_semver',
returnStdout: true
).trim()
}
}
}
Note: If using Jenkins, ensure that Fetch Tags
is enabled.
** Human Defined: **
GH_ORG
- GitHub OrganizationGH_REPO
- GitHub RepositoryGH_TOKEN
- Used for reading the repository details
** Jenkins Provided: **
BRANCH_NAME
- Used in calculating the version (anything other than master gets a build version)GIT_COMMIT
- Used in calculating build versions (automatically shortened to eight characters)