#!/bin/sh # Build mgsh, auto-incrementing the patch version by 0.0.1 on every build. # # version.txt holds the currently built version. Each run increments the patch # component, then builds with that version injected via -ldflags, and writes it # back. So version.txt always reflects the version of the binary just built. set -e cd "$(dirname "$0")" V=$(cat version.txt 2>/dev/null || echo 4.0.0) # split MAJOR.MINOR.PATCH and increment PATCH (no carry: 4.0.9 -> 4.0.10) MAJOR=${V%%.*} REST=${V#*.} MINOR=${REST%%.*} PATCH=${REST#*.} PATCH=$((PATCH + 1)) NV="$MAJOR.$MINOR.$PATCH" go build -ldflags "-X main.VERSION=$NV" -o mgsh . echo "$NV" > version.txt echo "built mgsh v$NV"