forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_hard_coded_version.sh
More file actions
executable file
·48 lines (42 loc) · 1.93 KB
/
check_hard_coded_version.sh
File metadata and controls
executable file
·48 lines (42 loc) · 1.93 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
#!/bin/bash
set -e
# This script checks to make sure that if LIBRARY_VERSION is hard coded, it is set
# to match the version in pubspec.yaml. This allows plugins to report their version
# for analytics purposes. See https://github.com/flutter/flutter/issues/32267
# So that users can run this script from anywhere and it will work as expected.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
source "$SCRIPT_DIR/common.sh"
function check_hard_coded_version() {
local failures=()
for package_name in "$@"; do
local dir="$REPO_DIR/packages/$package_name"
echo "Checking that $package_name has the correct hard coded version, if any."
PACKAGE_VERSION="$(cd "$dir" && cat pubspec.yaml | grep -E "^version: " | awk '{print $2}')"
IOS_VERSION="$(cd "$dir" && grep -r "#define LIBRARY_VERSION" ios/Classes/*.m | awk '{print $3}')"
ANDROID_VERSION="$(cd "$dir" && grep -r LIBRARY_VERSION android/src/main/java/* | awk '{print $8}')"
if [[ "$IOS_VERSION" == "" && "$ANDROID_VERSION" == "" ]]; then
echo "No hard coded version found"
elif [[ "$IOS_VERSION" == "@\"$PACKAGE_VERSION\"" && "$ANDROID_VERSION" == "\"$PACKAGE_VERSION\";" ]]; then
echo "Hard coded version matched: $PACKAGE_VERSION"
else
error "Hard coded version check failed for $package_name"
error "pubspec.yaml version: $PACKAGE_VERSION"
error "Android version: $ANDROID_VERSION"
error "iOS version: $IOS_VERSION"
failures=("${failures[@]}" "$package_name")
fi
done
if [[ "${#failures[@]}" != 0 ]]; then
error "FAIL: The following ${#failures[@]} package(s) failed the hard coded version check:"
for failure in "${failures[@]}"; do
error "$failure"
done
fi
return "${#failures[@]}"
}
# Sets CHANGED_PACKAGE_LIST
check_changed_packages
if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then
check_hard_coded_version "${CHANGED_PACKAGE_LIST[@]}"
fi