-
Notifications
You must be signed in to change notification settings - Fork 59
/
release
executable file
·61 lines (49 loc) · 1.29 KB
/
release
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
#!/bin/bash
# set -x
# Usage:
#
# release X.X.X
#
# Creates a new version of the package. This script creates a new release branch
# where it updates the version variable. It then creates a matching tag and
# pushes both to GitHub.
# The file holding a version variable.
VERSION_FILE=meta.go
function create_release_branch {
local version="$1"
git checkout -b "releases/${version}"
}
function update_version {
local version="$1"
sed -i.backup "s/var Version =.*/var Version = \"${version}\"/" "${VERSION_FILE}"
rm -rf "${VERSION_FILE}.backup"
}
function commit_changes {
local version="$1"
git add "${VERSION_FILE}"
git commit -m "v${version}"
git tag -a "v${version}" -m "v${version}"
}
function push_changes {
local version="$1"
git push origin "releases/${version}"
git push origin "v${version}"
}
function main {
local version="$1"
if [[ $version = v* ]]; then
echo "version should be in the format X.Y.Z"
exit 1
fi
if git rev-parse "v$version" > /dev/null 2>&1; then
echo "version $version already exists"
exit 1
fi
local current_branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
create_release_branch $version
update_version $version
commit_changes $version
push_changes $version
git checkout $current_branch
}
main "$@"