Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 1 | #!/bin/bash -eu |
| 2 | |
Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame^] | 3 | # Copyright 2015 The Bazel Authors. All rights reserved. |
Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 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 | # Some common method for release scripts |
| 18 | |
| 19 | # A release candidate is created from a branch named "release-%name%" |
| 20 | # where %name% is the name of the release. Once promoted to a release, |
| 21 | # A tag %name% will be created from this branch and the corresponding |
| 22 | # branch removed. |
| 23 | # The last commit of the release branch is always a commit containing |
| 24 | # the release notes in the commit message and updating the CHANGELOG.md. |
| 25 | # This last commit will be cherry-picked back in the master branch |
| 26 | # when the release candidate is promoted to a release. |
| 27 | # To follow tracks and to support how CI systems fetch the refs, we |
| 28 | # store two commit notes: the release name and the candidate number. |
| 29 | |
| 30 | # Returns the branch name of the current git repository |
| 31 | function git_get_branch() { |
| 32 | git symbolic-ref --short HEAD |
| 33 | } |
| 34 | |
| 35 | # Show the commit message of the ref specified in argument |
| 36 | function git_commit_msg() { |
| 37 | git show -s --pretty=format:%B "$@" |
| 38 | } |
| 39 | |
| 40 | # Extract the release candidate number from the git notes |
| 41 | function get_release_candidate() { |
| 42 | git notes --ref=release-candidate show "$@" 2>/dev/null | xargs echo || true |
| 43 | } |
| 44 | |
| 45 | # Extract the release name from the git notes |
| 46 | function get_release_name() { |
| 47 | git notes --ref=release show "$@" 2>/dev/null | xargs echo || true |
| 48 | } |
| 49 | |
| 50 | # Returns the info from the branch of the release. It is the current branch |
| 51 | # but it errors out if the current branch is not a release branch. This |
| 52 | # method returns the tag of the release and the number of the current |
| 53 | # candidate in this release. |
| 54 | function get_release_branch() { |
| 55 | local branch_name=$(git_get_branch) |
| 56 | if [ -z "$(get_release_name)" -o -z "$(get_release_candidate)" ]; then |
| 57 | echo "Not a release branch: ${branch_name}." >&2 |
| 58 | exit 1 |
| 59 | fi |
| 60 | echo "${branch_name}" |
| 61 | } |