From 01c7a8cd0dec66f0397866ece4c28062f4fd9269 Mon Sep 17 00:00:00 2001 From: David Norton Date: Sun, 1 Mar 2026 20:07:31 -0600 Subject: [PATCH 1/2] Add Homebrew tap support - Create formula at platformersdev/homebrew-tap - Add CI step to auto-update the formula on each release - Add Homebrew install instructions to README The CI step requires a HOMEBREW_TAP_TOKEN secret with repo access to platformersdev/homebrew-tap. If the secret is not set, the step is skipped gracefully. closes #66 Made-with: Cursor --- .github/workflows/ci.yml | 68 ++++++++++++++++++++++++++++++++++++++++ README.md | 6 ++++ 2 files changed, 74 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2e60ae..5ab38bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -128,3 +128,71 @@ jobs: gh release create v0.0.${{ github.run_number }} release/* \ --title "Release v0.0.${{ github.run_number }}" \ --generate-notes + + - name: Update Homebrew tap + if: ${{ secrets.HOMEBREW_TAP_TOKEN != '' }} + env: + GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} + run: | + VERSION="0.0.${{ github.run_number }}" + SHA_DARWIN_ARM64=$(shasum -a 256 release/kubectl-x-darwin-arm64 | cut -d' ' -f1) + SHA_DARWIN_AMD64=$(shasum -a 256 release/kubectl-x-darwin-amd64 | cut -d' ' -f1) + SHA_LINUX_AMD64=$(shasum -a 256 release/kubectl-x-linux-amd64 | cut -d' ' -f1) + + cat > /tmp/kubectl-x.rb << FORMULA + class KubectlX < Formula + desc "kubectl plugin that runs commands against every context in parallel" + homepage "https://github.com/platformersdev/kubectl-x" + version "${VERSION}" + license "MIT" + + on_macos do + if Hardware::CPU.arm? + url "https://github.com/platformersdev/kubectl-x/releases/download/v${VERSION}/kubectl-x-darwin-arm64" + sha256 "${SHA_DARWIN_ARM64}" + else + url "https://github.com/platformersdev/kubectl-x/releases/download/v${VERSION}/kubectl-x-darwin-amd64" + sha256 "${SHA_DARWIN_AMD64}" + end + end + + on_linux do + if Hardware::CPU.arm? + odie "kubectl-x is not available for Linux ARM" + else + url "https://github.com/platformersdev/kubectl-x/releases/download/v${VERSION}/kubectl-x-linux-amd64" + sha256 "${SHA_LINUX_AMD64}" + end + end + + depends_on "kubernetes-cli" + + def install + binary = Dir.glob("kubectl-x-*").first || "kubectl-x" + bin.install binary => "kubectl-x" + end + + test do + assert_match "kubectl x", shell_output("#{bin}/kubectl-x --help") + end + end + FORMULA + + # Remove leading whitespace from heredoc + sed -i 's/^ //' /tmp/kubectl-x.rb + + CONTENT=$(base64 -w 0 /tmp/kubectl-x.rb) + SHA=$(gh api repos/platformersdev/homebrew-tap/contents/Formula/kubectl-x.rb --jq '.sha' 2>/dev/null || echo "") + + if [ -n "$SHA" ]; then + gh api repos/platformersdev/homebrew-tap/contents/Formula/kubectl-x.rb \ + -X PUT \ + -f message="Update kubectl-x to v${VERSION}" \ + -f content="$CONTENT" \ + -f sha="$SHA" + else + gh api repos/platformersdev/homebrew-tap/contents/Formula/kubectl-x.rb \ + -X PUT \ + -f message="Add kubectl-x v${VERSION}" \ + -f content="$CONTENT" + fi diff --git a/README.md b/README.md index 3975640..3252271 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,12 @@ The authors of this project do not intend to support write operations (`apply`, ## Installation +### Homebrew + +```bash +brew install platformersdev/tap/kubectl-x +``` + ### Download a release Download the latest binary for your platform from the [releases page](https://github.com/platformersdev/kubectl-x/releases/latest), then place it in your `$PATH`: From fd5dca3156e7f37b800cb98a4b8862123ee622ab Mon Sep 17 00:00:00 2001 From: David Norton Date: Sun, 1 Mar 2026 20:29:02 -0600 Subject: [PATCH 2/2] Use deploy key via environment secret for Homebrew tap updates Replace the PAT-based GitHub API approach with a deploy key that clones and pushes to the tap repo over SSH. The key is stored as HOMEBREW_TAP_DEPLOY_KEY in a "homebrew" GitHub environment. Made-with: Cursor --- .github/workflows/ci.yml | 60 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ab38bb..308d22f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,17 +129,42 @@ jobs: --title "Release v0.0.${{ github.run_number }}" \ --generate-notes - - name: Update Homebrew tap - if: ${{ secrets.HOMEBREW_TAP_TOKEN != '' }} - env: - GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} + update-homebrew: + needs: release + runs-on: ubuntu-latest + environment: homebrew + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + merge-multiple: false + + - name: Prepare binaries + run: | + mkdir -p release + find artifacts -name "kubectl-x-*" -type f -exec cp {} release/ \; + + - name: Set up deploy key + run: | + mkdir -p ~/.ssh + echo "${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + ssh-keyscan github.com >> ~/.ssh/known_hosts + + - name: Update Homebrew formula run: | VERSION="0.0.${{ github.run_number }}" SHA_DARWIN_ARM64=$(shasum -a 256 release/kubectl-x-darwin-arm64 | cut -d' ' -f1) SHA_DARWIN_AMD64=$(shasum -a 256 release/kubectl-x-darwin-amd64 | cut -d' ' -f1) SHA_LINUX_AMD64=$(shasum -a 256 release/kubectl-x-linux-amd64 | cut -d' ' -f1) - cat > /tmp/kubectl-x.rb << FORMULA + git clone git@github.com:platformersdev/homebrew-tap.git /tmp/homebrew-tap + cd /tmp/homebrew-tap + + cat > Formula/kubectl-x.rb << FORMULA class KubectlX < Formula desc "kubectl plugin that runs commands against every context in parallel" homepage "https://github.com/platformersdev/kubectl-x" @@ -178,21 +203,10 @@ jobs: end FORMULA - # Remove leading whitespace from heredoc - sed -i 's/^ //' /tmp/kubectl-x.rb - - CONTENT=$(base64 -w 0 /tmp/kubectl-x.rb) - SHA=$(gh api repos/platformersdev/homebrew-tap/contents/Formula/kubectl-x.rb --jq '.sha' 2>/dev/null || echo "") - - if [ -n "$SHA" ]; then - gh api repos/platformersdev/homebrew-tap/contents/Formula/kubectl-x.rb \ - -X PUT \ - -f message="Update kubectl-x to v${VERSION}" \ - -f content="$CONTENT" \ - -f sha="$SHA" - else - gh api repos/platformersdev/homebrew-tap/contents/Formula/kubectl-x.rb \ - -X PUT \ - -f message="Add kubectl-x v${VERSION}" \ - -f content="$CONTENT" - fi + sed -i 's/^ //' Formula/kubectl-x.rb + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add Formula/kubectl-x.rb + git commit -m "Update kubectl-x to v${VERSION}" + git push