github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/tools/tag_release.sh (about) 1 #!/bin/bash 2 3 # Copyright 2019 The gVisor 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 # This script will optionally map a PiperOrigin-RevId to a given commit, 18 # validate a provided release name, create a tag and push it. It must be 19 # run manually when a release is created. 20 21 set -xeuo pipefail 22 23 # Check arguments. 24 if [[ "$#" -ne 3 ]]; then 25 echo "usage: $0 <commit|revid> <release.rc> <message-file>" 26 exit 1 27 fi 28 29 declare -r target_commit="$1" 30 declare -r release="$2" 31 declare -r message_file="$3" 32 33 if [[ -z "${target_commit}" ]]; then 34 echo "error: <commit|revid> is empty." 35 fi 36 if [[ -z "${release}" ]]; then 37 echo "error: <release.rc> is empty." 38 fi 39 if ! [[ -r "${message_file}" ]]; then 40 echo "error: message file '${message_file}' is not readable." 41 exit 1 42 fi 43 44 closest_commit() { 45 while read line; do 46 if [[ "$line" =~ ^"commit " ]]; then 47 current_commit="${line#commit }" 48 continue 49 elif [[ "$line" =~ "PiperOrigin-RevId: " ]]; then 50 revid="${line#PiperOrigin-RevId: }" 51 [[ "${revid}" -le "$1" ]] && break 52 fi 53 done 54 echo "${current_commit}" 55 } 56 57 # Is the passed identifier a sha commit? 58 if ! git show "${target_commit}" &> /dev/null; then 59 # Extract the commit given a piper ID. 60 commit="$(set +o pipefail; \ 61 git log --first-parent | closest_commit "${target_commit}")" 62 declare -r commit 63 else 64 declare -r commit="${target_commit}" 65 fi 66 if ! git show "${commit}" &> /dev/null; then 67 echo "unknown commit: ${target_commit}" 68 exit 1 69 fi 70 71 # Is the release name sane? Must be a date with patch/rc. 72 if ! [[ "${release}" =~ ^20[0-9]{6}\.[0-9]+$ ]]; then 73 declare -r expected="$(date +%Y%m%d.0)" # Use today's date. 74 echo "unexpected release format: ${release}" 75 echo " ... expected like ${expected}" 76 exit 1 77 fi 78 79 # Tag the given commit (annotated, to record the committer). Note that the tag 80 # here is applied as a force, in case the tag already exists and is the same. 81 # The push will fail in this case (because it is not forced). 82 declare -r tag="release-${release}" 83 git tag -f -F "${message_file}" -a "${tag}" "${commit}" && \ 84 git push origin tag "${tag}"