From 422aba9e69f7cf177635ca632cf97c36ed33e27d Mon Sep 17 00:00:00 2001 From: Skydust Date: Sun, 30 Mar 2025 23:45:24 +0200 Subject: [PATCH] Fixing get version same commit --- action.yml | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/action.yml b/action.yml index 93e031b..67799ac 100644 --- a/action.yml +++ b/action.yml @@ -19,29 +19,37 @@ runs: fi if [[ -n "${SEMVER_UPDATE}" ]]; then - git fetch --tags --force + log_info "Requested $(yellow)${SEMVER_UPDATE}$(reset_color) update" + git fetch --tags --force > /dev/null last_version="$(git describe --tags --abbrev=0 --match "v*" 2> /dev/null || echo "")" - if [[ -z "$last_version" ]]; then - last_version="v0.0.0" - fi - last_version="${last_version:1}" - log_info "Last version: ${last_version}" + + if git tag --points-at HEAD | grep -q "^${last_version}"; then + log_info "A tag already exists on the current commit, using it" + NEW_VERSION="${last_version:1}" + else + git fetch --tags --force --unshallow || echo "No fetch needed" + last_version="$(git describe --tags --abbrev=0 --match "v*" 2> /dev/null || echo "")" + + if [[ -z "${last_version}" ]]; then + last_version="v0.0.0" + fi + last_version="${last_version:1}" + log_info "Last version: ${last_version}" - # Split the version into components - IFS='.' read -r major minor patch <<< "${last_version%%-*}" + # Split the version into components + IFS='.' read -r major minor patch <<< "${last_version%%-*}" - # Increment the appropriate part of the version - case "${SEMVER_UPDATE}" in - "Major"*) NEW_VERSION="$((major + 1)).0.0" - ;; - "Minor"*) NEW_VERSION="$major.$((minor + 1)).0" - ;; - "Patch"*) NEW_VERSION="$major.$minor.$((patch + 1))" - ;; - esac - - log_info "Requested ${SEMVER_UPDATE} update" + # Increment the appropriate part of the version + case "${SEMVER_UPDATE}" in + "Major"*) NEW_VERSION="$((major + 1)).0.0" + ;; + "Minor"*) NEW_VERSION="$major.$((minor + 1)).0" + ;; + "Patch"*) NEW_VERSION="$major.$minor.$((patch + 1))" + ;; + esac + fi; NEW_VERSION="v${NEW_VERSION}" elif [[ "${{ github.ref }}" == refs/tags/* ]]; then