Skip to content
Draft
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
113 changes: 111 additions & 2 deletions scripts/fhir_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,110 @@ function igtools_version() {
fi
}

function check_pytool_version() {
local package_name="$1"
local repo_url="$2"
local current_version=""
local latest_version=""
local response=""

# Handle missing parameters gracefully
if [[ -z "$package_name" || -z "$repo_url" ]]; then
echo "error:missing_parameters"
return 0
fi

# Get current version from pipx
current_version=$(sudo pipx list --global --short 2>/dev/null | awk -v pkg="$package_name" '$1 == pkg {print $2}') || true

if [[ -z "$current_version" ]]; then
echo "not_installed"
return 0
fi

# Try to fetch latest version from GitHub with 1s timeout
response=$(curl -s --connect-timeout 1 --max-time 1 "$repo_url" 2>/dev/null || true)

if [[ -z "$response" ]]; then
echo "error:fetch_failed_or_timeout:${current_version}"
return 0
fi

# Try to find versions from filenames (dist/*.tar.gz, *.whl)
latest_version=$(echo "$response" \
| grep -Eo "${package_name}-[0-9]+(\.[0-9]+){1,2}(\.tar\.gz|\.whl)" \
| sort -V \
| tail -n 1 \
| grep -Eo '[0-9]+(\.[0-9]+){1,2}' || true)

# If not found, try to extract from __VERSION__ in source code listing
if [[ -z "$latest_version" ]]; then
latest_version=$(echo "$response" \
| grep -Eo "__VERSION__\s*=\s*['\"][0-9]+(\.[0-9]+){1,2}['\"]" \
| sed -E "s/.*__VERSION__\s*=\s*['\"]([^'\"]+)['\"].*/\1/" \
| sort -V \
| tail -n 1 || true)
fi

if [[ -z "$latest_version" ]]; then
echo "error:could_not_parse_latest_version:${current_version}"
return 0
fi

# Compare installed vs. latest
if [[ "$current_version" == "$latest_version" ]]; then
echo "up_to_date:${current_version}"
else
echo "update_available:${current_version}:${latest_version}"
fi

return 0
}

function maintain_pytools() {
echo "Checking epatools version"
result=$(check_pytool_version epatools "https://api.github.com/repos/onyg/epa-tools/contents/dist")
IFS=':' read -r status current latest <<< "$result"

case "$status" in
update_available)
echo "⬆️ $package_name: $current → $latest"
update_pytool "git+https://github.com/onyg/epa-tools.git" "Updated epa-tools to $(epatools_version)" "Failed to update epa-tools"
;;
up_to_date)
echo "✅ $package_name up to date ($current)"
;;
error*)
echo "⚠️ $package_name check failed ($status)"
;;
not_installed)
echo "📦 $package_name not installed"
update_pytool "git+https://github.com/onyg/epa-tools.git" "Updated epa-tools to $(epatools_version)" "Failed to update epa-tools"
;;
esac

echo "Checking igtools version"
result=$(check_pytool_version igtools "https://raw.githubusercontent.com/onyg/req-tooling/main/src/igtools/version.py")
IFS=':' read -r status current latest <<< "$result"

case "$status" in
update_available)
echo "⬆️ $package_name: $current → $latest"
update_pytool "git+https://github.com/onyg/req-tooling.git" "Upated reqtooling to $(igtools_version)" "Failed to update req-tooling"
;;
up_to_date)
echo "✅ $package_name up to date ($current)"
;;
error*)
echo "⚠️ $package_name check failed ($status)"
;;
not_installed)
echo "📦 $package_name not installed"
update_pytool "git+https://github.com/onyg/req-tooling.git" "Upated reqtooling to $(igtools_version)" "Failed to update req-tooling"
;;
esac
}

function update_pytools() {
update_pytool "git+https://github.com/onyg/epa-tools.git" "Updated epa-tools to $(epatools_version)" "Failed to update epa-tools"
update_pytool "git+https://github.com/onyg/req-tooling.git" "Upated reqtooling to $(igtools_version)" "Failed to update req-tooling"
Expand Down Expand Up @@ -529,11 +633,16 @@ case "$1" in

case "$choice" in
1)
maintain_pytools
build_definitions
build_ig
;;
2) build_definitions ;;
3) build_ig ;;
2)
maintain_pytools
build_definitions ;;
3)
maintain_pytools
build_ig ;;
0) exit 0 ;;
*) echo "Invalid option." ;;
esac
Expand Down