Update Homebrew Formula #73
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
actions: 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 | |
sed -i "/rebuild [0-9]\+/d" "Formula/mkectl@${{ env.version }}.rb" | |
- name: Create Pull Request | |
id: create-pr | |
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 }}" | |
- name: Trigger tests dispatch | |
run: | | |
curl --request POST \ | |
--url https://api.github.com/repos/${{ github.repository }}/actions/workflows/tests.yml/dispatches \ | |
--header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
--header "Content-Type: application/json" \ | |
--data '{"ref": "${{ steps.create-pr.outputs.pull-request-branch }}", "inputs": {"checkout_ref": "${{ steps.create-pr.outputs.pull-request-head-sha }}"}}' | |