File size: 2,172 Bytes
c7c67ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
set -euo pipefail

usage() {
    cat <<'EOF'
Usage: bash scripts/fisher-data.sh <upload|download|status>

  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