From 7543e9ec2043af7d071373aeec04b92a98051087 Mon Sep 17 00:00:00 2001 From: Adin Scannell Date: Mon, 1 Apr 2019 16:17:40 -0700 Subject: Add release hook and version flag PiperOrigin-RevId: 241421671 Change-Id: Ic0cebfe3efd458dc42c49f7f812c13318705199a --- tools/tag_release.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++ tools/workspace_status.sh | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100755 tools/tag_release.sh (limited to 'tools') diff --git a/tools/tag_release.sh b/tools/tag_release.sh new file mode 100755 index 000000000..6906a952f --- /dev/null +++ b/tools/tag_release.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script will optionally map a PiperOrigin-RevId to a given commit, +# validate a provided release name, create a tag and push it. It must be +# run manually when a release is created. + +set -euxo pipefail + +# Check arguments. +if [ "$#" -ne 2 ]; then + echo "usage: $0 " + exit 1 +fi + +commit=$1 +release=$2 + +# Is the passed identifier a sha commit? +if ! git show "${commit}" &> /dev/null; then + # Extract the commit given a piper ID. + commit=$(git log|grep -E "(^commit |^ PiperOrigin-RevId:)" |grep -B1 "RevId: ${commit}"| head -n1|cut -d" " -f2) +fi +if ! git show "${commit}" &> /dev/null; then + echo "unknown commit: ${commit}" + exit 1 +fi + +# Is the release name sane? Must be a date with patch/rc. +if ! [[ "${release}" =~ ^20[0-9]{6}\.[0-9]+$ ]]; then + expected=$(date +%Y%m%d.0) # Use today's date. + echo "unexpected release format: ${release}" + echo " ... expected like ${expected}" + exit 1 +fi + +# Tag the given commit. +tag="release-${release}" +(git tag "${tag}" "${commit}" && git push origin tag "${tag}") || \ + (git tag -d "${tag}" && false) diff --git a/tools/workspace_status.sh b/tools/workspace_status.sh index 7d44dad37..a0e646e45 100755 --- a/tools/workspace_status.sh +++ b/tools/workspace_status.sh @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -echo GIT_REVISION $(git describe --always --abbrev=40 --dirty) +echo VERSION $(git describe --always --tags --abbrev=12 --dirty) -- cgit v1.2.3