Files
davideisinger.com/bin/upgrade
2026-01-07 09:53:19 -05:00

47 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
build_file="$root_dir/.build.yml"
if ! command -v hugo >/dev/null 2>&1; then
echo "hugo not found in PATH" >&2
exit 1
fi
hugo_version_raw="$(hugo version)"
hugo_version="$(printf '%s\n' "$hugo_version_raw" | sed -E 's/^hugo v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/')"
if [[ -z "$hugo_version" || "$hugo_version" == "$hugo_version_raw" ]]; then
echo "Unable to parse hugo version from: $hugo_version_raw" >&2
exit 1
fi
current_version="$(rg -n "HUGO_VERSION:" "$build_file" | sed -E 's/.*HUGO_VERSION:[[:space:]]*//')"
if [[ -z "$current_version" ]]; then
echo "Unable to read HUGO_VERSION from $build_file" >&2
exit 1
fi
if [[ "$hugo_version" == "$current_version" ]]; then
echo "Hugo already at $hugo_version"
exit 0
fi
python3 - <<PY
from pathlib import Path
path = Path("$build_file")
data = path.read_text()
old = "$current_version"
new = "$hugo_version"
needle = f"HUGO_VERSION: {old}"
if needle not in data:
raise SystemExit("Expected HUGO_VERSION not found in .build.yml")
path.write_text(data.replace(needle, f"HUGO_VERSION: {new}", 1))
PY
git add "$build_file"
git commit -m "Upgrade Hugo to $hugo_version"
echo "Updated HUGO_VERSION from $current_version to $hugo_version"