mirror of
https://github.com/mas-cli/mas
synced 2024-11-24 20:43:10 +00:00
🚩 Add dry run support to brew_formula_update
This commit is contained in:
parent
11734da12a
commit
d84dd58088
2 changed files with 64 additions and 42 deletions
|
@ -19,18 +19,37 @@ LOCAL_MAS_FORMULA_PATH="${PROJECT_PATH}/Homebrew/mas.rb"
|
|||
LOCAL_TAP_FORMULA_PATH="${PROJECT_PATH}/Homebrew/mas-tap.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"
|
||||
echo "Usage: brew_formula_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
|
||||
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))
|
||||
|
||||
# arg 1 - version tag
|
||||
if test -n "${1}"; then
|
||||
if [[ -n "${1}" ]]; then
|
||||
MAS_VERSION="${1}"
|
||||
else
|
||||
MAS_VERSION="v$(script/version)"
|
||||
|
@ -39,10 +58,15 @@ fi
|
|||
echo "MAS_VERSION: ${MAS_VERSION}"
|
||||
|
||||
# arg 2 - revision (commit hash)
|
||||
if test -n "${2}"; then
|
||||
if [[ -n "${2}" ]]; then
|
||||
REVISION="${2}"
|
||||
else
|
||||
REVISION=$(git rev-parse "${MAS_VERSION}")
|
||||
if [[ $dry_run == '-d' ]]; then
|
||||
REVISION=fake-revision
|
||||
else
|
||||
# Derive revision from version. Fails if MAS_VERSION is not a tag.
|
||||
REVISION=$(git rev-parse "${MAS_VERSION}")
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "REVISION: ${REVISION}"
|
||||
|
@ -54,18 +78,18 @@ echo "REVISION: ${REVISION}"
|
|||
|
||||
script/version_bump "${MAS_VERSION}" "$REVISION"
|
||||
|
||||
cp -v "${LOCAL_MAS_FORMULA_PATH}" "${CORE_MAS_FORMULA_PATH}"
|
||||
# cp -v "${LOCAL_MAS_FORMULA_PATH}" "${CORE_MAS_FORMULA_PATH}"
|
||||
|
||||
branch_name="releases/release-${MAS_VERSION}"
|
||||
git branch "${branch_name}"
|
||||
git switch "${branch_name}"
|
||||
$echo git branch "${branch_name}"
|
||||
$echo git switch "${branch_name}"
|
||||
|
||||
git add \
|
||||
$echo git add \
|
||||
"${SWIFT_PACKAGE}" \
|
||||
"${LOCAL_MAS_FORMULA_PATH}" \
|
||||
"${LOCAL_TAP_FORMULA_PATH}"
|
||||
|
||||
git commit --message="🔖 Version ${MAS_VERSION}"
|
||||
$echo git commit --message="🔖 Version ${MAS_VERSION}"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
|
@ -82,7 +106,7 @@ if command -v mas >/dev/null; then
|
|||
fi
|
||||
|
||||
# Ensure core is tapped
|
||||
if ! test -d "${CORE_TAP_PATH}"; then
|
||||
if ! [[ -d "${CORE_TAP_PATH}" ]]; then
|
||||
brew tap homebrew/core
|
||||
fi
|
||||
|
||||
|
@ -108,36 +132,41 @@ brew style mas-cli/tap/mas
|
|||
#
|
||||
# Update Homebrew
|
||||
#
|
||||
echo "Checking to see if this update can be a simple bump."
|
||||
diff "${LOCAL_MAS_FORMULA_PATH}" "${CORE_MAS_FORMULA_PATH}"
|
||||
|
||||
# echo "Checking to see if this update can be a simple bump."
|
||||
# diff "${LOCAL_MAS_FORMULA_PATH}" "${CORE_MAS_FORMULA_PATH}"
|
||||
|
||||
echo "==> 🧪 Updating homebrew-core formula mas (${MAS_VERSION}, ${REVISION})"
|
||||
|
||||
if [[ $dry_run == '-d' ]]; then
|
||||
# -n, --dry-run Print what would be done rather than doing
|
||||
# it.
|
||||
# --write-only Make the expected file modifications without
|
||||
# taking any Git actions.
|
||||
dry_run="--dry-run"
|
||||
fi
|
||||
|
||||
echo "Validating formula"
|
||||
brew bump-formula-pr \
|
||||
--tag="${MAS_VERSION}" \
|
||||
--revision="${REVISION}" \
|
||||
--strict \
|
||||
--verbose \
|
||||
"${dry_run}" \
|
||||
mas
|
||||
|
||||
# brew exit status
|
||||
status=$?
|
||||
if test ${status} -ne 0; then
|
||||
if [[ ${status} -ne 0 ]]; then
|
||||
echo "Formula did not validate using 'brew bump-formula-pr'"
|
||||
exit ${status}
|
||||
fi
|
||||
|
||||
pushd "${CORE_FORMULA_PATH}" || exit 2
|
||||
|
||||
dry_run=''
|
||||
echo "Updating formula"
|
||||
# if test $formula_revisions -eq 1; then
|
||||
# # Options to
|
||||
# dry_run="--dry-run --write"
|
||||
# fi
|
||||
echo "Updating homebrew/core formula with a PR"
|
||||
|
||||
brew bump-formula-pr \
|
||||
$echo brew bump-formula-pr \
|
||||
--tag="${MAS_VERSION}" \
|
||||
--revision="${REVISION}" \
|
||||
--commit \
|
||||
|
@ -153,7 +182,7 @@ brew bump-formula-pr \
|
|||
# Create pr on mas-cli/mas
|
||||
#
|
||||
|
||||
gh pr create \
|
||||
$echo gh pr create \
|
||||
--assignee phatblat \
|
||||
--base main \
|
||||
--draft \
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
# Increments the marketing version of mas.
|
||||
#
|
||||
|
||||
|
||||
# SCRIPT_PATH=$(dirname "$(which "$0")")
|
||||
PROJECT_PATH="$(git rev-parse --show-toplevel)"
|
||||
PACKAGE_MANIFEST="${PROJECT_PATH}/Sources/MasKit/Package.swift"
|
||||
LOCAL_MAS_FORMULA_PATH="${PROJECT_PATH}/Homebrew/mas.rb"
|
||||
|
@ -24,23 +22,20 @@ if [[ $# -lt 1 ]]; then
|
|||
usage
|
||||
fi
|
||||
|
||||
last_tag=$(script/version)
|
||||
echo "Last git tag: $last_tag"
|
||||
|
||||
# arg 1 - version tag
|
||||
if test -n "$1"; then
|
||||
MAS_VERSION=$1
|
||||
if test -n "${1}"; then
|
||||
MAS_VERSION=${1}
|
||||
fi
|
||||
|
||||
# arg 2 - revision (commit hash)
|
||||
if test -n "$2"; then
|
||||
REVISION="$2"
|
||||
if test -n "${2}"; then
|
||||
REVISION="${2}"
|
||||
else
|
||||
REVISION=$(git rev-parse "$MAS_VERSION")
|
||||
REVISION=$(git rev-parse "${MAS_VERSION}")
|
||||
fi
|
||||
|
||||
echo "MAS_VERSION: $MAS_VERSION"
|
||||
echo "REVISION: $REVISION"
|
||||
echo "MAS_VERSION: ${MAS_VERSION}"
|
||||
echo "REVISION: ${REVISION}"
|
||||
|
||||
# Write new version into swift package
|
||||
cat <<EOF >"${PACKAGE_MANIFEST}"
|
||||
|
@ -54,11 +49,9 @@ echo
|
|||
cat "${PACKAGE_MANIFEST}"
|
||||
|
||||
# Write new version into brew formulae
|
||||
for file in $LOCAL_MAS_FORMULA_PATH $LOCAL_TAP_FORMULA_PATH; do
|
||||
echo "$file"
|
||||
# echo sed -i "5s/(\w+tag:\w+\"\)v[^\"]\",/$0$MAS_VERSION\"/" "$file"
|
||||
# sed -i '' -E "s/(\w+tag:\w+\")v,/\1$MAS_VERSION\"/" "$file"
|
||||
sd '( +tag: +)"[^"]+"' "\$1\"$MAS_VERSION\"" "$file"
|
||||
sd '( +revision: +)"[^"]+"' "\$1\"$REVISION\"" "$file"
|
||||
for file in ${LOCAL_MAS_FORMULA_PATH} ${LOCAL_TAP_FORMULA_PATH}; do
|
||||
echo "${file}"
|
||||
sd '( +tag: +)"[^"]+"' "\$1\"${MAS_VERSION}\"" "${file}"
|
||||
sd '( +revision: +)"[^"]+"' "\$1\"${REVISION}\"" "${file}"
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in a new issue