-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck-version.sh
More file actions
executable file
·73 lines (56 loc) · 2.08 KB
/
Copy pathcheck-version.sh
File metadata and controls
executable file
·73 lines (56 loc) · 2.08 KB
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
72
73
#!/bin/bash
set -euo pipefail
# scripts/check-version.sh
# Verify cfg-update, README.md, and ebuild PV agree (no git required).
# Usage: ./scripts/check-version.sh [EXPECTED_VERSION]
EXPECTED="${1:-}"
die() { echo "Error: $*" >&2; exit 1; }
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$REPO_ROOT"
CFG_VERSION=$(perl -ne 'print $1 if /^ my \$version\s+=\s+"([^"]+)"/' cfg-update)
README_VERSION=$(perl -ne 'print $1 if /^\*\*Version:\*\* (.+)/' README.md)
mapfile -t EBUILDS < <(ls gentoo/cfg-update-*.ebuild 2>/dev/null | sort -V || true)
EBUILD_COUNT=${#EBUILDS[@]}
if (( EBUILD_COUNT > 1 )); then
die "Expected exactly one gentoo/cfg-update-*.ebuild, found $EBUILD_COUNT: ${EBUILDS[*]}"
fi
EBUILD_VERSION=""
if (( EBUILD_COUNT == 1 )); then
EBUILD_BASENAME=$(basename "${EBUILDS[0]}")
if [[ "$EBUILD_BASENAME" =~ ^cfg-update-([0-9]+\.[0-9]+\.[0-9]+)\.ebuild$ ]]; then
EBUILD_VERSION="${BASH_REMATCH[1]}"
else
die "Cannot parse PV from ebuild filename: $EBUILD_BASENAME"
fi
fi
if [[ -z "$CFG_VERSION" ]]; then
die "Could not read \$version from cfg-update"
fi
if [[ -z "$README_VERSION" ]]; then
die "Could not read **Version:** from README.md"
fi
TARGET="$EXPECTED"
if [[ -z "$TARGET" ]]; then
TARGET="$CFG_VERSION"
fi
if ! [[ "$TARGET" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
die "Version must look like X.Y.Z (got '$TARGET')"
fi
MISMATCH=0
report_mismatch() {
local label="$1" actual="$2"
echo "Mismatch: $label has \"$actual\" (expected $TARGET)" >&2
MISMATCH=1
}
[[ "$CFG_VERSION" == "$TARGET" ]] || report_mismatch 'cfg-update \$version' "$CFG_VERSION"
[[ "$README_VERSION" == "$TARGET" ]] || report_mismatch 'README.md **Version:**' "$README_VERSION"
if (( EBUILD_COUNT == 1 )); then
[[ "$EBUILD_VERSION" == "$TARGET" ]] || report_mismatch 'ebuild PV' "$EBUILD_VERSION"
else
echo "Warning: no ebuild in gentoo/ — skipped ebuild PV check" >&2
fi
if (( MISMATCH )); then
die "Version check failed"
fi
echo "Version check passed: cfg-update, README.md, and ebuild all at $TARGET"