-
Notifications
You must be signed in to change notification settings - Fork 41
/
use-latest-deps-android.sh
executable file
·146 lines (116 loc) · 3.45 KB
/
use-latest-deps-android.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
print_usage () {
(>&2 echo "Usage:")
(>&2 echo " $0 [-d] github-user/repository-name")
(>&2 echo "Arguments:")
(>&2 echo " -d: do a dry-run. Don't push or send a PR.")
}
generate_dependencies_report () {
variables_passed=$#
if [ "${variables_passed}" -gt 0 ]; then
dir=$1
(>&2 echo "=========================================================================")
(>&2 echo "Push sample path to run gradle command locally (NEW PATH, PREVIOUS PATH):")
pushd "$dir"
# Generate JSON dependencies report
./gradlew dependencyUpdates -Drevision=release -DoutputFormatter=json
gradle_exit_code="$?"
(>&2 echo "Pop sample path off stack, back to original path:")
popd
return $gradle_exit_code
else
# Return invalid arguments exit code.
return 128
fi
}
update_dependencies () {
variables_passed=$#
if [ "${variables_passed}" -gt 0 ]; then
dir=$1
# Activate a virtualenv
virtualenv --python python3.8 env
# shellcheck disable=SC1091
source env/bin/activate
# Run Android fixer script
python3 "${dir}/fix_android_dependencies.py"
# Remove the virtualenv
rm -rf env
return 0
else
# Return invalid arguments exit code.
return 128
fi
}
# Use the version of Java specified in the build config
export JAVA_HOME=${KOKORO_GFILE_DIR}
export PATH="$JAVA_HOME/bin:$PATH"
# Check for optional arguments.
DRYRUN=0
while getopts :d opt; do
case $opt in
d)
(>&2 echo "Entered dry-run mode.")
DRYRUN=1
;;
\?)
(>&2 echo "Got invalid option -$OPTARG.")
print_usage
exit 1
;;
esac
done
shift $((OPTIND-1))
# Check that positional arguments are set.
if [[ -z $1 ]] ; then
(>&2 echo "Missing repo argument.")
print_usage
exit 1
fi
if [[ "$1" != *"/"* ]] ; then
(>&2 echo "Repo argument needs to be of form username/repo-name.")
print_usage
exit 1
fi
REPO=$1
# Get this script's directory.
# http://stackoverflow.com/a/246128/101923
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set +e
set -x
generate_dependencies_report "${DIR}/"
generate_dependencies_report_exit_code="$?"
# Gradle doesn't exist at root (127 means command not found), check all child folders for android/gradle projects.
if [ $generate_dependencies_report_exit_code -eq 127 ]; then
(>&2 echo "No Gradle at root of repo, go one level deeper for samples.")
# Allows us to skip the loop if there aren't any folders.
shopt -s nullglob
# Generate list of folders in current directory.
child_dirs=(*/)
for child_dir in "${child_dirs[@]}"
do
generate_dependencies_report "${DIR}/${child_dir}"
done
fi
set -e
update_dependencies "${DIR}"
# If there were any changes, test them and then push and send a PR.
if ! git diff --quiet; then
if [[ "$DRYRUN" -eq 0 ]] ; then
set -e
"${DIR}/commit-and-push.sh"
"${DIR}/send-pr.sh" "$REPO"
fi
fi