Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / FindFamily / scripts / stamp-version.sh
stamp-version.sh32 lines · 1.3 KiBRaw
| 1 | #!/usr/bin/env bash |
| 2 | # stamp-version.sh [Info.plist] |
| 3 | # Writes Modern-Apps version.txt into the app's Info.plist (in place): |
| 4 | # CFBundleVersion = line 1 (numeric code, e.g. 20261105) |
| 5 | # CFBundleShortVersionString = line 2 minus leading "v" and trailing letters (v2.6.11b -> 2.6.11), |
| 6 | # because Apple only accepts dot-separated integers. |
| 7 | # Run on a throwaway checkout (the release builder clones fresh). |
| 8 | set -euo pipefail |
| 9 | |
| 10 | HERE="$(cd "$(dirname "$0")/.." && pwd)" |
| 11 | PLIST="${1:-$HERE/FindFamilyiOS/Info.plist}" |
| 12 | VERSION_FILE="$HERE/../../version.txt" |
| 13 | |
| 14 | CODE=$(sed -n '1p' "$VERSION_FILE" | tr -d '[:space:]') |
| 15 | NAME=$(sed -n '2p' "$VERSION_FILE" | tr -d '[:space:]') |
| 16 | SHORT=$(printf '%s' "$NAME" | sed -E 's/^v//; s/[^0-9.]+$//') |
| 17 | |
| 18 | [[ "$CODE" =~ ^[0-9]+$ ]] || { echo "stamp-version: bad version code '$CODE'" >&2; exit 1; } |
| 19 | [[ "$SHORT" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]] || { echo "stamp-version: cannot map '$NAME' to an Apple version" >&2; exit 1; } |
| 20 | |
| 21 | python3 - "$PLIST" "$SHORT" "$CODE" <<'EOF' |
| 22 | import plistlib, sys |
| 23 | path, short, code = sys.argv[1:] |
| 24 | with open(path, "rb") as f: |
| 25 | info = plistlib.load(f) |
| 26 | info["CFBundleShortVersionString"] = short |
| 27 | info["CFBundleVersion"] = code |
| 28 | with open(path, "wb") as f: |
| 29 | plistlib.dump(info, f) |
| 30 | EOF |
| 31 | |
| 32 | echo "stamp-version: $SHORT ($CODE) -> $PLIST" |