uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2020-present Open Networking Foundation. |
| 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. |
| 16 | |
| 17 | # test-python-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 | |
| 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" |
| 31 | git status |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | # delete and regenerate python protos |
uwe ottrembka | 5ea5c0a | 2020-08-31 10:37:35 +0200 | [diff] [blame] | 36 | rm -rf python/dmi/* |
uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 37 | make python-protos |
| 38 | |
| 39 | # Running git status ensures correct git diff-index picks up changes |
| 40 | git status > /dev/null |
| 41 | STAGED_POST="$(git diff-index --quiet HEAD -- || echo "staged")" |
| 42 | UNTRACKED_POST="$(git ls-files --exclude-standard --others)" |
| 43 | |
| 44 | if [ "$STAGED_POST" == "staged" ] || [ "$UNTRACKED_POST" != "" ] ; then |
| 45 | echo "You have python proto build outputs that are not committed." |
| 46 | echo "Check git status and commit updated files." |
| 47 | git status |
| 48 | exit 1 |
| 49 | else |
| 50 | echo "Test successful. All python proto build outputs are committed" |
| 51 | exit 0 |
| 52 | fi |