name: Homebrew Tap Sync
on:
release:
types: [published, prereleased]
workflow_dispatch:
inputs:
tag:
description: "Release tag to sync (e.g. v0.1.2-beta). Optional on release event."
required: false
type: string
tap_repo:
description: "Tap repository in owner/repo form"
required: false
default: "amaduswaray/homebrew-tap"
type: string
permissions:
contents: read
jobs:
sync:
runs-on: ubuntu-latest
env:
RELEASE_TAG_EVENT: ${{ github.event.release.tag_name }}
RELEASE_TAG_INPUT: ${{ github.event.inputs.tag }}
TAP_REPO_INPUT: ${{ github.event.inputs.tap_repo }}
DEFAULT_TAP_REPO: amaduswaray/homebrew-tap
TAP_PUSH_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
steps:
- name: Resolve release tag and tap repo
id: vars
shell: bash
run: |
set -euo pipefail
TAG="${RELEASE_TAG_EVENT:-}"
if [[ -z "$TAG" ]]; then
TAG="${RELEASE_TAG_INPUT:-}"
fi
if [[ -z "$TAG" ]]; then
echo "No release tag provided. Use release event or pass workflow input 'tag'." >&2
exit 1
fi
if [[ ! "$TAG" =~ ^v ]]; then
echo "Tag must start with 'v' (got: $TAG)" >&2
exit 1
fi
TAP_REPO="${TAP_REPO_INPUT:-$DEFAULT_TAP_REPO}"
if [[ -z "$TAP_REPO" ]]; then
echo "Tap repo cannot be empty" >&2
exit 1
fi
VERSION="${TAG#v}"
BASE_URL="https://github.com/amaduswaray/ShellQL/releases/download/${TAG}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tap_repo=$TAP_REPO" >> "$GITHUB_OUTPUT"
echo "linux_url=${BASE_URL}/shql-linux-x86_64" >> "$GITHUB_OUTPUT"
echo "macos_arm_url=${BASE_URL}/shql-macos-arm64" >> "$GITHUB_OUTPUT"
- name: Validate token availability
shell: bash
run: |
set -euo pipefail
if [[ -z "${TAP_PUSH_TOKEN}" ]]; then
echo "Missing secret: HOMEBREW_TAP_GITHUB_TOKEN" >&2
echo "Create a PAT with access to the tap repo and add it as this repository secret." >&2
exit 1
fi
- name: Download release binaries and compute sha256
id: sha
shell: bash
run: |
set -euo pipefail
curl -sSLf "${{ steps.vars.outputs.linux_url }}" -o shql-linux-x86_64
curl -sSLf "${{ steps.vars.outputs.macos_arm_url }}" -o shql-macos-arm64
LINUX_SHA256="$(sha256sum shql-linux-x86_64 | awk '{print $1}')"
MACOS_ARM_SHA256="$(sha256sum shql-macos-arm64 | awk '{print $1}')"
echo "linux_sha256=$LINUX_SHA256" >> "$GITHUB_OUTPUT"
echo "macos_arm_sha256=$MACOS_ARM_SHA256" >> "$GITHUB_OUTPUT"
- name: Generate formula (prebuilt binaries; no Rust toolchain dependency)
shell: bash
run: |
set -euo pipefail
cat > shellql.rb <<EOF
class Shellql < Formula
desc "Vim- and tmux-inspired terminal database manager for developers"
homepage "https://github.com/amaduswaray/ShellQL"
version "${{ steps.vars.outputs.version }}"
license "MIT"
on_macos do
on_arm do
url "${{ steps.vars.outputs.macos_arm_url }}"
sha256 "${{ steps.sha.outputs.macos_arm_sha256 }}"
end
end
on_linux do
on_intel do
url "${{ steps.vars.outputs.linux_url }}"
sha256 "${{ steps.sha.outputs.linux_sha256 }}"
end
end
def install
if OS.mac? && Hardware::CPU.arm?
bin.install "shql-macos-arm64" => "shql"
elsif OS.linux? && Hardware::CPU.intel?
bin.install "shql-linux-x86_64" => "shql"
else
odie "Unsupported platform for shellql"
end
end
test do
assert_match "ShellQL", shell_output("#{bin}/shql --help")
end
end
EOF
- name: Clone tap repository
shell: bash
run: |
set -euo pipefail
git clone "https://x-access-token:${TAP_PUSH_TOKEN}@github.com/${{ steps.vars.outputs.tap_repo }}.git" tap-repo
- name: Update formula in tap repository
shell: bash
run: |
set -euo pipefail
mkdir -p tap-repo/Formula
cp shellql.rb tap-repo/Formula/shellql.rb
cd tap-repo
if git diff --quiet -- Formula/shellql.rb; then
echo "No formula changes detected; nothing to commit."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/shellql.rb
git commit -m "shellql ${{ steps.vars.outputs.version }}"
git push