Skip to content

Update Homebrew Formula #67

Update Homebrew Formula

Update Homebrew Formula #67

name: Update Homebrew Formula
on:
workflow_dispatch:
inputs:
version:
description: "The version of the mkectl formula to update to"
required: true
permissions:
contents: write
pull-requests: write
jobs:
update-formula:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Latest Release Info
id: release
run: |
echo "version=${{ inputs.version }}" >> "$GITHUB_ENV"
- name: Get SHA256 Checksums
run: |
BASE_URL="https://github.com/MirantisContainers/mke-release/releases/download/v${{ env.version }}"
declare -A assets=(
["mkectl_darwin_x86_64.tar.gz"]="sha256_darwin_x86"
["mkectl_darwin_arm64.tar.gz"]="sha256_darwin_arm64"
["mkectl_linux_x86_64.tar.gz"]="sha256_linux_x86"
)
for asset in "${!assets[@]}"; do
url="$BASE_URL/$asset"
echo "Downloading: $url"
curl -L -o "$asset" "$url" || { echo "Failed to download $asset"; exit 1; }
checksum=$(sha256sum "$asset" | awk '{print $1}')
echo "${assets[$asset]}=$checksum" >> "$GITHUB_ENV"
done
- name: Update Homebrew Formula
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git checkout -b update-mkectl-${{ env.version }}
FORMULA_PATH="Formula/mkectl.rb"
awk '
$0 ~ /VERSION =/ {
$0 = " VERSION = \"${{ env.version }}\".freeze"
}
/sha256/ {
count++
if (count == 1) {
$0 = " sha256 \"${{ env.sha256_darwin_x86 }}\""
} else if (count == 2) {
$0 = " sha256 \"${{ env.sha256_darwin_arm64 }}\""
} else if (count == 3) {
$0 = " sha256 \"${{ env.sha256_linux_x86 }}\""
}
}
{ print }
' "$FORMULA_PATH" > tmp && mv tmp "$FORMULA_PATH"
git push origin update-mkectl-${{ env.version }}
rm mkectl_*.tar.gz
cp $FORMULA_PATH Formula/mkectl@${{ env.version }}.rb
stripped_version=$(echo "${{ env.version }}" | tr -d '.')
sed -i "s/class Mkectl/class MkectlAT${stripped_version}/g" Formula/mkectl@${{ env.version }}.rb
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
title: "Update mkectl formula to ${{ env.version }}"
body: "This PR updates the mkectl formula to version ${{ env.version }}."
branch: update-mkectl-${{ env.version }}
base: main
commit-message: "Update mkectl homebrew formula to ${{ env.version }}"