Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 2 | |
Joey Armstrong | 25589d8 | 2024-01-02 22:31:35 -0500 | [diff] [blame] | 3 | # Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 4 | # |
| 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 Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 16 | |
| 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 | |
| 23 | set -eu -o pipefail |
| 24 | |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 25 | git status > /dev/null |
| 26 | STAGED="$(git diff-index --quiet HEAD -- || echo 'staged')" |
| 27 | UNTRACKED="$(git ls-files --exclude-standard --others)" |
| 28 | |
| 29 | if [ "$STAGED" == "staged" ] || [ "$UNTRACKED" != "" ]; then |
| 30 | echo "Please commit or ignore local changes before executing this test" |
William Kurkian | 1b65c91 | 2019-07-10 09:01:24 -0400 | [diff] [blame] | 31 | git status |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 32 | exit 1 |
| 33 | fi |
| 34 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 35 | # TODO: Move this into the make clean target for one stop shopping. |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 36 | # delete and regenerate go protos |
| 37 | rm -rf go/voltha.pb go/*/*.pb.go go_temp |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 38 | |
| 39 | echo "$0: make go-protos: ENTER" |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 40 | make go-protos |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 41 | echo "$0: make go-protos: LEAVE" |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 42 | |
| 43 | # Running git status ensures correct git diff-index picks up changes |
| 44 | git status > /dev/null |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 45 | STAGED_POST="$(git diff-index --quiet HEAD -- || echo "staged")" |
| 46 | UNTRACKED_POST="$(git ls-files --exclude-standard --others)" |
| 47 | |
| 48 | if [ "$STAGED_POST" == "staged" ] || [ "$UNTRACKED_POST" != "" ] ; then |
| 49 | echo "You have go proto build outputs that are not committed." |
| 50 | echo "Check git status and commit updated files." |
William Kurkian | 1b65c91 | 2019-07-10 09:01:24 -0400 | [diff] [blame] | 51 | git status |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 52 | exit 1 |
| 53 | else |
| 54 | echo "Test successful. All go proto build outputs are committed" |
| 55 | exit 0 |
| 56 | fi |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 57 | |
| 58 | # [EOF] |