2024-03-31 21:00:00 +00:00
|
|
|
#!/bin/bash -ex
|
2019-03-31 22:50:25 +00:00
|
|
|
#
|
2024-03-11 01:32:02 +00:00
|
|
|
# script/brew_core_update
|
2019-03-31 22:50:25 +00:00
|
|
|
# mas
|
|
|
|
#
|
|
|
|
# Updates mas Homebrew core formula:
|
|
|
|
# https://github.com/Homebrew/homebrew-core/blob/master/Formula/mas.rb
|
|
|
|
#
|
2019-04-01 04:00:29 +00:00
|
|
|
# brew bump-formula-pr --help
|
|
|
|
#
|
2019-03-31 22:50:25 +00:00
|
|
|
|
2024-03-09 15:33:05 +00:00
|
|
|
CORE_TAP_PATH="$(brew --repository homebrew/core)"
|
2024-08-01 03:04:54 +00:00
|
|
|
CORE_MAS_FORMULA_FILE="${CORE_TAP_PATH}/Formula/m/mas.rb"
|
2019-03-31 22:50:25 +00:00
|
|
|
|
2024-03-10 15:23:53 +00:00
|
|
|
PROJECT_PATH="$(git rev-parse --show-toplevel)"
|
|
|
|
LOCAL_MAS_FORMULA_PATH="${PROJECT_PATH}/Homebrew/mas.rb"
|
|
|
|
|
2019-03-31 22:50:25 +00:00
|
|
|
function usage {
|
2024-03-11 01:48:06 +00:00
|
|
|
echo "Usage: brew_core_update [-d] v0.0 [sha1_hash]"
|
2024-03-10 16:05:36 +00:00
|
|
|
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"
|
2021-03-21 23:50:09 +00:00
|
|
|
exit 1
|
2019-03-31 22:50:25 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 16:05:36 +00:00
|
|
|
# Max 3 arguments
|
2024-03-09 17:22:19 +00:00
|
|
|
if [[ $# -gt 3 ]]; then
|
2024-03-10 16:05:36 +00:00
|
|
|
usage 1>&2
|
2024-03-09 17:22:19 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-10 16:05:36 +00:00
|
|
|
echo=''
|
|
|
|
dry_run=''
|
|
|
|
|
|
|
|
# Detect presence of `-d` dry run option
|
|
|
|
while getopts "d" o; do
|
|
|
|
case "${o}" in
|
|
|
|
d)
|
|
|
|
echo='echo (DRY-RUN):'
|
|
|
|
dry_run='-d'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1>&2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2024-03-31 17:05:04 +00:00
|
|
|
shift $((OPTIND - 1))
|
2024-03-10 16:05:36 +00:00
|
|
|
|
2024-03-10 17:19:12 +00:00
|
|
|
# DRY_RUN environment variable
|
|
|
|
# shellcheck disable=SC2153
|
|
|
|
if [[ $DRY_RUN == 'true' ]]; then
|
|
|
|
echo='echo (DRY-RUN):'
|
|
|
|
dry_run='-d'
|
|
|
|
fi
|
|
|
|
|
2019-03-31 22:50:25 +00:00
|
|
|
# arg 1 - version tag
|
2024-03-10 16:05:36 +00:00
|
|
|
if [[ -n "${1}" ]]; then
|
2024-03-10 15:23:53 +00:00
|
|
|
MAS_VERSION="${1}"
|
2019-03-31 22:50:25 +00:00
|
|
|
else
|
2023-11-25 23:04:18 +00:00
|
|
|
MAS_VERSION="v$(script/version)"
|
2019-03-31 22:50:25 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-10 15:23:53 +00:00
|
|
|
echo "MAS_VERSION: ${MAS_VERSION}"
|
2024-03-09 17:22:19 +00:00
|
|
|
|
2019-03-31 22:50:25 +00:00
|
|
|
# arg 2 - revision (commit hash)
|
2024-03-10 16:05:36 +00:00
|
|
|
if [[ -n "${2}" ]]; then
|
2024-03-10 15:23:53 +00:00
|
|
|
REVISION="${2}"
|
2019-03-31 22:50:25 +00:00
|
|
|
else
|
2024-03-10 17:43:13 +00:00
|
|
|
# Derive revision from version. Fails if MAS_VERSION is not a tag.
|
|
|
|
REVISION=$(git rev-parse "${MAS_VERSION}")
|
2019-03-31 22:50:25 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-10 15:23:53 +00:00
|
|
|
echo "REVISION: ${REVISION}"
|
2024-03-09 17:22:19 +00:00
|
|
|
|
2024-03-10 15:03:03 +00:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Preflight checks
|
|
|
|
#
|
|
|
|
|
|
|
|
# Uninstall if necessary
|
|
|
|
brew remove mas 2>/dev/null || true
|
|
|
|
brew remove mas-cli/tap/mas 2>/dev/null || true
|
|
|
|
|
|
|
|
# Uninstall if still found on path
|
|
|
|
if command -v mas >/dev/null; then
|
|
|
|
script/uninstall || true
|
|
|
|
fi
|
2024-03-04 04:43:58 +00:00
|
|
|
|
2024-03-09 17:22:19 +00:00
|
|
|
# Ensure core is tapped
|
2024-03-10 16:05:36 +00:00
|
|
|
if ! [[ -d "${CORE_TAP_PATH}" ]]; then
|
2024-03-09 17:22:19 +00:00
|
|
|
brew tap homebrew/core
|
2024-03-09 15:33:05 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-10 15:03:03 +00:00
|
|
|
brew update
|
2024-02-19 06:31:03 +00:00
|
|
|
|
2024-03-10 15:03:03 +00:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Build the formula for the current macOS version and architecture.
|
|
|
|
#
|
|
|
|
|
2024-03-10 18:22:15 +00:00
|
|
|
# Update mas formula in core (temporary)
|
2024-08-01 03:04:54 +00:00
|
|
|
cp -v "${LOCAL_MAS_FORMULA_PATH}" "${CORE_MAS_FORMULA_FILE}"
|
2024-03-10 17:43:13 +00:00
|
|
|
|
|
|
|
# Install mas from source
|
|
|
|
# HOMEBREW_NO_INSTALL_FROM_API:
|
2024-03-10 15:03:03 +00:00
|
|
|
# Force brew to use the local repository instead of the API.
|
|
|
|
# Disable API before any install, reinstall or upgrade commands.
|
|
|
|
|
2024-03-10 17:43:13 +00:00
|
|
|
HOMEBREW_NO_INSTALL_FROM_API=1 \
|
|
|
|
brew install mas \
|
2024-03-31 17:05:04 +00:00
|
|
|
--build-from-source \
|
|
|
|
--verbose
|
2024-03-10 15:03:03 +00:00
|
|
|
|
|
|
|
# Audit formula
|
2024-03-10 17:49:14 +00:00
|
|
|
brew audit --strict mas
|
|
|
|
brew style mas
|
2024-03-10 15:03:03 +00:00
|
|
|
|
2024-03-10 18:22:15 +00:00
|
|
|
# Revert core formula change after testing
|
|
|
|
pushd "${CORE_TAP_PATH}"
|
|
|
|
git diff
|
|
|
|
git checkout .
|
|
|
|
popd
|
|
|
|
|
2024-03-10 15:03:03 +00:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Update Homebrew
|
|
|
|
#
|
2024-03-10 16:05:36 +00:00
|
|
|
|
|
|
|
# echo "Checking to see if this update can be a simple bump."
|
2024-08-01 03:04:54 +00:00
|
|
|
# diff "${LOCAL_MAS_FORMULA_PATH}" "${CORE_MAS_FORMULA_FILE}"
|
2019-04-01 04:00:29 +00:00
|
|
|
|
2024-03-10 15:23:53 +00:00
|
|
|
echo "==> 🧪 Updating homebrew-core formula mas (${MAS_VERSION}, ${REVISION})"
|
2024-03-10 15:03:03 +00:00
|
|
|
|
2024-03-10 16:05:36 +00:00
|
|
|
|
2019-03-31 22:50:25 +00:00
|
|
|
echo "Validating formula"
|
|
|
|
brew bump-formula-pr \
|
2024-03-10 15:23:53 +00:00
|
|
|
--tag="${MAS_VERSION}" \
|
|
|
|
--revision="${REVISION}" \
|
2021-03-21 23:50:09 +00:00
|
|
|
--strict \
|
2024-03-10 15:03:03 +00:00
|
|
|
--verbose \
|
2024-03-31 20:57:06 +00:00
|
|
|
--no-browse \
|
|
|
|
--fork-org mas-cli \
|
|
|
|
--dry-run \
|
2021-03-21 23:50:09 +00:00
|
|
|
mas
|
2019-03-31 22:50:25 +00:00
|
|
|
|
2019-04-01 04:00:29 +00:00
|
|
|
# brew exit status
|
|
|
|
status=$?
|
2024-03-10 16:05:36 +00:00
|
|
|
if [[ ${status} -ne 0 ]]; then
|
2021-03-21 23:50:09 +00:00
|
|
|
echo "Formula did not validate using 'brew bump-formula-pr'"
|
2024-03-10 15:23:53 +00:00
|
|
|
exit ${status}
|
2019-04-01 04:00:29 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-31 20:57:06 +00:00
|
|
|
if [[ $dry_run == '-d' ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-08-01 03:04:54 +00:00
|
|
|
pushd "${CORE_TAP_PATH}"
|
2019-03-31 22:50:25 +00:00
|
|
|
|
2024-03-10 16:05:36 +00:00
|
|
|
echo "Updating homebrew/core formula with a PR"
|
2019-04-01 04:00:29 +00:00
|
|
|
|
2024-03-10 16:05:36 +00:00
|
|
|
$echo brew bump-formula-pr \
|
2024-03-10 15:23:53 +00:00
|
|
|
--tag="${MAS_VERSION}" \
|
|
|
|
--revision="${REVISION}" \
|
2021-03-21 23:50:09 +00:00
|
|
|
--strict \
|
|
|
|
--verbose \
|
2024-03-31 20:57:06 +00:00
|
|
|
--online \
|
|
|
|
--no-browse \
|
|
|
|
--fork-org mas-cli \
|
2021-03-21 23:50:09 +00:00
|
|
|
mas
|
2024-03-10 15:23:53 +00:00
|
|
|
|
2024-03-11 01:32:02 +00:00
|
|
|
popd
|