davideisinger.com

My personal website
Log | Files | Refs | README

commit 24f43a3e70c4f5550d17c6301a7626db287aff1d
parent 1de665ff3ed2820af640eb0dc8e624e2755ac4ad
Author: David Eisinger <[email protected]>
Date:   Wed,  7 Jan 2026 09:53:19 -0500

Add Hugo upgrade script

Diffstat:
Abin/upgrade | 46++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+), 0 deletions(-)

diff --git a/bin/upgrade b/bin/upgrade @@ -0,0 +1,46 @@ +#!/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"