2020-09-07 16:15:01 +00:00
|
|
|
#!/bin/bash -e
|
2019-03-31 22:50:25 +00:00
|
|
|
#
|
2024-03-11 01:32:02 +00:00
|
|
|
# script/brew_tap_update
|
2019-03-31 22:50:25 +00:00
|
|
|
# mas
|
|
|
|
#
|
2024-03-11 01:32:02 +00:00
|
|
|
# Updates mas custom tap formula:
|
|
|
|
# https://github.com/mas-cli/homebrew-tap/blob/main/Formula/mas.rb
|
2019-04-01 04:00:29 +00:00
|
|
|
#
|
2019-03-31 22:50:25 +00:00
|
|
|
|
2024-03-11 01:32:02 +00:00
|
|
|
MAS_TAP_PATH="$(brew --repository mas-cli/tap)"
|
|
|
|
MAS_TAP_PATH_FORMULA="${MAS_TAP_PATH}/Formula/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_TAP_FORMULA_PATH="${PROJECT_PATH}/Homebrew/mas-tap.rb"
|
|
|
|
|
2019-03-31 22:50:25 +00:00
|
|
|
function usage {
|
2024-03-11 01:48:25 +00:00
|
|
|
echo "Usage: brew_tap_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
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
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
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Update Version
|
|
|
|
#
|
|
|
|
|
2024-03-10 15:23:53 +00:00
|
|
|
branch_name="releases/release-${MAS_VERSION}"
|
2024-03-10 16:05:36 +00:00
|
|
|
$echo git switch "${branch_name}"
|
2024-03-10 15:03:03 +00:00
|
|
|
|
2024-03-10 15:23:53 +00:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Create pr on mas-cli/homebrew-tap
|
|
|
|
#
|
2024-03-11 01:32:02 +00:00
|
|
|
|
|
|
|
# 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}"
|
|
|
|
|
2024-03-11 01:48:25 +00:00
|
|
|
# Update tap formula version
|
|
|
|
cp -v "${LOCAL_TAP_FORMULA_PATH}" "${MAS_TAP_PATH_FORMULA}"
|
|
|
|
|
2024-03-11 01:32:02 +00:00
|
|
|
$echo git add \
|
|
|
|
"${MAS_TAP_PATH_FORMULA}"
|
|
|
|
|
|
|
|
$echo git commit --message="🔖 Version ${MAS_VERSION}"
|
|
|
|
|
|
|
|
$echo gh pr create \
|
|
|
|
--assignee phatblat \
|
|
|
|
--base main \
|
|
|
|
--draft \
|
|
|
|
--fill
|
|
|
|
|
|
|
|
popd
|
|
|
|
|