This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
update-proto.sh
executable file
·58 lines (50 loc) · 1.66 KB
/
update-proto.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
#!/bin/sh
set -e
function update_proto {
usage="Usage: $0 remote repo branch folder"
remote="${1:?No remote specified
$usage}"
repo="${2:?No repo specified
$usage}"
branch="${3:?No branch specified
$usage}"
folder="${4:?No folder specified
$usage}"
git remote add -f -t main --no-tags "$remote" "$repo" 2>/dev/null ||
git fetch "$remote"
git rm -rf "proto/${folder:?}" 2>&1 >/dev/null || true
git read-tree --prefix="proto/$folder" -u "$remote/$branch:$folder"
find "proto/$folder" -type f -and -not -name '*.proto' -exec \
git rm -f {} \; 2>&1 >/dev/null
}
function find_dependencies {
xargs -n1 grep 'import "' |
sed 's@^.*"\(.*\)".*$@\1@' |
grep -v 'google/protobuf/' |
sort -u
}
function find_all_dependencies {
all_deps="$(cat | sort -u)"
deps="$all_deps"
while true; do
deps="$(echo "$deps" | find_dependencies)"
next_all_deps="$(echo "$all_deps\n$deps" | sort -u)"
[ "$all_deps" != "$next_all_deps" ] || break
all_deps="$next_all_deps"
done
echo "$all_deps"
}
update_proto authzed https://github.com/authzed/api.git main authzed
update_proto api-common-protos \
https://github.com/googleapis/api-common-protos.git main google
update_proto protoc-gen-validate \
https://github.com/envoyproxy/protoc-gen-validate.git main validate
update_proto protoc-gen-openapiv2 \
https://github.com/grpc-ecosystem/grpc-gateway.git \
master protoc-gen-openapiv2/options
cd "$(dirname "$0")/proto"
find authzed -name '*.proto' |
find_all_dependencies |
sed 's@^@-not\n-path\n*/@' |
xargs find . -type f |
xargs git rm -f 2>&1 >/dev/null