mas/script/brew_tap_update
2024-03-31 11:05:04 -06:00

118 lines
2.3 KiB
Bash
Executable file

#!/bin/bash -e
#
# script/brew_tap_update
# mas
#
# Updates mas custom tap formula:
# https://github.com/mas-cli/homebrew-tap/blob/main/Formula/mas.rb
#
MAS_TAP_PATH="$(brew --repository mas-cli/tap)"
MAS_TAP_PATH_FORMULA="${MAS_TAP_PATH}/Formula/mas.rb"
PROJECT_PATH="$(git rev-parse --show-toplevel)"
LOCAL_TAP_FORMULA_PATH="${PROJECT_PATH}/Homebrew/mas-tap.rb"
function usage {
echo "Usage: brew_tap_update [-d] v0.0 [sha1_hash]"
echo " -d option enables dry run mode"
echo " version will be inferred using version script if not provided"
echo " sha will be inferred from the current commit if not provided"
exit 1
}
# Max 3 arguments
if [[ $# -gt 3 ]]; then
usage 1>&2
fi
echo='echo'
# Detect presence of `-d` dry run option
while getopts "d" o; do
case "${o}" in
d)
echo='echo (DRY-RUN):'
;;
*)
usage 1>&2
;;
esac
done
# DRY_RUN environment variable
# shellcheck disable=SC2153
if [[ $DRY_RUN == 'true' ]]; then
echo='echo (DRY-RUN):'
fi
# arg 1 - version tag
if [[ -n "${1}" ]]; then
MAS_VERSION="${1}"
else
MAS_VERSION="v$(script/version)"
fi
echo "MAS_VERSION: ${MAS_VERSION}"
# arg 2 - revision (commit hash)
if [[ -n "${2}" ]]; then
REVISION="${2}"
else
# Derive revision from version. Fails if MAS_VERSION is not a tag.
REVISION=$(git rev-parse "${MAS_VERSION}")
fi
echo "REVISION: ${REVISION}"
################################################################################
#
# Update Version
#
branch_name="releases/release-${MAS_VERSION}"
$echo git switch "${branch_name}"
################################################################################
#
# Create branch on mas-cli/homebrew-tap
#
# Ensure mas is tapped
if ! [[ -d "${MAS_TAP_PATH}" ]]; then
brew tap mas-cli/tap
fi
pushd "${MAS_TAP_PATH}"
branch_name="releases/release-${MAS_VERSION}"
$echo git branch "${branch_name}"
$echo git switch "${branch_name}"
# Update tap formula version
cp -v "${LOCAL_TAP_FORMULA_PATH}" "${MAS_TAP_PATH_FORMULA}"
$echo git add \
"${MAS_TAP_PATH_FORMULA}"
$echo git commit --message="🔖 Version ${MAS_VERSION}"
popd
# Build in mas project
script/bottle
################################################################################
#
# Create PR on mas-cli/homebrew-tap
#
pushd "${MAS_TAP_PATH}"
$echo gh pr create \
--assignee phatblat \
--base main \
--draft \
--fill
popd