Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 44 additions & 26 deletions .github/workflows/reusable-manual-update-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,58 @@ jobs:
;;
esac
else
current=$(task version:get 2>/dev/null || true)
if [ -z "${current}" ] && [ -f .version ]; then
current=$(tr -d '\n' < .version)
fi
if [ -z "${current}" ]; then
echo "Current version not found"
exit 1
fi

no_v=${current#v}
major=$(echo "${no_v}" | awk -F. '{print $1}')
minor=$(echo "${no_v}" | awk -F. '{print $2}')
patch=$(echo "${no_v}" | awk -F. '{print $3}')
if [ -z "${major}" ] || [ -z "${minor}" ] || [ -z "${patch}" ]; then
echo "Invalid current version: ${current}"
exit 1
fi
normalize_and_validate_version() {
local input="$1"
local candidate
candidate="${input#v}"
if ! printf "%s" "${candidate}" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
return 1
fi
printf "v%s" "${candidate}"
}

get_current_version() {
local current
current=$(task version:get 2>/dev/null || true)
if [ -z "${current}" ] && [ -f .version ]; then
current=$(tr -d '\n' < .version)
fi
if [ -z "${current}" ]; then
return 1
fi
normalize_and_validate_version "${current}"
}

case "${BUMP_TYPE}" in
set)
if [ -z "${INPUT_VERSION}" ]; then
echo "Missing version for type=set"
exit 1
fi
next="${INPUT_VERSION}"
;;
patch)
next="v${major}.${minor}.$((patch + 1))"
;;
minor)
next="v${major}.$((minor + 1)).0"
next=$(normalize_and_validate_version "${INPUT_VERSION}") || {
echo "Invalid explicit version: ${INPUT_VERSION}. Expected vX.Y.Z or X.Y.Z"
exit 1
}
;;
major)
next="v$((major + 1)).0.0"
patch|minor|major)
current=$(get_current_version) || {
echo "Current version not found or invalid. Expected vX.Y.Z"
exit 1
}
no_v=${current#v}
IFS='.' read -r major minor patch <<< "${no_v}"

case "${BUMP_TYPE}" in
patch)
next="v${major}.${minor}.$((patch + 1))"
;;
minor)
next="v${major}.$((minor + 1)).0"
;;
major)
next="v$((major + 1)).0.0"
;;
esac
;;
*)
echo "Unknown type: ${BUMP_TYPE}"
Expand Down
Loading