Browse Source

feat: enhance git-version script to generate pseudo-versions with timestamp (#4553)

Signed-off-by: maksim.nabokikh <max.nabokih@gmail.com>
pull/4323/merge
Maksim Nabokikh 4 weeks ago committed by GitHub
parent
commit
955142bae2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      .github/workflows/artifacts.yaml
  2. 36
      scripts/git-version

13
.github/workflows/artifacts.yaml

@ -52,6 +52,8 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-tags: true
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0 uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
@ -90,6 +92,12 @@ jobs:
labels: | labels: |
org.opencontainers.image.documentation=https://dexidp.io/docs/ org.opencontainers.image.documentation=https://dexidp.io/docs/
# Multiple exporters are not supported yet
# See https://github.com/moby/buildkit/pull/2760
- name: Get version from git-version script
id: version
run: echo "value=$(bash ./scripts/git-version)" >> "$GITHUB_OUTPUT"
# Multiple exporters are not supported yet # Multiple exporters are not supported yet
# See https://github.com/moby/buildkit/pull/2760 # See https://github.com/moby/buildkit/pull/2760
- name: Determine build output - name: Determine build output
@ -124,10 +132,11 @@ jobs:
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
build-args: | build-args: |
BASE_IMAGE=${{ matrix.variant }} BASE_IMAGE=${{ matrix.variant }}
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} VERSION=${{ steps.version.outputs.value }}
COMMIT_HASH=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} COMMIT_HASH=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
BUILD_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} BUILD_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
labels: ${{ steps.meta.outputs.labels }} labels: |
${{ steps.meta.outputs.labels }}
# cache-from: type=gha # cache-from: type=gha
# cache-to: type=gha,mode=max # cache-to: type=gha,mode=max
outputs: ${{ steps.build-output.outputs.value }} outputs: ${{ steps.build-output.outputs.value }}

36
scripts/git-version

@ -1,14 +1,42 @@
#!/bin/sh -e #!/bin/sh -e
# parse the current git commit hash # parse the current git commit hash
COMMIT=`git rev-parse HEAD` COMMIT=`git rev-parse --short=8 HEAD`
# check if the current commit has a matching tag # check if the current commit has a matching tag (filter for v* tags, excluding api/)
TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true) TAG=$(git describe --exact-match --abbrev=0 --tags --match="v[0-9]*" 2> /dev/null || true)
# use the matching tag as the version, if available # use the matching tag as the version, if available
if [ -z "$TAG" ]; then if [ -z "$TAG" ]; then
VERSION=$COMMIT # No exact tag on current commit, find the last version tag and bump minor version
# Get all tags matching v[0-9]*, sort them, and take the last one
LAST_TAG=$(git tag --list "v[0-9]*" --sort=-version:refname | head -1)
if [ -z "$LAST_TAG" ]; then
# No tags found, use v0.1.0 as fallback
BASE_VERSION="v0.1.0"
else
# Parse the last tag and bump minor version
# Remove 'v' prefix
TAG_WITHOUT_V="${LAST_TAG#v}"
# Split version into parts (major.minor.patch)
MAJOR=$(echo "$TAG_WITHOUT_V" | cut -d. -f1)
MINOR=$(echo "$TAG_WITHOUT_V" | cut -d. -f2)
PATCH=$(echo "$TAG_WITHOUT_V" | cut -d. -f3)
# Bump minor version
MINOR=$((MINOR + 1))
# Construct base version with bumped minor
BASE_VERSION="v${MAJOR}.${MINOR}.0"
fi
# Get commit timestamp in YYYYMMDDhhmmss format
TIMESTAMP=$(git log -1 --format=%ci HEAD | sed 's/[-: ]//g' | cut -c1-14)
# Construct pseudo-version
VERSION="${BASE_VERSION}-${TIMESTAMP}-${COMMIT}"
else else
VERSION=$TAG VERSION=$TAG
fi fi

Loading…
Cancel
Save