From dd551ab1ce327efb14d3d22d1decbe90417861ed Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Mon, 27 May 2024 09:28:37 -0700 Subject: [PATCH] Refine version extraction from tag Depending on if we have commits afterwards or not, make sure the 'v' prefix is handled correctly. --- .github/workflows/ci.yml | 7 ++++--- scripts/create-workspace-status.sh | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f7c6da..e15ee9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -199,9 +199,10 @@ jobs: bazel-bin/bant/bant -V # Print version # Version number: current tag dot number of commits after tagging. + # If at exactly a tag, that will be left as-is VERSION=$(git describe --match=v* 2>/dev/null \ - | sed 's/v\([^-]*\)-\([0-9]*\).*/\1-\2/') - OUT=bant-v${VERSION}-x86 + | sed 's/v\([^-]*\)-\([0-9]*\)-.*/v\1-\2/') + OUT=bant-${VERSION}-x86 echo "OUT=${OUT}" >> $GITHUB_ENV mkdir -p "${OUT}/bin" @@ -226,7 +227,7 @@ jobs: contents: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/create-workspace-status.sh b/scripts/create-workspace-status.sh index 571ba6d..2635a85 100755 --- a/scripts/create-workspace-status.sh +++ b/scripts/create-workspace-status.sh @@ -3,14 +3,15 @@ version_from_git() { set -o pipefail git describe --match=v* 2>/dev/null \ - | sed 's/v\([^-]*\)-\([0-9]*\).*/\1-\2/' 2>/dev/null + | sed 's/v\([^-]*\)-\([0-9]*\).*/\1-\2/' \ + | sed 's/^v//' } version_from_module_bazel() { awk '/module/ { in_module=1; } /version/ { if (in_module) print $0; } /)/ { in_module=0; }' $(dirname $0)/../MODULE.bazel \ - | sed 's/.*version[ ]*=[ ]*"\([0-9.]*\)".*/\1/p;d' + | sed 's/.*version[ ]*=[ ]*"\([0-9.]*\)".*/\1/p;d' } # Get version from git including everything since last tag, but if that is