Skip to main content

Versioning tools for CI

Project description

Versioning tools for CI

project-version

Provides version environment variables to CI builds.

Example output
$ cat VERSION
0.2.7

$ project-version --version-source-file VERSION --dev-nr 12345 env-vars
VERSION_SEMVER=0.2.7-dev.12345
VERSION_SEMVER_MAJOR=0
VERSION_SEMVER_MINOR=0.2
VERSION_IS_PRE_RELEASE=1

$ project-version --version-source-file VERSION --dev-nr 12345 --git-tag v0.2.7 env-vars
VERSION_SEMVER=0.2.7
VERSION_SEMVER_MAJOR=0
VERSION_SEMVER_MINOR=0.2
VERSION_IS_RELEASE=1
VERSION_IS_LATEST_RELEASE=1

$ git checkout v0.2.6
Note: switching to 'v0.2.6'.

$ cat VERSION
0.2.6

$ project-version --version-source-file VERSION --dev-nr 12345 --git-tag v0.2.6 env-vars
VERSION_SEMVER=0.2.6
VERSION_SEMVER_MAJOR=0
VERSION_SEMVER_MINOR=0.2
VERSION_IS_RELEASE=1

$ project-version --version-source-file VERSION --dev-nr 12345 --git-tag v9.9.9 env-vars
ERROR:ci_version_tools.project:Version 0.2.7 in the version source does not match the version 9.9.9 in the Git tag

$ echo $?
1

Example application in .gitlab-cy.yml:

version:
  image: docker.io/alikov/ci-version-tools:0.1.0
  stage: .pre
  script:
    - project-version
        --version-source-file ./VERSION
        --git-version-tag-prefix v
        --dev-identifier dev
        --dev-nr "${CI_PIPELINE_IID:-0}"
        ${CI_COMMIT_TAG:+--git-tag "$CI_COMMIT_TAG"} | tee version.env
  artifacts:
    reports:
      dotenv:
        - version.env

.build-image:
  stage: build
  image: $BUILDAH_CI_IMAGE
  script:
    - IMAGE="${CI_REGISTRY_IMAGE}:${VERSION_SEMVER}"
    - buildah build -t "$IMAGE" .
    - buildah push "$IMAGE"
    - '[ -z "$VERSION_IS_RELEASE" ]
        || buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:${VERSION_SEMVER_MAJOR}"'
    - '[ -z "$VERSION_IS_RELEASE" ]
        || buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:${VERSION_SEMVER_MINOR}"'
    - '[ -z "$VERSION_IS_LATEST_RELEASE" ]
        || buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:latest"'
  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_MAJOR=3
ALPINE_VERSION_MINOR=3.20
TERRAFORM_VERSION_MAJOR=1

Example application in .gitlab-cy.yml:

variables:
  ALPINE_VERSION: "3.20.2"
  TERRAFORM_VERSION: "1.9.3"

tool-versions:
  image: docker.io/alikov/ci-version-tools:0.1.0
  stage: .pre
  script:
    - version-env-vars parse ALPINE_VERSION TERRAFORM_VERSION | tee tool-versions.env
  artifacts:
    reports:
      dotenv:
        - tool-versions.env

.build-image:
  stage: build
  image: $BUILDAH_CI_IMAGE
  script:
    - IMAGE="${CI_REGISTRY_IMAGE}:${VERSION_SEMVER}"
    - buildah build
        --build-arg "BASE_IMAGE=alpine:${ALPINE_VERSION}"
        --build-arg "DOWNLOAD_TERRAFORM_VERSION=${TERRAFORM_VERSION}"
        -t "$IMAGE"
        .
    - buildah inspect "$IMAGE"
    - buildah push "$IMAGE"
    - '[ -z "$VERSION_IS_RELEASE" ]
        || buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:alpine-${ALPINE_VERSION_MINOR}"'
    - '[ -z "$VERSION_IS_RELEASE" ]
        || buildah push "$IMAGE" "${CI_REGISTRY_IMAGE}:terraform-${TERRAFORM_VERSION_MINOR}"'
  needs:
    - version
    - tool-versions

Developing

See DEVELOPING.md for local development setup instructions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ci_version_tools-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

ci_version_tools-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file ci_version_tools-0.1.0.tar.gz.

File metadata

  • Download URL: ci_version_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.6.31-linuxkit

File hashes

Hashes for ci_version_tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d6ffba2ec90d5c02fe0a2545671993254acbda3c520b7be549132fdd35520237
MD5 51a2c48baa031cda180b38745d14ef46
BLAKE2b-256 94e37048f4264c29a56a4cff6179859fc61c89016f4f4a4d5faaab306fe6d7b8

See more details on using hashes here.

File details

Details for the file ci_version_tools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ci_version_tools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.6.31-linuxkit

File hashes

Hashes for ci_version_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30007ed6a7be030156e0ade7dcb1844c52cfa46c71d40f794ae6cfc333a6526e
MD5 dbef8d2fb617ef128472514ddf82a146
BLAKE2b-256 9ca3df91c1e1e567f12e0be37323a57b70c6d1d22e7af0afe5ba08140a58381e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page