#!/bin/bash # Get the current version from the Cargo.toml file if [[ ! -f Cargo.toml ]]; then echo "Could not find Cargo.toml file" echo "Run release from project root" exit 1 fi CVER=$(grep -Po '(?<=^version = ")\d+\.\d+\.\d+(?="$)' ./Cargo.toml | head -1) if [[ -z $1 ]]; then echo echo " Current Version: $CVER" echo echo " Usage: ./release " echo exit 1 fi set -euo pipefail if [[ $(git rev-parse --abbrev-ref HEAD) != "master" ]]; then echo "not ok - Must release on 'master' branch" exit 1 fi if [[ $(git status -s | wc -l | grep -Po '\d+') -gt 0 ]]; then echo "not ok - Please commit all changes before releasing" exit 1 fi NVER=$1 if [[ ! $(grep "v${NVER}" CHANGELOG.md | wc -l | grep -Po '^\d+') -eq 1 ]]; then echo "not ok - Add version to CHANGELOG.md before releasing" exit 1 fi sed -i "s/\"$CVER\"/\"$NVER\"/" ./Cargo.toml echo "ok - Updated Cargo.toml" if [[ ! $(git diff Cargo.toml | grep '^+' | wc -l | grep -Po '^\d+') -eq 2 ]]; then echo "not ok - Failed to update Cargo.toml" exit 1 fi sed -i "s/\"$CVER\"/\"$NVER\"/" ./src/lib.rs echo "ok - Updated src/lib.rs" if [[ ! $(git diff ./src/lib.rs | grep '^+' | wc -l | grep -Po '^\d+') -eq 2 ]]; then echo "not ok - Failed to update src/lib.rs" exit 1 fi sed -i "s/$CVER/$NVER/" ./src/cli.yml echo "ok - Updated src/cli.yml" if [[ ! $(git diff ./src/cli.yml | grep '^+' | wc -l | grep -Po '^\d+') -eq 2 ]]; then echo "not ok - Failed to update src/cli.yml" exit 1 fi # Get CHANGELOG INFO CHANGE_START=$(echo $(grep -n "## v${NVER}" CHANGELOG.md | grep -Po '^\d+') + 1 | bc) CHANGE_END=$(echo $(grep -n "## v${CVER}" CHANGELOG.md | grep -Po '^\d+') - 1 | bc) CHANGE="$(sed -n "${CHANGE_START},${CHANGE_END}p" CHANGELOG.md)" cargo build --release git commit -am "v${NVER}" git tag "v${NVER}" git push git push --tags echo "ok - $CVER => $NVER" echo "ok - release pushed!" echo echo "${CHANGE}" echo echo "ok - publish the new release - https://github.com/mapbox/Hecate/releases/new?tag=v${NVER}"