#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' Usage: bash scripts/fisher-data.sh upload Register validation/fisher with DVC and upload its data. Then print the Git commands needed to publish the manifest. download Download validation/fisher using its Git-tracked DVC manifest. status Check whether local and remote Fisher data are in sync. This helper never stages, commits, or pushes Git changes. EOF } die() { printf 'Error: %s\n' "$*" >&2 exit 2 } if [[ $# -ne 1 ]]; then usage >&2 exit 2 fi action=$1 case "$action" in upload|download|status) ;; -h|--help|help) usage; exit 0 ;; *) die "unknown action '$action' (choose upload, download, or status)" ;; esac script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) repo_root=$(cd -- "$script_dir/.." && pwd) cd "$repo_root" [[ -f .dvc/config ]] || die "run this from a cjfp-data checkout" if command -v dvc >/dev/null 2>&1; then dvc_cmd=(dvc) elif command -v uvx >/dev/null 2>&1; then dvc_cmd=(uvx --from dvc dvc) else die "DVC is not available; activate the project environment or install uv/uvx" fi manifest=validation/fisher.dvc results=validation/fisher case "$action" in upload) [[ -d "$results" ]] || die "missing $results; run the Fisher validation suite first" "${dvc_cmd[@]}" add "$results" "${dvc_cmd[@]}" push "$manifest" printf '\nFisher results uploaded to the configured DVC remote.\n' printf 'Publish the updated manifest through Git when ready:\n' printf ' git add %q %q\n' "$manifest" validation/.gitignore printf ' git commit -m %q\n' "Update Fisher validation data manifest" printf ' git push origin main\n' ;; download) [[ -f "$manifest" ]] || die "missing $manifest; first sync the manifest with Git (git pull)" "${dvc_cmd[@]}" pull "$manifest" ;; status) [[ -f "$manifest" ]] || die "missing $manifest; first sync the manifest with Git (git pull)" "${dvc_cmd[@]}" status "$manifest" "${dvc_cmd[@]}" status -c "$manifest" ;; esac