From 36d40d99d708227a71023014615b804a663e5afc Mon Sep 17 00:00:00 2001 From: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> Date: Sat, 16 Nov 2024 13:47:13 -0500 Subject: [PATCH] Simplify & standardize script output headers & mas version handling. Partial #638 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> --- script/bootstrap | 2 +- script/bottle | 12 +++++------- script/build | 2 +- script/build_artifacts | 4 +--- script/install | 3 +-- script/lint | 2 +- script/package | 6 +++--- script/test | 2 +- script/version | 7 ++----- 9 files changed, 16 insertions(+), 24 deletions(-) diff --git a/script/bootstrap b/script/bootstrap index bacad7a..7b6d030 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -31,7 +31,7 @@ while getopts 'f' opt; do esac done -printf $'==> 👢 Bootstrapping (%s)\n' "$(script/version)" +printf $'==> 👢 Bootstrapping mas %s\n' "$(script/version)" # shellcheck disable=SC2086 brew bundle install ${frozen} --verbose diff --git a/script/bottle b/script/bottle index 3760f1d..695510f 100755 --- a/script/bottle +++ b/script/bottle @@ -23,8 +23,8 @@ fi BOTTLE_DIR=".build/bottles" CORE_TAP_PATH="$(brew --repo homebrew/core)" -MAS_VERSION="$(script/version)" -ROOT_URL="https://github.com/mas-cli/mas/releases/download/v${MAS_VERSION}" +version="$(script/version)" +ROOT_URL="https://github.com/mas-cli/mas/releases/download/v${version}" # Supports macOS 10.13 and later OS_NAMES=( @@ -76,8 +76,6 @@ if [[ "$(uname -m)" == 'arm64' ]]; then CURRENT_PLATFORM="arm64_${CURRENT_PLATFORM}" fi -echo "CURRENT_PLATFORM: ${CURRENT_PLATFORM}" - ################################################################################ # # Preflight checks @@ -105,14 +103,14 @@ brew style Homebrew/mas-tap.rb # Build the formula for the current macOS version and architecture. # -echo "==> 🍼 Bottling mas ${MAS_VERSION} for: ${OS_NAMES[*]}" +echo "==> 🍼 Bottling mas ${version} on ${CURRENT_PLATFORM} for ${OS_NAMES[*]}" brew install --build-bottle mas-cli/tap/mas # Generate bottle do block, dropping last 2 lines brew bottle --verbose --no-rebuild --root-url="${ROOT_URL}" mas-cli/tap/mas # Output filename from brew bottle -generated_bottle_filename="mas--${MAS_VERSION}.${CURRENT_PLATFORM}.bottle.tar.gz" +generated_bottle_filename="mas--${version}.${CURRENT_PLATFORM}.bottle.tar.gz" if [[ ! -e "${generated_bottle_filename}" ]]; then echo "Bottle not found: ${generated_bottle_filename}" >&2 @@ -140,7 +138,7 @@ EOF # Fix filename for os in "${OS_NAMES[@]}"; do - cp -v "${generated_bottle_filename}" "${BOTTLE_DIR}/mas-${MAS_VERSION}.${os}.bottle.tar.gz" + cp -v "${generated_bottle_filename}" "${BOTTLE_DIR}/mas-${version}.${os}.bottle.tar.gz" # Append each os # BOTTLE_BLOCK="$(printf "${BOTTLE_BLOCK}\n sha256 cellar: :any_skip_relocation, %-15s %s" "${os}:" "${SHA256}")" diff --git a/script/build b/script/build index 345d7de..b6ac981 100755 --- a/script/build +++ b/script/build @@ -30,7 +30,7 @@ else CACHE=() fi -echo "==> 🏗️ Building mas ($(script/version --write))" +echo "==> 🏗️ Building mas $(script/version --write)" swift build \ --configuration release \ "${ARCH[@]+"${ARCH[@]}"}" \ diff --git a/script/build_artifacts b/script/build_artifacts index a8ee44a..d81148b 100755 --- a/script/build_artifacts +++ b/script/build_artifacts @@ -13,9 +13,7 @@ if ! cd -- "${mas_dir}"; then exit 1 fi -MAS_VERSION="$(script/version)" - -echo "Building mas ${MAS_VERSION} artifacts" +echo "==> 👑 Building mas $(script/version) artifacts" script/clean script/build --universal diff --git a/script/install b/script/install index cb992be..90a4978 100755 --- a/script/install +++ b/script/install @@ -19,7 +19,6 @@ fi ARCH="$(uname -m)" RELEASE=".build/${ARCH}-apple-macosx/release" -MAS_VERSION="$(script/version)" PREFIX=/usr/local while [[ -n "${1}" ]]; do @@ -34,7 +33,7 @@ while [[ -n "${1}" ]]; do shift done -echo "==> 📲 Installing mas (${MAS_VERSION}) for ${ARCH} to ${PREFIX}" +echo "==> 📲 Installing mas $(script/version) for ${ARCH} to ${PREFIX}" ditto -v \ "${RELEASE}/mas" \ "${PREFIX}/bin/mas" diff --git a/script/lint b/script/lint index 03dca6b..844b804 100755 --- a/script/lint +++ b/script/lint @@ -19,7 +19,7 @@ if ! cd -- "${mas_dir}"; then exit 1 fi -printf $'==> 🚨 Linting mas (%s)\n' "$(script/version --write)" +printf $'==> 🚨 Linting mas %s\n' "$(script/version --write)" for linter in git markdownlint periphery shellcheck shfmt swift-format swiftformat swiftlint yamllint; do if [[ ! -x "$(command -v "${linter}")" ]]; then diff --git a/script/package b/script/package index 324df3f..0f40291 100755 --- a/script/package +++ b/script/package @@ -27,15 +27,15 @@ DISTRIBUTION_PLIST=Package/Distribution.plist DSTROOT="${BUILD_DIR}/distributions" script/install "${DSTROOT}/usr/local" --universal -MAS_VERSION="$(script/version)" +version="$(script/version)" -echo '==> 📦 Assemble an installer package' +echo "==> 📦 Assembling installer package for mas ${version}" # Assemble macOS installer component package (aka 'product archive'). pkgbuild \ --identifier "${IDENTIFIER}" \ --install-location '/' \ - --version "${MAS_VERSION}" \ + --version "${version}" \ --root "${DSTROOT}" \ "${COMPONENT_PACKAGE}" diff --git a/script/test b/script/test index 7c5f41c..02c5eec 100755 --- a/script/test +++ b/script/test @@ -13,6 +13,6 @@ if ! cd -- "${mas_dir}"; then exit 1 fi -printf $'==> ✅ Testing mas (%s)\n' "$(script/version --write)" +printf $'==> ✅ Testing mas %s\n' "$(script/version --write)" swift test diff --git a/script/version b/script/version index d6af92d..067c184 100755 --- a/script/version +++ b/script/version @@ -13,11 +13,8 @@ if ! cd -- "${mas_dir}"; then exit 1 fi -if [[ -z "${MAS_VERSION:-}" ]] && git describe >/dev/null 2>&1; then - # Use last tag if MAS_VERSION environment variable is unset or empty - MAS_VERSION="$(git describe --abbrev=0 --tags 2>/dev/null || true)" -fi -echo "${MAS_VERSION#v}" +version_tag="$(git describe --abbrev=0 --tags 2>/dev/null)" +printf $'%s\n' "${version_tag#v}" if [[ "${#}" -ge 1 && "${1}" == '--write' ]]; then # Write new version into swift package