#!/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/bash-unit/bash_unit/releases -d " { \"tag_name\": \"$version\" }" } usage() { local message=$1 cat >&2 < [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= token= is your github account. 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"