-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildRelease
executable file
·133 lines (115 loc) · 4.84 KB
/
buildRelease
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#
# Infomaniak SwissTransfer - Multiplatform
# Copyright (C) 2024 Infomaniak Network SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Variables
BOLD=$(tput bold)
END_BOLD=$(tput sgr0)
BOLD_GREEN='\033[1;32m'
COLOR_OFF='\033[0m'
# Function to check whether a string is a valid version (x.x.x)
function is_valid_version {
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
return 0
else
return 1
fi
}
# Function to display documentation
function show_help {
echo "Usage: $0 <version> [--ios | --android]"
echo " <version> The version number in the format x.x.x"
echo " --ios Release for iOS platform only"
echo " --android Release for Android platform only"
echo "Examples:"
echo " $0 1.2.3"
echo " $0 1.2.3 --ios"
echo " $0 1.2.3 --android"
}
function release_android {
echo "Releasing Android version $1"
sed -i '' "s|mavenVersionName = \".*\"|mavenVersionName = \"$1\"|g" buildTools/gradle/src/main/kotlin/com/infomaniak/gradle/utils/Versions.kt
}
function release_ios {
IOS_TAG=$1
echo "Releasing iOS version $1"
echo "Deletes all old caches"
./gradlew clean
rm -rf build # We delete to avoid caching problems
rm -rf .gradle # We delete to avoid caching problems
rm -rf release # The release folder contains the old archives
# Build
echo "Build all Modules for XCFrameworks"
./gradlew :STNetwork:assembleSTNetworkReleaseXCFramework
./gradlew :STDatabase:assembleSTDatabaseReleaseXCFramework
./gradlew :STCore:assembleSTCoreReleaseXCFramework
# Archive
echo "Archive XCFramework to ${BOLD}release${END_BOLD} folder"
mkdir -p release
zip -r release/STNetwork.xcframework.zip STNetwork/build/XCFrameworks/release/STNetwork.xcframework
zip -r release/STDatabase.xcframework.zip STDatabase/build/XCFrameworks/release/STDatabase.xcframework
zip -r release/STCore.xcframework.zip STCore/build/XCFrameworks/release/STCore.xcframework
# Calculate checksums
echo "Calculate modules checksums from release folder"
NETWORK_CHECKSUM=$(swift package compute-checksum release/STNetwork.xcframework.zip)
DATABASE_CHECKSUM=$(swift package compute-checksum release/STDatabase.xcframework.zip)
CORE_CHECKSUM=$(swift package compute-checksum release/STCore.xcframework.zip)
# Update Package.swift
echo "${BOLD}Update Package.swift${END_BOLD}"
NETWORK_URL="https://github.com/Infomaniak/multiplatform-SwissTransfer/releases/download/$IOS_TAG/STNetwork.xcframework.zip"
DATABASE_URL="https://github.com/Infomaniak/multiplatform-SwissTransfer/releases/download/$IOS_TAG/STDatabase.xcframework.zip"
CORE_URL="https://github.com/Infomaniak/multiplatform-SwissTransfer/releases/download/$IOS_TAG/STCore.xcframework.zip"
# With the `sed` command the regex doesn't work, whereas with the `perl` command it does.
perl -0777 -pi -e "s|url: \".*Network.xcframework.zip\",(\s*)checksum: \".*\"|url: \"$NETWORK_URL\",\1checksum: \"$NETWORK_CHECKSUM\"|g" Package.swift
perl -0777 -pi -e "s|url: \".*Database.xcframework.zip\",(\s*)checksum: \".*\"|url: \"$DATABASE_URL\",\1checksum: \"$DATABASE_CHECKSUM\"|g" Package.swift
perl -0777 -pi -e "s|url: \".*Core.xcframework.zip\",(\s*)checksum: \".*\"|url: \"$CORE_URL\",\1checksum: \"$CORE_CHECKSUM\"|g" Package.swift
# Upload info
echo "${BOLD_GREEN}Check the ${BOLD}release${END_BOLD} folder to see if the archives are there, then you can upload them to a github release.${COLOR_OFF}"
}
# Release Android and iOS
function release_both {
echo "Releasing both iOS and Android version $1"
release_android "$1"
release_ios "$1"
}
# Check arguments, if no arguments are supplied, the documentation is displayed
if [ $# -eq 0 ]; then
show_help
exit 1
fi
VERSION=$1
if ! is_valid_version "$VERSION"; then
echo "Error: Invalid version format. It should be x.x.x"
show_help
exit 1
fi
# No options have been provided, so release of both iOS and Android versions
if [ $# -eq 1 ]; then
release_both "$VERSION"
exit 0
fi
# An option has been provided
OPTION=$2
if [[ "$OPTION" == "--ios" ]]; then
release_ios "$VERSION"
elif [[ "$OPTION" == "--android" ]]; then
release_android "$VERSION"
else
echo "Error: Invalid option $OPTION"
show_help
exit 1
fi