-
Notifications
You must be signed in to change notification settings - Fork 48
/
extract-versions.sh
executable file
·104 lines (79 loc) · 3.47 KB
/
extract-versions.sh
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
#!/bin/bash
set -o pipefail
# THE JSON path for outputs
json_file_write_path=$1
# Update pod repo to ensure we retrieve the latest version.
echo "Updating pods..."
pod repo list
pod repo add cocoapods "https://github.com/CocoaPods/Specs.git"
pod repo update
pod spec which FirebaseFirestoreInternal
# Should be removed once the podspec is updated.
PODSPEC_FILE=$(pod spec which FirebaseFirestoreInternal)
# Extract Firebase Firestore version
firebase_firestore_version=$(python3 -c 'import json; data = json.load(open("'"$PODSPEC_FILE"'")); print(data["version"])')
# Extract gRPC version
firebase_firestore_grpc_version=$(python3 -c 'import json; data = json.load(open("'"$PODSPEC_FILE"'")); print(data["dependencies"]["gRPC-C++"][0].replace("~> ", ""))')
# If the gRPC version is 1.65.0, set it to 1.65.1
# Since the tag is missing for 1.65.0.
if [ "$firebase_firestore_grpc_version" = "1.65.0" ]; then
echo "Overriding gRPC version to 1.65.1"
firebase_firestore_grpc_version="1.65.1"
fi
# Extract leveldb version
firebase_firestore_leveldb_version=$(python3 -c 'import json; data = json.load(open("'"$PODSPEC_FILE"'")); print(data["dependencies"]["leveldb-library"][0])')
# Extract nanopb minimum version
firebase_firestore_nanopb_version=$(python3 -c 'import json; data = json.load(open("'"$PODSPEC_FILE"'")); print(data["dependencies"]["nanopb"][0])')
# URL of the grpc binary Package.swift file
grpc_binary_swift_url="https://raw.githubusercontent.com/google/grpc-binary/$firebase_firestore_grpc_version/Package.swift"
# Fetch the Package.swift file
echo "Fetching Package.swift file from $grpc_binary_swift_url"
package_swift=$(curl -s $grpc_binary_swift_url)
# Check if the fetch was successful
if [[ -z $package_swift ]]; then
echo "Failed to fetch the Package.swift grpc binary file."
exit 1
fi
# Capture the line with the version range for abseil
version_line=$(echo "$package_swift" | grep -o '".*\.\.<.*"')
# Check if the version line was captured
if [[ -z $version_line ]]; then
echo "Failed to capture the version line."
exit 1
fi
# Extract the first part of the version
firebase_firestore_abseil_version=$(echo "$version_line" | awk -F\" '{print $2}' | head -1)
# Check if the versions were extracted
if [[ -z $firebase_firestore_abseil_version ]]; then
echo "Failed to extract the Firebase Firestore Abseil version."
exit 1
fi
if [ -z "$firebase_firestore_version" ]; then
echo "Failed to extract Firebase Firestore version from podspec."
exit 1
fi
if [ -z "$firebase_firestore_grpc_version" ]; then
echo "Failed to extract Firebase Firestore gRPC version from podspec."
exit 1
fi
if [ -z "$firebase_firestore_leveldb_version" ]; then
echo "Failed to extract Firebase Firestore leveldb version from podspec."
exit 1
fi
if [ -z "$firebase_firestore_nanopb_version" ]; then
echo "Failed to extract Firebase Firestore nanopb version from podspec."
exit 1
fi
# Write to a temporary JSON file for reading in the next step
# Ensure the tmp directory exists
mkdir -p ./tmp
# Output the variables in JSON format to a local temporary file. filename is passed as first argument.
cat <<EOF > $json_file_write_path
{
"firebase_firestore_version": "$firebase_firestore_version",
"firebase_firestore_grpc_version": "$firebase_firestore_grpc_version",
"firebase_firestore_leveldb_version": "$firebase_firestore_leveldb_version",
"firebase_firestore_nanopb_version": "$firebase_firestore_nanopb_version",
"firebase_firestore_abseil_version": "$firebase_firestore_abseil_version"
}
EOF