#!/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='' 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)) # DRY_RUN environment variable # shellcheck disable=SC2153 if [[ $DRY_RUN == 'true' ]]; then echo='echo (DRY-RUN):' dry_run='-d' 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 pr 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}" $echo gh pr create \ --assignee phatblat \ --base main \ --draft \ --fill popd