-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbump-version.sh
More file actions
executable file
·116 lines (92 loc) · 4.59 KB
/
bump-version.sh
File metadata and controls
executable file
·116 lines (92 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
# bump-version.sh - Update SDK version across all files in the repository
#
# Usage:
# ./bump-version.sh [version]
#
# If version is not provided, the script will prompt for it.
set -e
# File paths
VERSION_SWIFT="Sources/KlaviyoCore/Utils/Version.swift"
# Extract current version from Version.swift
currentVersion=$(grep '__klaviyoSwiftVersion' "$VERSION_SWIFT" | sed 's/.*"\(.*\)"/\1/')
if [[ -z "$currentVersion" ]]; then
echo "Error: Could not extract current version from $VERSION_SWIFT"
exit 1
fi
# Get new version from argument or prompt
if [[ -z "$1" ]]; then
echo "Current version: $currentVersion"
read -rp "Enter new version: " newVersion
else
newVersion="$1"
fi
# Validate input
if [[ -z "$newVersion" ]]; then
echo "Error: Version cannot be empty"
exit 1
fi
if [[ "$newVersion" == "$currentVersion" ]]; then
echo "Version is already $currentVersion - nothing to do"
exit 0
fi
echo "Bumping version: $currentVersion -> $newVersion"
echo ""
# 1. Update Version.swift
echo "Updating $VERSION_SWIFT..."
sed -i '' "s/__klaviyoSwiftVersion = \"$currentVersion\"/__klaviyoSwiftVersion = \"$newVersion\"/" "$VERSION_SWIFT"
# 2. Update podspecs
echo "Updating podspecs..."
# KlaviyoCore.podspec - version only
sed -i '' "s/s.version = \"$currentVersion\"/s.version = \"$newVersion\"/" "KlaviyoCore.podspec"
# KlaviyoSwift.podspec - version and dependency
sed -i '' "s/s.version = \"$currentVersion\"/s.version = \"$newVersion\"/" "KlaviyoSwift.podspec"
sed -i '' "s/'KlaviyoCore', '~> $currentVersion'/'KlaviyoCore', '~> $newVersion'/" "KlaviyoSwift.podspec"
# KlaviyoForms.podspec - version and dependency
sed -i '' "s/s.version = \"$currentVersion\"/s.version = \"$newVersion\"/" "KlaviyoForms.podspec"
sed -i '' "s/'KlaviyoSwift', '~> $currentVersion'/'KlaviyoSwift', '~> $newVersion'/" "KlaviyoForms.podspec"
# KlaviyoSwiftExtension.podspec - version only
sed -i '' "s/s.version = \"$currentVersion\"/s.version = \"$newVersion\"/" "KlaviyoSwiftExtension.podspec"
# KlaviyoLocation.podspec - version and dependency
sed -i '' "s/s.version = \"$currentVersion\"/s.version = \"$newVersion\"/" "KlaviyoLocation.podspec"
sed -i '' "s/'KlaviyoSwift', '~> $currentVersion'/'KlaviyoSwift', '~> $newVersion'/" "KlaviyoLocation.podspec"
# 3. Update test files/snapshots with hardcoded versions
echo "Updating test files..."
# NetworkSessionTests.swift
sed -i '' "s/klaviyo-swift\/$currentVersion/klaviyo-swift\/$newVersion/g" "Tests/KlaviyoCoreTests/NetworkSessionTests.swift"
echo "Updating test snapshots..."
for snapshot in \
"Tests/KlaviyoCoreTests/__Snapshots__/EncodableTests/testEventPayload.1.json" \
"Tests/KlaviyoCoreTests/__Snapshots__/EncodableTests/testKlaviyoRequest.1.json" \
"Tests/KlaviyoCoreTests/__Snapshots__/EncodableTests/testTokenPayload.1.json" \
"Tests/KlaviyoCoreTests/__Snapshots__/NetworkSessionTests/testCreateEmphemeralSesionHeaders.1.txt" \
"Tests/KlaviyoCoreTests/__Snapshots__/NetworkSessionTests/testDefaultUserAgent.1.txt" \
"Tests/KlaviyoSwiftTests/__Snapshots__/EncodableTests/testKlaviyoState.1.json" \
"Tests/KlaviyoSwiftTests/__Snapshots__/KlaviyoStateTests/testValidStateFileExists.1.txt"
do
if [[ -f "$snapshot" ]]; then
sed -i '' "s/$currentVersion/$newVersion/g" "$snapshot"
fi
done
# 4. Update example app Podfile
EXAMPLE_PODFILE="Examples/KlaviyoSwiftExamples/CocoapodsExample/Podfile"
if [[ -f "$EXAMPLE_PODFILE" ]]; then
echo "Updating $EXAMPLE_PODFILE..."
# Update version-pinned pod references
sed -i '' "s/'KlaviyoSwift', '$currentVersion'/'KlaviyoSwift', '$newVersion'/g" "$EXAMPLE_PODFILE"
sed -i '' "s/'KlaviyoForms', '$currentVersion'/'KlaviyoForms', '$newVersion'/g" "$EXAMPLE_PODFILE"
sed -i '' "s/'KlaviyoSwiftExtension', '$currentVersion'/'KlaviyoSwiftExtension', '$newVersion'/g" "$EXAMPLE_PODFILE"
sed -i '' "s/'KlaviyoLocation', '$currentVersion'/'KlaviyoLocation', '$newVersion'/g" "$EXAMPLE_PODFILE"
fi
# 5. Update example app project marketing versions
echo "Updating example app project versions..."
COCOAPODS_PROJECT="Examples/KlaviyoSwiftExamples/CocoapodsExample/CocoapodsExample.xcodeproj/project.pbxproj"
if [[ -f "$COCOAPODS_PROJECT" ]]; then
sed -i '' "s/MARKETING_VERSION = $currentVersion;/MARKETING_VERSION = $newVersion;/g" "$COCOAPODS_PROJECT"
fi
SPM_PROJECT="Examples/KlaviyoSwiftExamples/SPMExample/SPMExample.xcodeproj/project.pbxproj"
if [[ -f "$SPM_PROJECT" ]]; then
sed -i '' "s/MARKETING_VERSION = $currentVersion;/MARKETING_VERSION = $newVersion;/g" "$SPM_PROJECT"
fi
echo ""
echo "✅ Version bumped from $currentVersion to $newVersion"