Skip to content

Commit 7fd78c9

Browse files
author
Brandon Sneed
committed
Fixups for Amplitude
1 parent d4e988a commit 7fd78c9

File tree

6 files changed

+154
-16
lines changed

6 files changed

+154
-16
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let package = Package(
2222
.package(
2323
name: "Segment",
2424
url: "https://github.com/segmentio/analytics-swift.git",
25-
from: "1.1.1"
25+
from: "1.1.2"
2626
)
2727
],
2828
targets: [
@@ -31,9 +31,8 @@ let package = Package(
3131
.target(
3232
name: "SegmentAmplitude",
3333
dependencies: ["Segment"]),
34-
.testTarget(
35-
name: "SegmentAmplitude-Tests",
36-
dependencies: ["SegmentAmplitude"]),
34+
35+
// TESTS ARE HANDLED VIA THE EXAMPLE APP.
3736
]
3837
)
3938

Sources/SegmentAmplitude-Tests/AmplitudeSession-Tests.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

Sources/SegmentAmplitude/AmplitudeSession.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,9 @@ extension AmplitudeSession {
156156
sessionID = -1
157157
}
158158
}
159+
160+
extension AmplitudeSession: VersionedPlugin {
161+
public static func version() -> String {
162+
return __destination_version
163+
}
164+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Version.swift
3+
// Segment
4+
//
5+
// Created by Brandon Sneed on 2/24/2022.
6+
//
7+
8+
// DO NOT MODIFY THIS FILE BY HAND!!
9+
// DO NOT MODIFY THIS FILE BY HAND!!
10+
// DO NOT MODIFY THIS FILE BY HAND!!
11+
// DO NOT MODIFY THIS FILE BY HAND!!
12+
13+
// Use release.sh's automation.
14+
15+
// BREAKING.FEATURE.FIX
16+
internal let __destination_version = "1.1.2"

release.sh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/bash
2+
3+
vercomp () {
4+
if [[ $1 == $2 ]]
5+
then
6+
return 0
7+
fi
8+
local IFS=.
9+
local i ver1=($1) ver2=($2)
10+
# fill empty fields in ver1 with zeros
11+
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
12+
do
13+
ver1[i]=0
14+
done
15+
for ((i=0; i<${#ver1[@]}; i++))
16+
do
17+
if [[ -z ${ver2[i]} ]]
18+
then
19+
# fill empty fields in ver2 with zeros
20+
ver2[i]=0
21+
fi
22+
if ((10#${ver1[i]} > 10#${ver2[i]}))
23+
then
24+
return 1
25+
fi
26+
if ((10#${ver1[i]} < 10#${ver2[i]}))
27+
then
28+
return 2
29+
fi
30+
done
31+
return 0
32+
}
33+
34+
# check if `gh` tool is installed.
35+
if ! command -v gh &> /dev/null
36+
then
37+
echo "Github CLI tool is required, but could not be found."
38+
echo "Install it via: $ brew install gh"
39+
exit 1
40+
fi
41+
42+
# check if `gh` tool has auth access.
43+
# command will return non-zero if not auth'd.
44+
authd=$(gh auth status -t)
45+
if [[ $? != 0 ]]; then
46+
echo "ex: $ gh auth login"
47+
exit 1
48+
fi
49+
50+
# check that we're on the `main` branch
51+
branch=$(git rev-parse --abbrev-ref HEAD)
52+
if [ $branch != 'main' ]
53+
then
54+
echo "The 'main' must be the current branch to make a release."
55+
echo "You are currently on: $branch"
56+
exit 1
57+
fi
58+
59+
versionFile="./sources/SegmentAmplitude/Version.swift"
60+
61+
# get last line in version.swift
62+
versionLine=$(tail -n 1 $versionFile)
63+
# split at the =
64+
version=$(cut -d "=" -f2- <<< "$versionLine")
65+
# remove quotes and spaces
66+
version=$(sed "s/[' \"]//g" <<< "$version")
67+
68+
echo "$(basename $(pwd)) current version: $version"
69+
70+
# no args, so give usage.
71+
if [ $# -eq 0 ]
72+
then
73+
echo "Release automation script"
74+
echo ""
75+
echo "Usage: $ ./release.sh <version>"
76+
echo " ex: $ ./release.sh \"1.0.2\""
77+
exit 0
78+
fi
79+
80+
newVersion="${1%.*}.$((${1##*.}))"
81+
echo "Preparing to release $newVersion..."
82+
83+
vercomp $newVersion $version
84+
case $? in
85+
0) op='=';;
86+
1) op='>';;
87+
2) op='<';;
88+
esac
89+
90+
if [ $op != '>' ]
91+
then
92+
echo "New version must be greater than previous version ($version)."
93+
exit 1
94+
fi
95+
96+
read -r -p "Are you sure you want to release $newVersion? [y/N] " response
97+
case "$response" in
98+
[yY][eE][sS]|[yY])
99+
;;
100+
*)
101+
exit 1
102+
;;
103+
esac
104+
105+
# get the commits since the last release...
106+
# note: we do this here so the "Version x.x.x" commit doesn't show up in logs.
107+
changelog=$(git log --pretty=format:"- (%an) %s" $(git describe --tags --abbrev=0 @^)..@)
108+
tempFile=$(mktemp)
109+
#write changelog to temp file.
110+
echo -e "$changelog" >> $tempFile
111+
112+
# update sources/Segment/Version.swift
113+
# - remove last line...
114+
sed -i '' -e '$ d' $versionFile
115+
# - add new line w/ new version
116+
echo "internal let __destination_version = \"$newVersion\"" >> $versionFile
117+
118+
# commit the version change.
119+
git commit -am "Version $newVersion" && git push
120+
# gh release will make both the tag and the release itself.
121+
gh release create $newVersion -F $tempFile -t "Version $newVersion"
122+
123+
# remove the tempfile.
124+
rm $tempFile
125+
126+

0 commit comments

Comments
 (0)