fork of https://github.com/sourcegraph/zoekt
1#!/usr/bin/env bash
2
3# This script updates the JSON schemas in this directory by cloning the
4# relevant protos from Google and gRPC, and then running protoc-gen-jsonschema
5# on them.
6
7tmpdir="$(mktemp -d)"
8function cleanup() {
9 rm -rf "$tmpdir"
10}
11
12trap cleanup EXIT
13
14cd "$(dirname "${BASH_SOURCE[0]}")"
15set -euo pipefail
16
17output_dir="$(pwd)"
18
19if ! command -v protoc-gen-jsonschema &>/dev/null; then
20 go install "github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema@latest"
21fi
22
23# Delete all existing JSON schemas.
24find . -name '*.json' -print0 | xargs -0 rm -f
25
26git_clones_dir="${tmpdir}/clones"
27
28mkdir -p "$git_clones_dir"
29cd "$git_clones_dir"
30
31function clone_at_commit() {
32 local repo="$1"
33 local commit="$2"
34 local dir="$3"
35
36 mkdir -p "$dir"
37
38 pushd "$dir"
39
40 git init
41 git remote add origin "$repo"
42 git fetch --depth 1 origin "$commit"
43 git checkout FETCH_HEAD
44
45 popd
46}
47
48# clone well-known protos from Google and gRPC protos
49clone_at_commit "git@github.com:googleapis/googleapis.git" "c959f4214cb3947aa42ded4a14610d0607fcd57a" "${git_clones_dir}/googleapis"
50clone_at_commit "git@github.com:grpc/grpc-proto.git" "6956c0ef3b8c21efb44992edc858fbae9414aa05" "${git_clones_dir}/grpc-proto"
51
52cd "$tmpdir"
53
54# prepare protos in a single directory
55cp -r "${git_clones_dir}/googleapis/google" .
56cp -r "${git_clones_dir}/grpc-proto/grpc" .
57cp "${git_clones_dir}/grpc-proto/grpc/service_config/service_config.proto" .
58
59# Generate JSON schemas from protos.
60
61protoc \
62 --jsonschema_opt=json_fieldnames \
63 --jsonschema_out="$output_dir" \
64 -I. \
65 service_config.proto