mas/script/brew_formula_update
2024-03-09 10:36:27 -07:00

100 lines
2.1 KiB
Bash
Executable file

#!/bin/bash -e
#
# script/brew_formula_update
# mas
#
# Updates mas Homebrew core formula:
# https://github.com/Homebrew/homebrew-core/blob/master/Formula/mas.rb
#
# brew bump-formula-pr --help
#
CORE_TAP_PATH="$(brew --repository homebrew/core)"
CORE_FORMULA_PATH="${CORE_TAP_PATH}/Formula"
MAS_FORMULA_PATH="${CORE_FORMULA_PATH}/m/mas.rb"
function usage {
echo "Usage: brew_formula_update [0.0] [sha1_hash]"
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
}
if [[ $# -gt 3 ]]; then
usage
fi
# arg 1 - version tag
if test -n "$1"; then
MAS_VERSION="v$1"
else
MAS_VERSION="v$(script/version)"
fi
echo "MAS_VERSION: $MAS_VERSION"
# arg 2 - revision (commit hash)
if test -n "$2"; then
REVISION="$2"
else
REVISION=$(git rev-parse "$MAS_VERSION")
fi
echo "REVISION: $REVISION"
# Force brew to use the local repository instead of the API.
# Disable API before any install, reinstall or upgrade commands.
export HOMEBREW_NO_INSTALL_FROM_API=1
# Ensure core is tapped
if ! test -d "${CORE_TAP_PATH}"; then
brew tap homebrew/core
fi
if ! test -f "${MAS_FORMULA_PATH}"; then
brew install mas
fi
echo "Checking to see if this update can be a simple bump."
diff "Homebrew/mas.rb" "${MAS_FORMULA_PATH}"
# diff exit status
status=$?
formula_revisions=0
if test $status -ne 0; then
echo "There are changes in the local formula (Homebrew/mas.rb) that haven't been released yet."
#exit $status
formula_revisions=1
fi
echo "==> 🧪 Updating homebrew-core formula mas ($MAS_VERSION, $REVISION)"
echo "Validating formula"
brew bump-formula-pr \
--tag="$MAS_VERSION" \
--revision="$REVISION" \
--strict \
mas
# brew exit status
status=$?
if test $status -ne 0; then
echo "Formula did not validate using 'brew bump-formula-pr'"
exit $status
fi
pushd "$CORE_FORMULA_PATH" || exit 2
echo "Updating formula"
if test $formula_revisions -eq 1; then
# Options to
dry_run="--dry-run --write"
fi
brew bump-formula-pr \
--tag="$MAS_VERSION" \
--revision="$REVISION" \
--strict \
--verbose \
"$dry_run" \
mas