Skip to content

Commit

Permalink
Add release tagging script
Browse files Browse the repository at this point in the history
  • Loading branch information
taisph committed Oct 27, 2021
1 parent a66e723 commit e24231c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ image images:

render:
scripts/ops.sh render

release:
scripts/ops.sh release
63 changes: 63 additions & 0 deletions scripts/ops.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -euo pipefail

function usage() {
echo "Usage: $0 <check|release>"
exit 1
}

function check() {
output=${1:-verbose}
for cmd in git semver; do
command -v ${cmd} 2>/dev/null 1>&2 || (echo "Error: ${cmd} not found in path" && exit 1)
[[ "$output" = "silent" ]] || echo "Found ${cmd}"
done
[[ "$output" = "silent" ]] || echo "OK"
}

function release {
git fetch --all

src_branch=$(git rev-parse --abbrev-ref ${1:-HEAD})
src_branch_base=${src_branch#origin/*}
src_branch_topic=${src_branch_base%%/*}
src_branch_version=${src_branch_base#*/}

if [[ "$src_branch_topic" != "release" ]]; then
echo "Unsupported branch type: ${src_branch_topic}"
exit 1
fi

last_tag=$(git describe --abbrev=0 ${src_branch})
tag=$(semver --range $src_branch_version $last_tag || true)
if [[ -z "$tag" ]]; then
tag="$src_branch_version.0"
else
tag=$(semver --increment $tag)
fi

message=$(
echo -e "Release $tag\n"
git log --oneline $last_tag..$src_branch | sed -re 's/^[^ ]+/-/' | (grep -vE "^- (Merge (branch|tag) |Bump)" || [ $? -eq 1 ])
)

git tag -a "$tag" -m "$message"
git push --tags
}

action=${1:-}

case "${action}" in
release)
check silent
release
;;
check)
check verbose
;;
*)
echo "Error: invalid action: ${action}"
usage
;;
esac

0 comments on commit e24231c

Please sign in to comment.