Skip to content

Commit 10011a8

Browse files
Automate SDK update (#40)
1 parent 05962d0 commit 10011a8

File tree

5 files changed

+216
-5
lines changed

5 files changed

+216
-5
lines changed

Diff for: .justfile

+113-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,121 @@
1-
alias r := release
21
alias d := docs
2+
alias pt := push-tag
3+
alias r := release
4+
alias us := update-sdk
5+
alias usa := update-sdk-android
6+
alias usal := update-sdk-android-latest
7+
alias usi := update-sdk-ios
8+
alias usil := update-sdk-ios-latest
9+
alias usl := update-sdk-latest
10+
alias v := version
11+
12+
# Source: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
13+
# \ are escaped
14+
SEMVER_REGEX := "(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?"
15+
16+
docs: lint
17+
dart doc
18+
cp -R doc/api/ docs
19+
rm -r doc
20+
21+
latest-android:
22+
@curl -s https://s3-us-west-2.amazonaws.com/m2.hypertrack.com/com/hypertrack/sdk-android/maven-metadata-sdk-android.xml | grep latest | grep -o -E '{{SEMVER_REGEX}}' | head -n 1
23+
24+
latest-ios:
25+
@curl -s https://cocoapods.org/pods/HyperTrack | grep -m 1 -o -E "HyperTrack <span>{{SEMVER_REGEX}}" | grep -o -E '{{SEMVER_REGEX}}' | head -n 1
326

427
lint:
528
ktlint --format .
629

30+
push-tag:
31+
#!/usr/bin/env sh
32+
if [ $(git symbolic-ref --short HEAD) = "master" ] ; then
33+
VERSION = $(just version)
34+
git tag $VERSION
35+
git push origin $VERSION
36+
else
37+
echo "You are not on master branch"
38+
fi
39+
740
release: docs
841
flutter pub publish --dry-run
942

10-
docs: lint
11-
dart doc
12-
cp -R doc/api/ docs
13-
rm -r doc
43+
update-sdk-latest wrapper_version commit="true" branch="true":
44+
#!/usr/bin/env sh
45+
LATEST_IOS=$(just latest-ios)
46+
LATEST_ANDROID=$(just latest-android)
47+
just update-sdk {{wrapper_version}} $LATEST_IOS $LATEST_ANDROID {{commit}} {{branch}}
48+
49+
update-sdk-android-latest wrapper_version commit="true" branch="true":
50+
#!/usr/bin/env sh
51+
LATEST_ANDROID=$(just latest-android)
52+
just update-sdk-android {{wrapper_version}} $LATEST_ANDROID {{commit}} {{branch}}
53+
54+
update-sdk-ios-latest wrapper_version commit="true" branch="true":
55+
#!/usr/bin/env sh
56+
LATEST_IOS=$(just latest-ios)
57+
just update-sdk-ios {{wrapper_version}} $LATEST_IOS {{commit}} {{branch}}
58+
59+
update-sdk wrapper_version ios_version android_version commit="true" branch="true":
60+
#!/usr/bin/env sh
61+
if [ "{{branch}}" = "true" ] ; then
62+
git checkout -b update-sdk-ios-{{ios_version}}-android-{{android_version}}
63+
fi
64+
just version
65+
echo "New version is {{wrapper_version}}"
66+
just update-wrapper-version-file {{wrapper_version}}
67+
./scripts/update_changelog.sh -w {{wrapper_version}} -i {{ios_version}} -a {{android_version}}
68+
echo "Updating HyperTrack SDK iOS to {{ios_version}}"
69+
just update-sdk-ios-version-file {{ios_version}}
70+
echo "Updating HyperTrack SDK Android to {{android_version}}"
71+
just update-sdk-android-version-file {{android_version}}
72+
just docs
73+
if [ "{{commit}}" = "true" ] ; then
74+
git add .
75+
git commit -m "Update HyperTrack SDK iOS to {{ios_version}} and Android to {{android_version}}"
76+
fi
77+
78+
update-sdk-android wrapper_version android_version commit="true" branch="true":
79+
#!/usr/bin/env sh
80+
if [ "{{branch}}" = "true" ] ; then
81+
git checkout -b update-sdk-android-{{android_version}}
82+
fi
83+
just version
84+
echo "Updating HyperTrack SDK Android to {{android_version}} on {{wrapper_version}}"
85+
just update-wrapper-version-file {{wrapper_version}}
86+
just update-sdk-android-version-file {{android_version}}
87+
./scripts/update_changelog.sh -w {{wrapper_version}} -a {{android_version}}
88+
just docs
89+
if [ "{{commit}}" = "true" ] ; then
90+
git add .
91+
git commit -m "Update HyperTrack SDK Android to {{android_version}}"
92+
fi
93+
94+
update-sdk-ios wrapper_version ios_version commit="true" branch="true":
95+
#!/usr/bin/env sh
96+
if [ "{{branch}}" = "true" ] ; then
97+
git checkout -b update-sdk-ios-{{ios_version}}
98+
fi
99+
just version
100+
echo "Updating HyperTrack SDK iOS to {{ios_version}} on {{wrapper_version}}"
101+
just update-wrapper-version-file {{wrapper_version}}
102+
just update-sdk-ios-version-file {{ios_version}}
103+
./scripts/update_changelog.sh -w {{wrapper_version}} -i {{ios_version}}
104+
just docs
105+
if [ "{{commit}}" = "true" ] ; then
106+
git add .
107+
git commit -m "Update HyperTrack SDK iOS to {{ios_version}}"
108+
fi
109+
110+
update-sdk-android-version-file android_version:
111+
./scripts/update_file.sh android/build.gradle 'def hyperTrackVersion = \".*\"' 'def hyperTrackVersion = \"{{android_version}}\"'
112+
113+
update-sdk-ios-version-file ios_version:
114+
./scripts/update_file.sh ios/hypertrack_plugin.podspec "'HyperTrack', '.*'" "'HyperTrack', '{{ios_version}}'"
115+
116+
update-wrapper-version-file wrapper_version:
117+
./scripts/update_file.sh pubspec.yaml 'version: .*' 'version: {{wrapper_version}}'
118+
./scripts/update_file.sh ios/hypertrack_plugin.podspec "s.version = '.*'" "s.version = '{{wrapper_version}}'"
119+
120+
version:
121+
@cat pubspec.yaml | grep version | grep -o -E '{{SEMVER_REGEX}}'

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
242242

243243
- Initial release.
244244

245+
[2.0.0]: https://github.com/hypertrack/sdk-flutter/releases/tag/2.0.0
246+
245247
[1.1.3]: https://github.com/hypertrack/sdk-flutter/releases/tag/1.1.3
246248

247249
[1.1.2]: https://github.com/hypertrack/sdk-flutter/releases/tag/1.1.2

Diff for: CONTRIBUTING.md

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
### How to update the HyperTrack SDK version and make a release?
66

7+
#### Automated:
8+
9+
1. `just usl <new wrapper version>` (or `just usal` for Android only, `just usil` for iOS only) will:
10+
- update the SDK to the latest version
11+
- update the wrapper version
12+
- update the CHANGELOG
13+
- create a branch
14+
- update docs
15+
- commit changes
16+
2. Push the branch and create a PR
17+
3. Merge the PR
18+
4. `just pt` on master will push a tag with the version
19+
5. Create a GitHub release with the tag
20+
6. `flutter pub publish`
21+
22+
#### Manual:
23+
724
1. Update SDK version
825

926
- android

Diff for: scripts/update_changelog.sh

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
while [ "$#" -gt 0 ]; do
4+
case "$1" in
5+
-w)
6+
wrapper_version="$2"
7+
shift 2
8+
;;
9+
-i)
10+
ios_version="$2"
11+
shift 2
12+
;;
13+
-a)
14+
android_version="$2"
15+
shift 2
16+
;;
17+
*)
18+
echo "Usage: $0 [-w wrapper_version] [-i ios_version] [-a android_version]"
19+
exit 1
20+
;;
21+
esac
22+
done
23+
24+
file="CHANGELOG.md"
25+
26+
if [ ! -f "$file" ]; then
27+
echo "Error: $file not found."
28+
exit 1
29+
fi
30+
31+
if [ -z "$wrapper_version" ]; then
32+
echo "Error: wrapper_version is required."
33+
exit 1
34+
fi
35+
36+
date=$(date +%Y-%m-%d)
37+
38+
sed -i '' -e "245 i\\
39+
" CHANGELOG.md
40+
sed -i '' -e "245 i\\
41+
[$wrapper_version]: https://github.com/hypertrack/sdk-flutter/releases/tag/$wrapper_version" CHANGELOG.md
42+
43+
sed -i '' -e "6 i\\
44+
" CHANGELOG.md
45+
sed -i '' -e "6 i\\
46+
## [$wrapper_version] - $date" CHANGELOG.md
47+
sed -i '' -e "7 i\\
48+
" CHANGELOG.md
49+
sed -i '' -e "8 i\\
50+
### Changed" CHANGELOG.md
51+
sed -i '' -e "9 i\\
52+
" CHANGELOG.md
53+
54+
if [ -n "$android_version" ]; then
55+
sed -i '' -e "10 i\\
56+
- Updated HyperTrack SDK Android to $android_version" CHANGELOG.md
57+
fi
58+
59+
if [ -n "$ios_version" ]; then
60+
sed -i '' -e "10 i\\
61+
- Updated HyperTrack SDK iOS to $ios_version" CHANGELOG.md
62+
fi

Diff for: scripts/update_file.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Check if params are provided
4+
if [ $# -ne 3 ]; then
5+
echo "Usage: $0 <file> <source_text> <new_text>"
6+
exit 1
7+
fi
8+
9+
file="$1"
10+
source_text="$2"
11+
new_text="$3"
12+
13+
if [ ! -f "$file" ]; then
14+
echo "Error: $file not found."
15+
exit 1
16+
fi
17+
18+
cat $file | sed "s/$source_text/$new_text/" >tmp
19+
cat tmp >$file
20+
rm -f tmp
21+
22+
echo "Updated $source_text in $file to $new_text"

0 commit comments

Comments
 (0)