This repository has been archived by the owner on Sep 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrelease.sh
executable file
·62 lines (53 loc) · 1.76 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
set -e
function print_usage {
echo "Usage:"
echo " RELEASE_VERSION=v1.0.0 release.sh"
echo " release.sh (-?, -h, --help)"
echo
echo "Options:"
echo " -?, -h, --help - Prints this usage information."
echo
echo "Environment variables:"
echo " - RELEASE_VERSION - Required. Set to a semantic version"
echo
}
if [[ $1 == "-?" || $1 == "-h" || $1 == "--help" ]]; then
print_usage
exit 0
fi
function sanity_check() {
if [[ ! -z $(git status --porcelain) ]]; then
echo "There are uncommitted changes. Please make sure branch is clean."
git status --porcelain
exit 1
fi
local_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $local_branch != "master" ]]; then
echo "This script can only be run from the master branch."
echo "You are on '$local_branch'. Aborting."
exit 1
fi
# Check if local branch is up-to-date with remote master branch
git fetch origin master
git diff origin/master --exit-code > /dev/null
if [[ $? -ne 0 ]]; then
echo "Local branch is not up-to-date with remote master. Please pull the latest changes."
git diff origin/master --name-only
exit 1
fi
}
## Verify that the local branch is pristine
sanity_check
## Build corectl with the version number and generate an API specification
echo "Generating new API specification for version ${RELEASE_VERSION}"
go build -ldflags "-X main.version=${RELEASE_VERSION}"
./corectl generate-spec > docs/spec.json
## Create a commit and add a tag
echo "Creating commit and tag for version ${RELEASE_VERSION}"
git commit -a -m "Release ${RELEASE_VERSION}"
git tag -a $RELEASE_VERSION -m "Release ${RELEASE_VERSION}"
## Push the commit and tag to origin
echo "Pushing release version ${RELEASE_VERSION} to origin"
git push --follow-tags
echo "Done."