|
| 1 | +#!/usr/bin/env bash |
| 2 | +# eval "$GLUE_BOOTSTRAP" |
| 3 | +# bootstrap || exit |
| 4 | + |
| 5 | +# @file util-release-pre.sh |
| 6 | +# @brief Steps to perform before specialized version bumping |
| 7 | +# @description Before the release is made, this ensures there |
| 8 | +# are no changes in the working directory, and from the version |
| 9 | +# in 'glue-auto.toml', increments the version. This does not handle |
| 10 | +# anything language specific, so this is usually called along with |
| 11 | +# 'util-release-post.sh', and any other files that need version bumping |
| 12 | +# is performed in the interum |
| 13 | + |
| 14 | +unset main |
| 15 | +main() { |
| 16 | + ensure.cmd 'git' |
| 17 | + ensure.file 'glue-auto.toml' |
| 18 | + |
| 19 | + # Ensure working tree not dirty |
| 20 | + if [ -n "$(git status --porcelain)" ]; then |
| 21 | + die 'Working tree still dirty. Please commit all changes before making a release' |
| 22 | + fi |
| 23 | + |
| 24 | + # Ensure we can push new version and its tags changes without --force-lease |
| 25 | + if ! git merge-base --is-ancestor origin/main main; then |
| 26 | + # main NOT is the same or has new additional commits on top of origin/main" |
| 27 | + die "Detected that your 'main' branch and it's remote have diverged. Won't initiate release process until histories are shared" |
| 28 | + fi |
| 29 | + |
| 30 | + # Get current version |
| 31 | + toml.get_key version glue-auto.toml |
| 32 | + local currentVersion="$REPLY" |
| 33 | + |
| 34 | + # Get new version number |
| 35 | + # TODO: make incremenet better |
| 36 | + echo "Current Version: $currentVersion" |
| 37 | + read -rp 'New Version? ' -ei "$currentVersion" |
| 38 | + local newVersion="$REPLY" |
| 39 | + declare -g REPLY="$newVersion" # explicit |
| 40 | + |
| 41 | + # Ensure new version is valid (does not already exist) |
| 42 | + if [ -n "$(git tag -l "v$newVersion")" ]; then |
| 43 | + # TODO: ensure there are no tag sthat exists that are greater than it |
| 44 | + die 'Version already exists in a Git tag' |
| 45 | + fi |
| 46 | + |
| 47 | + sed -i -e "s|\(version[ \t]*=[ \t]*\"\).*\(\"\)|\1${newVersion}\2|g" glue-auto.toml |
| 48 | +} |
| 49 | + |
| 50 | +main "$@" |
| 51 | + |
| 52 | +# unbootstrap |
0 commit comments