Skip to content

Update mkectl formula to v4.0.0 #72

Update mkectl formula to v4.0.0

Update mkectl formula to v4.0.0 #72

Workflow file for this run

name: Upload bottles
on:
pull_request:
types: [ labeled ]
permissions:
contents: write
pull-requests: write
jobs:
upload-bottle:
if: ${{ github.event.label.name == 'bottle' }}
strategy:
max-parallel: 1
matrix:
os: [ ubuntu-22.04, macos-13, macos-14 ]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Load environment variables on Linux
if: ${{ matrix.os == 'ubuntu-22.04' }}
uses: c-py/action-dotenv-to-setenv@v4
with:
env-file: .github/development.env
- name: Load environment variables on macOS
if: ${{ matrix.os != 'ubuntu-22.04' }}
run: |
set -a
source .github/development.env
echo "K0SCTL_TAP_COMMIT=${K0SCTL_TAP_COMMIT}" >> "$GITHUB_ENV"
echo "KUBECTL_VER=${KUBECTL_VER}" >> "$GITHUB_ENV"
set +a
- name: Get Version Info
run: |
VERSION=$(grep 'VERSION = ' Formula/mkectl.rb | sed 's/VERSION = "\(.*\)".freeze/\1/' | sed 's/^[[:space:]]*//')
echo "version=${VERSION}" >> "$GITHUB_ENV"
- name: Install dependencies
run: |
brew install kubernetes-cli@${{ env.KUBECTL_VER }}
brew tap k0sproject/tap
cd "$(brew --repo k0sproject/tap)"
git fetch origin
git checkout ${{ env.K0SCTL_TAP_COMMIT }}
- name: Build the Homebrew bottle
run: |
rm -f mkectl--*.tar.gz
brew install --build-bottle mkectl
brew bottle mkectl
bottle_file=$(ls -1 mkectl--*.tar.gz | head -n 1)
corrected_bottle_file="${bottle_file/.1.tar.gz/.tar.gz}"
corrected_bottle_file=$(echo "$corrected_bottle_file" | sed 's/--/-/')
mv "$bottle_file" "$corrected_bottle_file"
echo "bottle_path=$(pwd)/$corrected_bottle_file" >> "$GITHUB_ENV"
- name: Create a GitHub Release (if not existing)
run: |
TAG="mkectl-${{ env.version }}"
RELEASE_EXISTS=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/tags/${TAG} | jq -r '.id')
if [ "$RELEASE_EXISTS" == "null" ]; then
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "{\"tag_name\":\"${TAG}\", \"name\":\"${TAG}\"}" \
https://api.github.com/repos/${{ github.repository }}/releases
fi
echo "Waiting for the release to become available..."
until [ "$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/tags/${TAG} | jq -r '.id')" != "null" ]; do
echo "Release not available yet. Retrying in 10 seconds..."
sleep 10
done
echo "Release ${TAG} is now available."
- name: Upload the Bottle to GitHub Release
run: |
echo "Uploading bottle: ${{ env.bottle_path }}"
TAG="mkectl-${{ env.version }}"
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-F "file=@${{ env.bottle_path }}" \
"https://uploads.github.com/repos/${{ github.repository }}/releases/$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/tags/${TAG} | jq -r '.id')/assets?name=$(basename ${{ env.bottle_path }})"
- name: Update Homebrew Formula
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git config pull.ff only
git checkout update-mkectl-${{ env.version }}
git pull
FORMULA_PATH="Formula/mkectl.rb"
if command -v sha256sum > /dev/null; then
checksum=$(sha256sum "${{ env.bottle_path }}" | awk '{print $1}')
else
checksum=$(shasum -a 256 "${{ env.bottle_path }}" | awk '{print $1}')
fi
echo "checksum is $checksum"
awk -v matrixos="${{ matrix.os }}" -v checksum="$checksum" '
/bottle do/ {
in_bottle_block = 1
print
next
}
in_bottle_block && /sha256/ {
if ($0 ~ /ventura/ && matrixos == "macos-13") {
$0 = " sha256 cellar: :any_skip_relocation, ventura: \"" checksum "\""
} else if ($0 ~ /arm64_sonoma/ && matrixos == "macos-14") {
$0 = " sha256 cellar: :any_skip_relocation, arm64_sonoma: \"" checksum "\""
} else if ($0 ~ /x86_64_linux/ && matrixos == "ubuntu-22.04") {
$0 = " sha256 cellar: :any_skip_relocation, x86_64_linux: \"" checksum "\""
}
}
{ print }
' "$FORMULA_PATH" > tmp && mv tmp "$FORMULA_PATH"
cat $FORMULA_PATH
cp $FORMULA_PATH Formula/mkectl@${{ env.version }}.rb
stripped_version=$(echo "${{ env.version }}" | tr -d '.')
if [ "${{ matrix.os }}" == "ubuntu-22.04" ]; then
sed -i "s/class Mkectl/class MkectlAT${stripped_version}/g" Formula/mkectl@${{ env.version }}.rb
else
sed -i '' "s/class Mkectl/class MkectlAT${stripped_version}/g" Formula/mkectl@${{ env.version }}.rb
fi
rm -f ${{ env.bottle_path }}
git add $FORMULA_PATH
git add Formula/mkectl@${{ env.version }}.rb
git commit -m "Update bottle for ${{ matrix.os }} to ${{ env.version }}"
git push origin update-mkectl-${{ env.version }}
trigger-tests-dispatch:
needs: upload-bottle
run: |
curl --request POST \
--url https://api.github.com/repos/Mirantis/homebrew-tap/actions/workflows/tests.yml/dispatches \
--header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
--header "Content-Type: application/json" \
--data '{"ref": "${{ github.event.pull_request.head.ref }}", "inputs": {"checkout_ref": "${{ github.sha }}"}}'