blob: 4067d5334bc20470e29ccb71a28d052bbba05e37 [file] [log] [blame]
Zack Williams43bfd9e2019-04-12 13:09:31 -07001#!/usr/bin/env bash
William Kurkianad745652019-03-20 08:45:51 -04002
Joey Armstronge6cdd8e2022-12-29 11:58:15 -05003# Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
William Kurkianad745652019-03-20 08:45:51 -04004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Zack Williams43bfd9e2019-04-12 13:09:31 -070016
17# test-go-proto-consistency.sh
18#
19# This test validates that go proto outputs are committed to git. It does this
20# by regenerating them and validating whether git thinks they are the same. If
21# they become out of sync, there can be problems for consumers of the protos.
22
23set -eu -o pipefail
24
William Kurkianad745652019-03-20 08:45:51 -040025git status > /dev/null
26STAGED="$(git diff-index --quiet HEAD -- || echo 'staged')"
27UNTRACKED="$(git ls-files --exclude-standard --others)"
28
29if [ "$STAGED" == "staged" ] || [ "$UNTRACKED" != "" ]; then
30 echo "Please commit or ignore local changes before executing this test"
William Kurkian1b65c912019-07-10 09:01:24 -040031 git status
William Kurkianad745652019-03-20 08:45:51 -040032 exit 1
33fi
34
Zack Williams43bfd9e2019-04-12 13:09:31 -070035# delete and regenerate go protos
36rm -rf go/voltha.pb go/*/*.pb.go go_temp
William Kurkianad745652019-03-20 08:45:51 -040037make go-protos
38
39# Running git status ensures correct git diff-index picks up changes
40git status > /dev/null
William Kurkianad745652019-03-20 08:45:51 -040041STAGED_POST="$(git diff-index --quiet HEAD -- || echo "staged")"
42UNTRACKED_POST="$(git ls-files --exclude-standard --others)"
43
44if [ "$STAGED_POST" == "staged" ] || [ "$UNTRACKED_POST" != "" ] ; then
45 echo "You have go proto build outputs that are not committed."
46 echo "Check git status and commit updated files."
William Kurkian1b65c912019-07-10 09:01:24 -040047 git status
William Kurkianad745652019-03-20 08:45:51 -040048 exit 1
49else
50 echo "Test successful. All go proto build outputs are committed"
51 exit 0
52fi