-
Notifications
You must be signed in to change notification settings - Fork 5
🧹 Refactor: Extract duplicated version classification logic into shared helper #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/usr/bin/env bash | ||
| # Classifies an idstack version string as "skip" (modern), "legacy", or "unknown". | ||
| # Used by setup, bin/idstack-doctor, and test/test-version-classifier.sh. | ||
|
|
||
| case "${1:-}" in | ||
| 2.0.[1-9]*|2.[1-9]*|[3-9]*|[1-9][0-9]*) echo "skip" ;; | ||
| 0.*|1.*|2.0.0.*|2.0.0) echo "legacy" ;; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version Adding Please also consider adding |
||
| *) echo "unknown" ;; | ||
| esac | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,14 +92,12 @@ elif [ -d "$LEGACY_SKILLS_LINK" ] && [ "$LEGACY_SKILLS_LINK" != "$IDSTACK_DIR" ] | |
| legacy_is_old_version=0 | ||
| if [ -f "$LEGACY_SKILLS_LINK/VERSION" ]; then | ||
| legacy_version=$(tr -d '[:space:]' < "$LEGACY_SKILLS_LINK/VERSION") | ||
| # Two arms: explicitly skip modern/future versions first, then flag the | ||
| # legacy ones. Patterns avoid literal dots and single-digit ranges so | ||
| # multi-digit components (2.0.10.0, 2.10.0.0, 20.x, 100.0.0, 200.0.0) | ||
| # work. Covered by test/test-version-classifier.sh. | ||
| case "$legacy_version" in | ||
| 2.0.[1-9]*|2.[1-9]*|[3-9]*|[1-9][0-9]*) ;; | ||
| 0.*|1.*|2.0.0.*|2.0.0) legacy_is_old_version=1 ;; | ||
| esac | ||
| # Uses shared classifier to identify pre-v2.0.1.0 versions. Covered by | ||
| # test/test-version-classifier.sh. | ||
| class=$("$IDSTACK_DIR/bin/idstack-version-classifier" "$legacy_version") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Executing the helper script directly relies on the file having the executable permission bit set. Since Invoking the script with |
||
| if [ "$class" = "legacy" ]; then | ||
| legacy_is_old_version=1 | ||
| fi | ||
| fi | ||
| if [ "$legacy_is_dispatcher" = "1" ] || [ "$legacy_is_old_version" = "1" ]; then | ||
| if [[ " $* " == *" --keep-legacy "* ]]; then | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,26 +16,18 @@ | |
|
|
||
| set -e | ||
|
|
||
| IDSTACK_DIR="$(cd "$(dirname "$0")/.." && pwd -P)" | ||
|
|
||
| PASS=0 | ||
| FAIL=0 | ||
| TOTAL=0 | ||
|
|
||
| # Mirror of the case statement in setup and bin/idstack-doctor. Keep these | ||
| # patterns in lockstep with both files — if you change one, change all three. | ||
| classify_version() { | ||
| case "$1" in | ||
| 2.0.[1-9]*|2.[1-9]*|[3-9]*|[1-9][0-9]*) echo "skip" ;; | ||
| 0.*|1.*|2.0.0.*|2.0.0) echo "legacy" ;; | ||
| *) echo "unknown" ;; | ||
| esac | ||
| } | ||
|
|
||
| check() { | ||
| TOTAL=$((TOTAL + 1)) | ||
| local version="$1" | ||
| local expected="$2" | ||
| local got | ||
| got="$(classify_version "$version")" | ||
| got="$("$IDSTACK_DIR/bin/idstack-version-classifier" "$version")" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if [ "$got" = "$expected" ]; then | ||
| PASS=$((PASS + 1)) | ||
| echo " PASS: $version -> $got" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Executing the helper script directly relies on the file having the executable permission bit set (
chmod +x). In some environments (e.g., Windows/WSL, or when files are transferred/cloned with certain git configurations), the executable bit can be lost, leading to a "Permission denied" error.Invoking the script with
bashis more robust and avoids permission issues.