Skip to content

Commit

Permalink
♻️ Split workflow into 4 jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
phatblat committed Mar 11, 2024
1 parent 87a0074 commit c0950b1
Show file tree
Hide file tree
Showing 5 changed files with 328 additions and 19 deletions.
46 changes: 44 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -22,7 +22,7 @@ on:
release:
types: [published]
jobs:
release:
debug-event:
runs-on: macos-14
steps:

Expand All @@ -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
Expand All @@ -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' }}
Expand All @@ -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' }}
Expand Down
17 changes: 9 additions & 8 deletions script/bottle
Expand Up @@ -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}"

Expand All @@ -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)
Expand Down Expand Up @@ -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
)

Expand All @@ -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
Expand Down
38 changes: 35 additions & 3 deletions script/brew_formula_update → script/brew_core_update
@@ -1,6 +1,6 @@
#!/bin/bash -e
#
# script/brew_formula_update
# script/brew_core_update
# mas
#
# Updates mas Homebrew core formula:
Expand All @@ -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)"
Expand Down Expand Up @@ -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"

Expand All @@ -190,6 +192,8 @@ $echo brew bump-formula-pr \
"${dry_run}" \
mas

popd

################################################################################
#
# Create pr on mas-cli/mas
Expand All @@ -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

0 comments on commit c0950b1

Please sign in to comment.