-
Notifications
You must be signed in to change notification settings - Fork 57
/
gen.sh
executable file
·66 lines (51 loc) · 1.5 KB
/
gen.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
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the Apache v2.0 license.
# Script that handles regenerating protobuf files.
# Make sure the script exits on first failure and returns the
# proper exit code to the shell.
set -e
while getopts "c" flag
do
case "${flag}" in
c) checkGeneratedFiles=1;;
esac
done
# Get script's directory.
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
cd $SCRIPTPATH
# Create directory for build files.
mkdir -p ./bld/gen
PROTOC_VER=3.11.4
PROTOC_FILE=protoc-$PROTOC_VER-linux-x86_64.zip
PROTOC_FILE_PATH=bld/$PROTOC_FILE
# Check if protoc tool has already been downloaded.
if [ ! -f $PROTOC_FILE_PATH ]; then
# Download protoc tool.
(cd bld && curl -OL https://github.com/google/protobuf/releases/download/v$PROTOC_VER/$PROTOC_FILE)
fi
# Unzip protoc tool.
unzip -o $PROTOC_FILE_PATH -d bld/protoc
GOPATH=$(go env GOPATH)
(
export PATH=$GOPATH/bin:$SCRIPTPATH/bld/protoc/bin:$SCRIPTPATH/bld/protoc/include:$PATH
# Generate the .go files from the .proto files.
cd rpc
/bin/bash ./gen_proto.sh
)
# Copy generated .go files into repo.
cp -rf ./bld/gen/github.com/microsoft/moc/rpc/* rpc/
# Cleanup.
rm -rf ./bld/gen/
go mod tidy
if [[ $checkGeneratedFiles ]]; then
# Check if any files have changed.
changed=$(git status --short)
if [[ $changed ]]; then
# Report warning.
printf "\n\n##vso[task.logissue type=warning]Generated files are different:\n\n"
# Log the diff.
git --no-pager diff
fi
fi