Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
49 changes: 49 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -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 <version> 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."
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading