From 71da4fdb66cda520a0086117a651b0aafbcea426 Mon Sep 17 00:00:00 2001 From: Hituzi Ando Date: Thu, 27 Aug 2026 15:48:43 +0900 Subject: [PATCH] chore(release): add a version bump script The framework version was hard-coded in three files and had to be edited by hand, so a release could easily ship with a stale value in one of them. - Add bump_version.sh, which updates the podspec, SUK.version, and the four MARKETING_VERSION entries in the framework project. - Verify the occurrence count in each file after substitution, because sed exits successfully even when no pattern matches. - Reject a malformed version and leave the sample apps, which have their own versions, untouched. - Expose it as the version:bump npm script and document the procedure in AGENTS.md. Co-Authored-By: Claude Opus 5 --- AGENTS.md | 22 ++++++++++++++++++++++ bump_version.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100755 bump_version.sh diff --git a/AGENTS.md b/AGENTS.md index 25e6dcb..a27ced0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,6 +66,28 @@ npm run fmt:fix - Depending on the scope of the change, verify the macOS target build in addition to the iOS tests. +## Versioning + +The framework version is hard-coded in several places. Do not edit them by hand; run the script +from the repository root: + +```sh +./bump_version.sh 1.6.0 +# or +npm run version:bump -- 1.6.0 +``` + +- The script updates `SwiftyUpdateKit.podspec`, `Framework/Sources/SUK.swift`, and + `MARKETING_VERSION` in `Framework/SwiftyUpdateKit.xcodeproj/project.pbxproj`. +- It accepts `MAJOR.MINOR.PATCH` with an optional pre-release suffix, and exits with a non-zero + status when the version is malformed or when any location was not updated. +- `iOSSample/` and `MacSample/` have their own versions. The script does not change them, and + neither should you. +- After bumping, regenerate the distribution binary with `./build.sh`, then commit and tag the + release. +- When a new location for the version string is added, update `bump_version.sh` together with the + expected occurrence counts in its verification step. + ## Documentation - Update `README.md` when changing a public API or its usage. diff --git a/bump_version.sh b/bump_version.sh new file mode 100755 index 0000000..571caff --- /dev/null +++ b/bump_version.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# +# Updates the framework version in every place it is hard-coded. +# +# ./bump_version.sh 1.6.0 +# +set -eu + +VERSION="${1:-}" +if [ -z "$VERSION" ]; then + echo "usage: $0 e.g. $0 1.6.0" >&2 + exit 1 +fi + +if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$'; then + echo "error: invalid version: $VERSION" >&2 + exit 1 +fi + +cd "$(dirname "$0")" + +PODSPEC=SwiftyUpdateKit.podspec +SOURCE=Framework/Sources/SUK.swift +PBXPROJ=Framework/SwiftyUpdateKit.xcodeproj/project.pbxproj + +CURRENT=$(sed -n -E 's/^[[:space:]]*s\.version = "(.*)"/\1/p' "$PODSPEC") +echo "$CURRENT -> $VERSION" + +# BSD sed (macOS). -i '' edits in place without a backup file. +sed -i '' -E "s/^([[:space:]]*s\.version = )\".*\"/\1\"$VERSION\"/" "$PODSPEC" +sed -i '' -E "s/^([[:space:]]*public static let version = )\".*\"/\1\"$VERSION\"/" "$SOURCE" +sed -i '' -E "s/MARKETING_VERSION = .*;/MARKETING_VERSION = $VERSION;/" "$PBXPROJ" + +# sed exits 0 even when nothing matched, so verify each file actually holds the +# new version. Expected: podspec 1, SUK.swift 1, project.pbxproj 4. +verify() { + count=$(grep -c "$2" "$1" || true) + if [ "$count" -ne "$3" ]; then + echo "error: $1 has $count occurrences of $VERSION, expected $3" >&2 + exit 1 + fi +} +verify "$PODSPEC" "s\.version = \"$VERSION\"" 1 +verify "$SOURCE" "public static let version = \"$VERSION\"" 1 +verify "$PBXPROJ" "MARKETING_VERSION = $VERSION;" 4 + +git diff --stat -- "$PODSPEC" "$SOURCE" "$PBXPROJ" +echo +echo "Next: ./build.sh to regenerate the XCFramework, then commit and tag $VERSION." diff --git a/package.json b/package.json index 54a590f..5aa1673 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "scripts": { "prepare": "./prepare.sh", "fmt:install": "./codeformat.sh --install", - "fmt:fix": "./codeformat.sh --fix" + "fmt:fix": "./codeformat.sh --fix", + "version:bump": "./bump_version.sh" }, "volta": { "node": "18.14.2",