-
Notifications
You must be signed in to change notification settings - Fork 24
/
check_version
executable file
·91 lines (76 loc) · 4.18 KB
/
check_version
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
#!/bin/bash
# Read the official version number from package.json file
PACKAGE_VERSION=`grep '"version":' ./package.json | cut -d '"' -f4`
# Read the version number from the Android Gradle build file
ANDROID_GRADLE_VERSION=`grep "versionName " ./android/app/build.gradle | cut -d '"' -f2`
# Read the version number (MARKETING_VERSION and CURRENT_PROJECT_VERSION) from the iOS project file
TEMP_IOS_VAR=`perl -n -e '/MARKETING_VERSION = (.*);/ && print "$1\n"' ./ios/HathorMobile.xcodeproj/project.pbxproj`
TEMP_IOS_PROJECT_VERSION=`perl -n -e '/CURRENT_PROJECT_VERSION = (.*);/ && print "$1\n"' ./ios/HathorMobile.xcodeproj/project.pbxproj`
# The iOS version number is repeated two times
IOS_MARKETING_VERSION_1=`echo $TEMP_IOS_VAR | awk '{print $1}'`
IOS_MARKETING_VERSION_2=`echo $TEMP_IOS_VAR | awk '{print $2}'`
IOS_PROJECT_VERSION_1=`echo $TEMP_IOS_PROJECT_VERSION | awk '{print $1}'`
IOS_PROJECT_VERSION_2=`echo $TEMP_IOS_PROJECT_VERSION | awk '{print $2}'`
# The version number from the package.json file is split into two parts
STRIPPED_PACKAGE_VERSION=$(echo $PACKAGE_VERSION| cut -d- -f1);
if [[ "$PACKAGE_VERSION" == *-* ]]; then
# If the version contains a hyphen, extract the second part as the release candidate
STRIPPED_PACKAGE_CANDIDATE=$(echo $PACKAGE_VERSION | cut -d- -f2)
else
# Otherwise, the release candidate is empty
STRIPPED_PACKAGE_CANDIDATE=""
fi
# Variables for debugging
# echo package: x${PACKAGE_VERSION}x
# echo stripped: x${STRIPPED_PACKAGE_VERSION}x
# echo stripped rc: x${STRIPPED_PACKAGE_CANDIDATE}x
# echo android: x${ANDROID_GRADLE_VERSION}x
# echo ios mv1: x${IOS_MARKETING_VERSION_1}x
# echo ios mv2: x${IOS_MARKETING_VERSION_2}x
# echo ios pv1: x${IOS_PROJECT_VERSION_1}x
# echo ios pv2: x${IOS_PROJECT_VERSION_2}x
# Initialize the error code with a success
EXITCODE=0
# Check if the version numbers from the package and Android are different
if [[ x${PACKAGE_VERSION}x != x${ANDROID_GRADLE_VERSION}x ]]; then
echo Version different in package.json \($PACKAGE_VERSION\) and android/app/build.gradle
EXITCODE=-1
fi
# Check if the version numbers from the package and iOS MARKETING_VERSION are different
if [[ x${STRIPPED_PACKAGE_VERSION}x != x${IOS_MARKETING_VERSION_1}x ]]; then
echo Version different in package.json \($PACKAGE_VERSION\) and first MARKETING_VERSION \($IOS_MARKETING_VERSION_1\) on ios/HathorMobile.xcodeproj/project.pbxproj
EXITCODE=-1
fi
if [[ x${STRIPPED_PACKAGE_VERSION}x != x${IOS_MARKETING_VERSION_2}x ]]; then
echo Version different in package.json \($PACKAGE_VERSION\) and second MARKETING_VERSION \($IOS_MARKETING_VERSION_2\) on ios/HathorMobile.xcodeproj/project.pbxproj
EXITCODE=-1
fi
# Check the format of iOS' CURRENT_PROJECT_VERSION
# If it's a release version (without hyphen in package version), it should be 1.0.X
# If it's a release candidate version (with hyphen in package version), it should be 0.rc.X, where rc is taken from package version
if [ -z "$STRIPPED_PACKAGE_CANDIDATE" ]; then
if [[ ! "$IOS_PROJECT_VERSION_1" =~ ^1\.0\.[0-9]{1,3}$ ]]; then
echo "Invalid format (expected 1.0.X) for first CURRENT_PROJECT_VERSION (${IOS_PROJECT_VERSION_1}) on ios/HathorMobile.xcodeproj/project.pbxproj"
EXITCODE=-1
fi
if [[ ! "$IOS_PROJECT_VERSION_2" =~ ^1\.0\.[0-9]{1,3}$ ]]; then
echo "Invalid format (expected 1.0.X) for second CURRENT_PROJECT_VERSION (${IOS_PROJECT_VERSION_2}) on ios/HathorMobile.xcodeproj/project.pbxproj"
EXITCODE=-1
fi
else
RCVERSION=${STRIPPED_PACKAGE_CANDIDATE//[^0-9]/}
# echo "RCVERSION: $RCVERSION"
if [[ ! "$IOS_PROJECT_VERSION_1" =~ ^0\.${RCVERSION}\.[0-9]{1,3}$ ]]; then
echo "Invalid format (expected 0.$RCVERSION.X) for first CURRENT_PROJECT_VERSION (${IOS_PROJECT_VERSION_1}) on ios/HathorMobile.xcodeproj/project.pbxproj"
EXITCODE=-1
fi
if [[ ! "$IOS_PROJECT_VERSION_2" =~ ^0\.${RCVERSION}\.[0-9]{1,3}$ ]]; then
echo "Invalid format (expected 0.$RCVERSION.X) for second CURRENT_PROJECT_VERSION (${IOS_PROJECT_VERSION_2}) on ios/HathorMobile.xcodeproj/project.pbxproj"
EXITCODE=-1
fi
fi
if [[ x${EXITCODE}x != x0x ]]; then
echo "Check version failed. Consider using 'make bump updateType=xx' to update the version"
fi
# Exit the script with the error code
exit $EXITCODE