Versioning tools for CI
Project description
Versioning tools for CI
project-version
Provides version environment variables to CI builds.
Example output
$ git tag
v0.1.3
v0.1.4
v0.2.0
v0.3.0
$ cat VERSION
0.3.0
$ project-version --version-source file --version-source-file VERSION env-vars
VERSION_SEMVER=0.3.0
VERSION_MAJOR=0
VERSION_MINOR=3
VERSION_PATCH=0
VERSION_MAJOR_MINOR=0.3
VERSION_WITHOUT_BUILD_METADATA=0.3.0
VERSION_IS_RELEASE=1
VERSION_IS_LATEST_RELEASE=1
$ git checkout v0.1.4
$ cat VERSION
0.1.4
$ project-version --version-source file --version-source-file VERSION env-vars
VERSION_SEMVER=0.1.4
VERSION_MAJOR=0
VERSION_MINOR=1
VERSION_PATCH=4
VERSION_MAJOR_MINOR=0.1
VERSION_WITHOUT_BUILD_METADATA=0.1.4
VERSION_IS_RELEASE=1
$ project-version --version-source file --version-source-file VERSION --git-tag v0.1.3 env-vars
ERROR:ci_version_tools.project:Project version 0.1.5 in does not match the version 0.1.3 in the Git tag.
$ echo 0.3.0 >VERSION
$ project-version --version-source file --version-source-file VERSION env-vars
ERROR:ci_version_tools.project:Version 0.3.0 has been released on a different commit already. Increment the version to a next pre-release to fix this error.
$ echo 0.2.0-rc.1 >VERSION
$ project-version --version-source file --version-source-file VERSION env-vars
ERROR:ci_version_tools.project:Version 0.2.0-rc.1 targets 0.2.0 which has been released already. Increment the version to fix this error.
$ echo 0.4.0-rc.1+deadbeef >VERSION
$ project-version --version-source file --version-source-file VERSION env-vars
VERSION_SEMVER=0.4.0-rc.1+deadbeef
VERSION_MAJOR=0
VERSION_MINOR=4
VERSION_PATCH=0
VERSION_MAJOR_MINOR=0.4
VERSION_WITHOUT_BUILD_METADATA=0.4.0-rc.1
VERSION_PRE_RELEASE=rc.1
VERSION_IS_PRE_RELEASE=1
VERSION_BUILD_METADATA=deadbeef
$ echo 0.4.0 >VERSION
$ project-version --version-source file --version-source-file VERSION --git-tag v0.4.0 env-vars
ERROR:ci_version_tools.project:Release tag v0.4.0 does not exist in git.
Example application in .gitlab-ci.yml:
version:
image: docker.io/alikov/ci-version-tools:0.2.0
stage: .pre
variables:
GIT_DEPTH: 0
script:
- project-version
--version-source-file ./VERSION
--git-version-tag-prefix v
${CI_COMMIT_TAG:+--git-tag "$CI_COMMIT_TAG"}
env-vars | tee version.env
artifacts:
reports:
dotenv: version.env
.build-image:
stage: build
image: $BUILDAH_CI_IMAGE
script:
- IMAGE="${CI_REGISTRY_IMAGE}:${VERSION_WITHOUT_BUILD_METADATA}"
- buildah build -t "$IMAGE" .
- buildah push "$IMAGE"
- if [ -n "${VERSION_IS_RELEASE:-}" ]; then
buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:${VERSION_MAJOR}";
buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:${VERSION_MAJOR_MINOR}";
fi
- if [ -n "${VERSION_IS_LATEST_RELEASE:-}" ]; then
buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:latest";
fi
needs:
- version
version-env-vars
Parses environment variables containing semantic versions into major/minor variants.
Example output
$ export ALPINE_VERSION=3.20.2
$ export TERRAFORM_VERSION=1.9.3
$ version-env-vars parse ALPINE_VERSION TERRAFORM_VERSION
ALPINE_VERSION_SEMVER=3.20.2
ALPINE_VERSION_MAJOR=3
ALPINE_VERSION_MINOR=20
ALPINE_VERSION_PATCH=2
ALPINE_VERSION_MAJOR_MINOR=3.20
ALPINE_VERSION_WITHOUT_BUILD_METADATA=3.20.2
ALPINE_VERSION_IS_RELEASE=1
TERRAFORM_VERSION_SEMVER=1.9.3
TERRAFORM_VERSION_MAJOR=1
TERRAFORM_VERSION_MINOR=9
TERRAFORM_VERSION_PATCH=3
TERRAFORM_VERSION_MAJOR_MINOR=1.9
TERRAFORM_VERSION_WITHOUT_BUILD_METADATA=1.9.3
TERRAFORM_VERSION_IS_RELEASE=1
Example application in .gitlab-cy.yml:
variables:
ALPINE_VERSION: "3.20.2"
TERRAFORM_VERSION: "1.9.3"
# https://support.gitlab.com/hc/en-us/articles/18085676898588-Dotenv-variables-exceed-default-limit-in-GitLab-pipelinestool-versions:
image: docker.io/alikov/ci-version-tools:0.2.0
stage: .pre
parallel:
matrix:
- VAR_NAME: ALPINE_VERSION
- VAR_NAME: TERRAFORM_VERSION
script:
- version-env-vars parse ALPINE_VERSION TERRAFORM_VERSION | tee "${VAR_NAME}.env"
artifacts:
reports:
dotenv: "${VAR_NAME}.env"
.build-image:
stage: build
image: $BUILDAH_CI_IMAGE
script:
- IMAGE="${CI_REGISTRY_IMAGE}:${VERSION_WITHOUT_BUILD_METADATA}"
- buildah build
--build-arg "BASE_IMAGE=alpine:${ALPINE_VERSION}"
--build-arg "DOWNLOAD_TERRAFORM_VERSION=${TERRAFORM_VERSION}"
-t "$IMAGE"
.
- buildah inspect "$IMAGE"
- buildah push "$IMAGE"
- if [ -n "${VERSION_IS_RELEASE:-}" ]; then
buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:alpine-${ALPINE_VERSION_MAJOR_MINOR}";
buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:terraform-${TERRAFORM_VERSION_MAJOR_MINOR}";
fi
needs:
- version
- tool-versions
Developing
See DEVELOPING.md for local development setup instructions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ci_version_tools-0.2.6.tar.gz.
File metadata
- Download URL: ci_version_tools-0.2.6.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.3 Linux/6.12.5-100.fc40.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f57fa800e1bcd61dbc3314641929212a3a72ebb99a1adbdaa1c3f23da34c6f7
|
|
| MD5 |
5e44200295afac5aab1acedff5ad37ca
|
|
| BLAKE2b-256 |
5102cb6b3e087f54ae709df30bb5494255ed4ccf2159194e8eb3a2b8d1d390f7
|
File details
Details for the file ci_version_tools-0.2.6-py3-none-any.whl.
File metadata
- Download URL: ci_version_tools-0.2.6-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.3 Linux/6.12.5-100.fc40.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dafb1ee92a47bc8cdcf9db68f98ca0c7d91416a5ecb4fb6184b48943c560393d
|
|
| MD5 |
3be89aec4ab344180def68d36fb75eb4
|
|
| BLAKE2b-256 |
aafeea6c603f3342aa4c75e9aa5d1ed20f266b59ebf17a360f9b2b9797ca8cd3
|