Zack Williams | 12783ac | 2018-06-12 15:13:12 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2018-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 | # tagcollisionreject.sh |
| 18 | # checks that there isn't an existing tag in the repo that has this tag |
| 19 | |
| 20 | set -eu -o pipefail |
| 21 | |
| 22 | NEW_VERSION="" |
| 23 | |
| 24 | # find the version string in the repo, read into NEW_VERSION |
| 25 | # Add additional places NEW_VERSION could be found to this function |
| 26 | function read_version { |
| 27 | if [ -f "VERSION" ] |
| 28 | then |
| 29 | NEW_VERSION=$(head -n1 "VERSION") |
| 30 | echo "New version: $NEW_VERSION" |
| 31 | else |
| 32 | echo "ERROR: No versioning file found!" |
| 33 | exit 1 |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | # check if the version is already a tag in git |
| 38 | function is_git_tag_duplicated { |
| 39 | for existing_tag in $(git tag) |
| 40 | do |
| 41 | if [ "$NEW_VERSION" = "$existing_tag" ] |
| 42 | then |
| 43 | echo "ERROR: Duplicate tag: $existing_tag" |
| 44 | exit 2 |
| 45 | fi |
| 46 | done |
| 47 | } |
| 48 | |
| 49 | echo "Checking git repo with remotes:" |
| 50 | git remote -v |
| 51 | |
| 52 | echo "Branches:" |
| 53 | git branch -v |
| 54 | |
| 55 | echo "Existing git tags:" |
| 56 | git tag -n |
| 57 | |
| 58 | read_version |
| 59 | is_git_tag_duplicated |
| 60 | |
| 61 | exit 0 |
| 62 | |