From c717685d84f891881a8b944edcf7cfe05fbe3828 Mon Sep 17 00:00:00 2001 From: Chris Banks Date: Wed, 6 Mar 2024 12:36:46 +0000 Subject: [PATCH] Fetch latest release tag more robustly. The previous implementation failed when it encountered two or more release tags at the same commit. Make it robust to that edge case. Also saves an unnecessary deep fetch from remote. This time, avoid implicitly enabling `-o pipefail` by specifying `shell: bash`. We don't want to error out on SIGPIPE, because `| head` relies on it. --- .github/workflows/release.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3becc7cf4..be408c5f5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,12 +19,13 @@ jobs: - name: Find latest version tag id: find-last-tag run: | - git fetch --tags --deepen=100 + last_tag=$( + git ls-remote -q --exit-code --tags --sort=-version:refname origin 'v*' | + head -1 | grep -Eo 'v[0-9]+' + ) - last_tag=$(git describe --tags --match "v*" --abbrev=0) - - if [ -z "$last_tag" ]; then - echo "No previous tag found." + if [[ ! "$last_tag" =~ ^v[0-9]*$ ]]; then + echo "No valid previous tag found. last_tag=$last_tag" exit 1 fi