|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# This script checks that current branch has most recent entrypoint tag. |
| 4 | +# Entrypoint tag is annotated tag. Release tags are also expected to |
| 5 | +# be annotated tags. |
| 6 | +# |
| 7 | +# There are 2 cases when we require entrypoint tag. |
| 8 | +# |
| 9 | +# 1. We require that after release tag (like 2.11.3) the next commit |
| 10 | +# has entrypoint tag (2.11.4-entrypoint). |
| 11 | +# |
| 12 | +# 2. After branching. For example we develop 3.0.0 in master. And decide |
| 13 | +# to create 3.0 branch. The first commint in 3.0 branch is required |
| 14 | +# to have some tag (like 3.0.0-rc1, 3.0.0 or whatever). The first commit after |
| 15 | +# fork in master branch is required to have entrypoint tag (3.1.0-entrypoint). |
| 16 | +# |
| 17 | +# Note that in both cases we do not check that entrypoint tag has proper |
| 18 | +# suffix or numbers. |
| 19 | +# |
| 20 | +# We check for most recent entrypoint tag only. For example if there |
| 21 | +# are tags 2.10.0 and 2.10.1 we only check for 2.10.2-entrypoint. |
| 22 | +# |
| 23 | +# Expected branches names: |
| 24 | +# |
| 25 | +# - master |
| 26 | +# - release/* |
| 27 | + |
| 28 | +set -eo pipefail |
| 29 | + |
| 30 | +error() { |
| 31 | + echo "$@" 1>&2 |
| 32 | + exit 1 |
| 33 | +} |
| 34 | + |
| 35 | +######### |
| 36 | +# Case 1. |
| 37 | +######### |
| 38 | + |
| 39 | +# Match digit only release tags like 2.10.0. |
| 40 | +pattern='^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$' |
| 41 | +# Get most recent tag in the HEAD ancestry. |
| 42 | +tag=`git describe --abbrev=0` |
| 43 | +# If it is a release tag. |
| 44 | +if [[ "$tag" =~ $pattern ]]; then |
| 45 | + # Find the commit just after the release tag in the HEAD ancestry. |
| 46 | + # It is not tagged as entrypoint because it was not seen by the |
| 47 | + # describe command above. |
| 48 | + entrypoint=`git rev-list HEAD ^$tag | tail -n1` |
| 49 | + if [[ $entrypoint ]]; then |
| 50 | + error "Missing entrypoint tag for commit $entrypoint after release"\ |
| 51 | + "tag $tag." |
| 52 | + fi |
| 53 | +fi |
| 54 | + |
| 55 | +######### |
| 56 | +# Case 2. |
| 57 | +######### |
| 58 | + |
| 59 | +# Find current branch (report HEAD for 'detached HEAD' state). |
| 60 | +branch=`git rev-parse --abbrev-ref HEAD` |
| 61 | +if [[ "$branch" =~ ^(master|release/.*)$ ]]; then |
| 62 | + # We need to find the commit that starts this branch (i.e. that the first |
| 63 | + # commit on this branch after the commit that is common for two branches.) |
| 64 | + # |
| 65 | + # In order to achieve this we find all the commits of this branch that |
| 66 | + # are not on other branches from release/* && master set. |
| 67 | + # |
| 68 | + # Unfortunately I did not find a way to set arguments for git rev-list |
| 69 | + # without this branch. |
| 70 | + if [[ "$branch" = master ]]; then |
| 71 | + not_remotes="--remotes=origin/release/*" |
| 72 | + else |
| 73 | + not_remotes="--exclude origin/$branch --remotes=origin/release/* origin/master" |
| 74 | + fi |
| 75 | + entrypoint=`git rev-list HEAD --not $not_remotes | tail -n1` |
| 76 | + if [[ $entrypoint ]]; then |
| 77 | + # Check if entrypoint has annotated tag. |
| 78 | + git describe --exact-match $entrypoint &>/dev/null || \ |
| 79 | + error "Missing tag for commit $entrypoint after branching in"\ |
| 80 | + "branch $branch." |
| 81 | + fi |
| 82 | +fi |
| 83 | + |
| 84 | +echo OK |
0 commit comments