|
| 1 | +#!/bin/bash -xe |
| 2 | + |
| 3 | +# Copyright 2022 The Kubernetes Authors. |
| 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 | +VERSION=$(cat version.txt) |
| 18 | + |
| 19 | +if [[ ! "${VERSION}" =~ ^([0-9]+[.][0-9]+)[.]([0-9]+)(-(alpha|beta)[.]([0-9]+))?$ ]]; then |
| 20 | + echo "Version ${VERSION} must be 'X.Y.Z', 'X.Y.Z-alpha.N', or 'X.Y.Z-beta.N'" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +BRANCH=$(git branch --show-current) |
| 25 | + |
| 26 | +if [[ ! "${BRANCH}" =~ ^(release-)([0-9]+[.][0-9]+)$ ]]; then |
| 27 | + echo "Automatic tag creation must take place on a release branch." |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +BRANCH_MAJ_MIN=${BRANCH#release-} |
| 32 | +VERSION_MAJ_MIN=$(echo ${VERSION} | sed -Ee 's/-(alpha|beta)\.[0-9]+$//' | sed -Ee 's/\.[0-9]+$//') |
| 33 | + |
| 34 | +if [[ ! "${BRANCH_MAJ_MIN}" = $VERSION_MAJ_MIN ]]; then |
| 35 | + echo "Major minor version of tag must match major minor version of branch." |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +if [ "$(git tag -l "v${VERSION}")" ]; then |
| 40 | + echo "Tag v${VERSION} already exists" |
| 41 | + exit 0 |
| 42 | +fi |
| 43 | + |
| 44 | +git tag -a -m "Release ${VERSION}" "v${VERSION}" |
| 45 | +git push origin "v${VERSION}" |
0 commit comments