♻️ Split workflow into 4 jobs

This commit is contained in:
Ben Chatelain 2024-03-10 19:32:02 -06:00
parent 87a00742c8
commit c0950b130b
No known key found for this signature in database
5 changed files with 328 additions and 19 deletions

View file

@ -22,7 +22,7 @@ on:
release:
types: [published]
jobs:
release:
debug-event:
runs-on: macos-14
steps:
@ -47,10 +47,16 @@ jobs:
echo "MAS_VERSION: ${MAS_VERSION}"
echo "RELEASE_COMMIT: ${RELEASE_COMMIT}"
pkg-installer:
runs-on: macos-14
needs: debug-event
steps:
- uses: actions/checkout@v4
with:
# A fetch-depth of 0 includes all history and tags for script/version
fetch-depth: 0
- name: 👢 Bootstrap
run: |
script/bootstrap
@ -60,9 +66,11 @@ jobs:
- name: 🏗️ Build Universal
run: |
script/build --universal
- name: 📦 macOS Package
run: |
script/package
- name: 🚀 Upload mas.pkg
uses: actions/upload-artifact@v3
if: ${{ env.DRY_RUN == 'false' }}
@ -71,14 +79,48 @@ jobs:
name: mas.pkg
path: .build/mas.pkg
homebrew-core:
runs-on: macos-14
needs: debug-event
steps:
- uses: actions/checkout@v4
with:
# A fetch-depth of 0 includes all history and tags for script/version
fetch-depth: 0
- name: 👢 Bootstrap
run: |
script/bootstrap
- name: 🍺 Update Homebrew mas formula
run: |
DRY_RUN=${{ env.DRY_RUN }} \
script/brew_formula_update ${{ env.MAS_VERSION }}
script/brew_core_update ${{ env.MAS_VERSION }}
homebrew-tap:
runs-on: macos-14
needs: [debug-event, homebrew-core]
steps:
- uses: actions/checkout@v4
with:
# A fetch-depth of 0 includes all history and tags for script/version
fetch-depth: 0
- name: 👢 Bootstrap
run: |
script/bootstrap
- name: 🚰 Update mas tap formula
run: |
DRY_RUN=${{ env.DRY_RUN }} \
script/brew_tap_update ${{ env.MAS_VERSION }}
- name: 🍼 Homebrew Bottles for mas tap
run: |
script/bottle
- name: 🚀 Upload Bottles
uses: actions/upload-artifact@v3
if: ${{ env.DRY_RUN == 'false' }}

View file

@ -16,6 +16,7 @@
BUILD_DIR="$PWD/.build"
BOTTLE_DIR="$BUILD_DIR/bottles"
CORE_TAP_PATH="$(brew --repository homebrew/core)"
MAS_VERSION=$(script/version)
ROOT_URL="https://github.com/mas-cli/mas/releases/download/v${MAS_VERSION}"
@ -41,8 +42,8 @@ IFS=" " read -r -a CURRENT_OS_VERSION <<<"$(sw_vers -productVersion | sed 's/\./
CURRENT_OS_VERSION_MAJOR=${CURRENT_OS_VERSION[0]}
CURRENT_OS_VERSION_MINOR=${CURRENT_OS_VERSION[1]}
echo "CURRENT_OS_VERSION_MAJOR: $CURRENT_OS_VERSION_MAJOR"
echo "CURRENT_OS_VERSION_MINOR: $CURRENT_OS_VERSION_MINOR"
echo "CURRENT_OS_VERSION_MAJOR: ${CURRENT_OS_VERSION_MAJOR}"
echo "CURRENT_OS_VERSION_MINOR: ${CURRENT_OS_VERSION_MINOR}"
case "${CURRENT_OS_VERSION_MAJOR}" in
14)
@ -107,23 +108,23 @@ echo "==> 🍼 Bottling mas ${MAS_VERSION} 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
brew bottle --verbose --no-rebuild --root-url="${ROOT_URL}" mas-cli/tap/mas
if ! test -e "${OLD_FILENAME}"; then
echo "Bottle not found: ${OLD_FILENAME}"
echo "If an old version is showing in the log and filename, then make sure the formula has been updated in:"
echo "<BREW_HOME>/Library/Taps/homebrew/homebrew-core"
echo "${CORE_TAP_PATH}"
exit 1
fi
SHA256=$(shasum --algorithm 256 "${OLD_FILENAME}" | cut -f 1 -d ' ' -)
mkdir -p "$BOTTLE_DIR"
mkdir -p "${BOTTLE_DIR}"
# Start of bottle block
BOTTLE_BLOCK=$(
cat <<-EOF
bottle do
root_url "$ROOT_URL"
root_url "${ROOT_URL}"
EOF
)
@ -139,10 +140,10 @@ for os in "${OS_NAMES[@]}"; do
# Append each os
# BOTTLE_BLOCK="$(printf "${BOTTLE_BLOCK}\n sha256 cellar: :any_skip_relocation, %-15s %s" "${os}:" "${SHA256}")"
BOTTLE_BLOCK="$BOTTLE_BLOCK"$(
BOTTLE_BLOCK="${BOTTLE_BLOCK}"$(
cat <<-EOF
sha256 cellar: :any_skip_relocation, $os: "$SHA256"
sha256 cellar: :any_skip_relocation, ${os}: "${SHA256}"
EOF
)
done

View file

@ -1,6 +1,6 @@
#!/bin/bash -e
#
# script/brew_formula_update
# script/brew_core_update
# mas
#
# Updates mas Homebrew core formula:
@ -10,7 +10,9 @@
#
CORE_TAP_PATH="$(brew --repository homebrew/core)"
CORE_FORMULA_PATH="${CORE_TAP_PATH}/Formula"
MAS_TAP_PATH="$(brew --repository mas-cli/tap)"
MAS_TAP_PATH_FORMULA="${MAS_TAP_PATH}/Formula/mas.rb"
CORE_FORMULA_PATH="${CORE_TAP_PATH}/Formula/"
CORE_MAS_FORMULA_PATH="${CORE_FORMULA_PATH}/m/mas.rb"
PROJECT_PATH="$(git rev-parse --show-toplevel)"
@ -175,7 +177,7 @@ if [[ ${status} -ne 0 ]]; then
exit ${status}
fi
pushd "${CORE_FORMULA_PATH}" || exit 2
pushd "${CORE_FORMULA_PATH}"
echo "Updating homebrew/core formula with a PR"
@ -190,6 +192,8 @@ $echo brew bump-formula-pr \
"${dry_run}" \
mas
popd
################################################################################
#
# Create pr on mas-cli/mas
@ -205,3 +209,31 @@ $echo gh pr create \
#
# Create pr on mas-cli/homebrew-tap
#
# Ensure mas is tapped
if ! [[ -d "${MAS_TAP_PATH}" ]]; then
brew tap mas-cli/tap
fi
# Update tap formula version
cp -v "${LOCAL_TAP_FORMULA_PATH}" "${MAS_TAP_PATH_FORMULA}"
pushd "${MAS_TAP_PATH}"
branch_name="releases/release-${MAS_VERSION}"
$echo git branch "${branch_name}"
$echo git switch "${branch_name}"
$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

237
script/brew_tap_update Executable file
View file

@ -0,0 +1,237 @@
#!/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
#
CORE_TAP_PATH="$(brew --repository homebrew/core)"
MAS_TAP_PATH="$(brew --repository mas-cli/tap)"
MAS_TAP_PATH_FORMULA="${MAS_TAP_PATH}/Formula/mas.rb"
CORE_FORMULA_PATH="${CORE_TAP_PATH}/Formula/"
CORE_MAS_FORMULA_PATH="${CORE_FORMULA_PATH}/m/mas.rb"
PROJECT_PATH="$(git rev-parse --show-toplevel)"
SWIFT_PACKAGE="${PROJECT_PATH}/Sources/MasKit/Package.swift"
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 [-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
#
script/version_bump "${MAS_VERSION}" "$REVISION"
branch_name="releases/release-${MAS_VERSION}"
$echo git branch "${branch_name}"
$echo git switch "${branch_name}"
$echo git add \
"${SWIFT_PACKAGE}" \
"${LOCAL_MAS_FORMULA_PATH}" \
"${LOCAL_TAP_FORMULA_PATH}"
$echo git commit --message="🔖 Version ${MAS_VERSION}"
################################################################################
#
# 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
# Ensure core is tapped
if ! [[ -d "${CORE_TAP_PATH}" ]]; then
brew tap homebrew/core
fi
brew update
################################################################################
#
# Build the formula for the current macOS version and architecture.
#
# Update mas formula in core (temporary)
cp -v "${LOCAL_MAS_FORMULA_PATH}" "${CORE_MAS_FORMULA_PATH}"
# Install mas from source
# HOMEBREW_NO_INSTALL_FROM_API:
# Force brew to use the local repository instead of the API.
# Disable API before any install, reinstall or upgrade commands.
HOMEBREW_NO_INSTALL_FROM_API=1 \
brew install mas \
--build-from-source \
--verbose
# Audit formula
brew audit --strict mas
brew style mas
# Revert core formula change after testing
pushd "${CORE_TAP_PATH}"
git diff
git checkout .
popd
################################################################################
#
# Update Homebrew
#
# 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 [[ ${status} -ne 0 ]]; then
echo "Formula did not validate using 'brew bump-formula-pr'"
exit ${status}
fi
pushd "${CORE_FORMULA_PATH}"
echo "Updating homebrew/core formula with a PR"
$echo brew bump-formula-pr \
--tag="${MAS_VERSION}" \
--revision="${REVISION}" \
--commit \
--fork-org mas-cli \
--online \
--strict \
--verbose \
"${dry_run}" \
mas
popd
################################################################################
#
# Create pr on mas-cli/mas
#
$echo gh pr create \
--assignee phatblat \
--base main \
--draft \
--fill
################################################################################
#
# Create pr on mas-cli/homebrew-tap
#
# Ensure mas is tapped
if ! [[ -d "${MAS_TAP_PATH}" ]]; then
brew tap mas-cli/tap
fi
# Update tap formula version
cp -v "${LOCAL_TAP_FORMULA_PATH}" "${MAS_TAP_PATH_FORMULA}"
pushd "${MAS_TAP_PATH}"
branch_name="releases/release-${MAS_VERSION}"
$echo git branch "${branch_name}"
$echo git switch "${branch_name}"
$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

View file

@ -6,13 +6,10 @@
# Displays the current marketing version of mas.
#
# This no longer works with MARKETING_VERSION build setting in Info.plist
# agvtool what-marketing-version -terse1
if git describe >/dev/null 2>&1; then
MAS_VERSION=$(git describe --abbrev=0 --tags 2>/dev/null || true)
else
MAS_VERSION=1.0.0
last_tag=$(git describe --abbrev=0 --tags 2>/dev/null || true)
# Use MAS_VERSION environment varible unless unset
MAS_VERSION=${MAS_VERSION:-$last_tag}
fi
MAS_VERSION=${MAS_VERSION#v}
echo "${MAS_VERSION}"