fix: allow manual set version in non-action repos#47
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the reusable manual version-bump workflow so repos using non-actions profiles can run in set mode without requiring an existing “current version” (e.g., missing .version).
Changes:
- Moves “current version required” logic to only the
patch/minor/majorbump paths for non-actionsprofiles. - Allows
setto directly write the requested version to.versionfor non-actionsprofiles.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 |
There was a problem hiding this comment.
The current-version discovery + parsing block is duplicated in the patch, minor, and major branches. This makes future changes (e.g., supporting prerelease versions or improving validation) error-prone since it must be updated in 3 places. Consider extracting this into a small helper (shell function) or doing the current-version lookup/parsing once before the case (guarded so it only runs for patch/minor/major).
There was a problem hiding this comment.
Good catch. Refactored this block to remove duplication: added helper functions normalize_and_validate_version and get_current_version, and consolidated patch|minor|major into a single path that computes parsed version components once.
| 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 | ||
| next="v${major}.${minor}.$((patch + 1))" |
There was a problem hiding this comment.
Version parsing here uses awk -F. which relies on awk field-splitting behavior for .; in other parts of the repo the dot is escaped (-F\.), which is more explicit/portable. Also, the validation only checks for non-empty fields; if patch/minor are non-numeric (e.g., v1.2.3-alpha) the later arithmetic expansion will fail. Recommend validating the full version format (e.g., ^v?[0-9]+\.[0-9]+\.[0-9]+$) and/or splitting using shell (IFS=. / read) instead of multiple echo|awk calls.
There was a problem hiding this comment.
Implemented. Replaced repeated awk parsing with explicit validation and shell split:
- validate versions with regex (
^v?[0-9]+\.[0-9]+\.[0-9]+$) - normalize to
vX.Y.Z - parse once via
IFS=. read -r major minor patch
This now rejects prerelease/non-numeric formats before arithmetic expansion.
Summary
other,static,dockerized) do not require a pre-existing current version when bump type issetpatch,minor, andmajormodes.githubmeta repository release workflow from failing withCurrent version not foundduring manual setWhy
The meta repo does not always have a pre-existing
.versionat runtime, sosetmode should initialize version state directly instead of depending on current-version discovery.