|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +cd "$(dirname "${BASH_SOURCE[0]}")" |
| 6 | + |
| 7 | +get_latest() { |
| 8 | + git fetch |
| 9 | + |
| 10 | + git tag | |
| 11 | + # drop `v` prefix |
| 12 | + grep "^v" | |
| 13 | + cut -c2- | |
| 14 | + |
| 15 | + # sort by semantic version |
| 16 | + sort -t "." -k1,1n -k2,2n -k3,3n | |
| 17 | + |
| 18 | + # last |
| 19 | + tail -n 1 | |
| 20 | + |
| 21 | + # drop newline |
| 22 | + tr -d '\n' |
| 23 | +} |
| 24 | + |
| 25 | +NEW="$1" |
| 26 | + |
| 27 | +if [ -z "$NEW" ]; then |
| 28 | + echo "Usage : bash release.sh <version>" |
| 29 | + echo "Example: bash release.sh 1.2.3" |
| 30 | + echo "" |
| 31 | + echo "Fetching tags..." |
| 32 | + latest="$(get_latest)" |
| 33 | + echo -n "The current version is: $latest" |
| 34 | + |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +if [[ "$NEW" == v* ]]; then |
| 39 | + echo "<version> must not start with \"v\"" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +echo "Checking for clean working tree..." |
| 44 | +if [[ "$(git diff --stat)" != "" ]]; then |
| 45 | + echo "❌ Dirty working tree (try git stash)" |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +echo "Checking that we're on master..." |
| 50 | +if [[ "$(git symbolic-ref HEAD | tr -d '\n')" != "refs/heads/master" ]]; then |
| 51 | + echo "❌ Not on master (try git checkout master)" |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +echo "Checking that master is up to date..." |
| 56 | +git fetch |
| 57 | +if [[ "$(git rev-parse master)" != "$(git rev-parse origin/master)" ]]; then |
| 58 | + echo "❌ master is out of sync with origin/master (try git pull)" |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | + |
| 62 | +git ls-tree -r HEAD --name-only -z examples | xargs -0 sed -i.sedbak "s/\"[0-9]*\.[0-9]*\.[0-9]*\" # LATEST/\"$NEW\" # LATEST/g" |
| 63 | +find . -name "*.sedbak" -print0 | xargs -0 rm |
| 64 | + |
| 65 | +git commit --all --message "release $NEW" |
| 66 | +git tag "v$NEW" |
| 67 | +git push --tags |
| 68 | +git push |
| 69 | + |
| 70 | +echo "" |
| 71 | +echo "✅ Released $NEW" |
| 72 | +echo "" |
| 73 | +echo "- Tags : https://github.com/sourcegraph/terraform-aws-executors/tags" |
| 74 | +echo "- Commits: https://github.com/sourcegraph/terraform-aws-executors/commits/master" |
| 75 | +echo "" |
| 76 | +echo "Make sure CI goes green 🟢:" |
| 77 | +echo "" |
| 78 | +echo "- https://buildkite.com/sourcegraph/terraform-aws-executors/builds?branch=master" |
| 79 | +echo "- https://buildkite.com/sourcegraph/terraform-aws-executors/builds?branch=v$NEW" |
0 commit comments