mirror of
https://github.com/netbirdio/dex.git
synced 2026-05-22 18:43:53 -07:00
feat: enhance git-version script to generate pseudo-versions with timestamp (#4553)
Signed-off-by: maksim.nabokikh <max.nabokih@gmail.com>
This commit is contained in:
@@ -52,6 +52,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
fetch-tags: true
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
|
||||
@@ -90,6 +92,12 @@ jobs:
|
||||
labels: |
|
||||
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
|
||||
# See https://github.com/moby/buildkit/pull/2760
|
||||
- name: Determine build output
|
||||
@@ -124,10 +132,11 @@ jobs:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
build-args: |
|
||||
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'] }}
|
||||
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-to: type=gha,mode=max
|
||||
outputs: ${{ steps.build-output.outputs.value }}
|
||||
|
||||
+32
-4
@@ -1,14 +1,42 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
# 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
|
||||
TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true)
|
||||
# check if the current commit has a matching tag (filter for v* tags, excluding api/)
|
||||
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
|
||||
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
|
||||
VERSION=$TAG
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user