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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#!/usr/bin/env -S bash -e
token_file=token
cd "$(dirname "$0")" || exit
check_can_release() {
local version="$1"
type -P asciidoctor >/dev/null || usage "You need asciidoctor to make releases"
if [ -n "$(git status --porcelain)" ]
then
git status >&2
echo >&2
usage "Please commit your pending changes first"
fi
[[ -z "$version" ]] && usage "No version specified on command line"
echo "$version" | grep -E '^v[0-9]*\.[0-9]*\.[0-9]*$' >/dev/null || usage "Invalid format for version: $version"
[ -r "$token_file" ] || usage "'$token_file' file does not exist"
# shellcheck disable=1090
source "$token_file"
[[ -z "$user" ]] && usage "user not found in file '$token_file'"
[[ -z "$token" ]] && usage "token not found in file '$token_file'"
true #avoid error on last instruction of function (see bash -e)
}
prepare_release() {
set -x
local version="$1"
shift
update_version "$version"
update_man
git add bash_unit
git add docs/man/man1/bash_unit.1
if [ $# -eq 0 ]
then
git commit -m "prepare release $version"
else
git commit -m "$*"
fi
git tag "$version"
}
update_version() {
local version="$1"
sed -i -e "s:^VERSION=.*:VERSION=$version:" bash_unit
}
update_man() {
asciidoctor -D docs/man/man1 -d manpage -b manpage README.adoc
}
publish_release() {
local version="$1"
git push
git push --tags
curl -u "$user:$token" -XPOST https://api.github.com/repos/pgrange/bash_unit/releases -d "
{
\"tag_name\": \"$version\"
}"
}
usage() {
local message=$1
cat >&2 <<EOF
$message
$0 <version> [release note]
Publishes a new release of bash_unit on github.
Version must respect [Semantic Versioning](http://semver.org/)
A token file must exist in the current working directory. This file must be of the form:
user=<user>
token=<token>
<user> is your github account.
<token> is your github api token. See https://github.com/settings/tokens
EOF
exit 1
}
[[ $# -ge 1 ]] || usage "You must specify version on command line"
version=$1
shift
check_can_release "$version"
prepare_release "$version" "$@"
publish_release "$version"
|