Skip to content

fix: set up SSH deploy key inline without third-party action #22

fix: set up SSH deploy key inline without third-party action

fix: set up SSH deploy key inline without third-party action #22

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
jobs:
goreleaser:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
with:
go-version-file: go.mod
- uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.2.1
with:
version: ~> v2
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
homebrew:
runs-on: ubuntu-latest
needs: goreleaser
steps:
- name: Update Homebrew formula
env:
TAG: ${{ github.ref_name }}
HOMEBREW_TAP_DEPLOY_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}
run: |
VERSION="${TAG#v}"
BASE_URL="https://github.com/serpapi/serpapi-cli/releases/download/${TAG}"
# Fetch checksums
CHECKSUMS=$(curl -fsSL "${BASE_URL}/serpapi_${VERSION}_checksums.txt")
get_sha() {
echo "$CHECKSUMS" | grep "$1" | awk '{print $1}'
}
SHA_DARWIN_AMD64=$(get_sha "serpapi_${VERSION}_darwin_amd64.tar.gz")
SHA_DARWIN_ARM64=$(get_sha "serpapi_${VERSION}_darwin_arm64.tar.gz")
SHA_LINUX_AMD64=$(get_sha "serpapi_${VERSION}_linux_amd64.tar.gz")
SHA_LINUX_ARM64=$(get_sha "serpapi_${VERSION}_linux_arm64.tar.gz")
cat > /tmp/serpapi-cli.rb <<FORMULA
class SerpapiCli < Formula
desc "HTTP client for structured web search data via SerpApi"
homepage "https://serpapi.com"
version "${VERSION}"
license "MIT"
on_macos do
if Hardware::CPU.arm?
url "${BASE_URL}/serpapi_${VERSION}_darwin_arm64.tar.gz"
sha256 "${SHA_DARWIN_ARM64}"
else
url "${BASE_URL}/serpapi_${VERSION}_darwin_amd64.tar.gz"
sha256 "${SHA_DARWIN_AMD64}"
end
end
on_linux do
if Hardware::CPU.arm?
url "${BASE_URL}/serpapi_${VERSION}_linux_arm64.tar.gz"
sha256 "${SHA_LINUX_ARM64}"
else
url "${BASE_URL}/serpapi_${VERSION}_linux_amd64.tar.gz"
sha256 "${SHA_LINUX_AMD64}"
end
end
def install
bin.install "serpapi"
end
test do
assert_match version.to_s, shell_output("#{bin}/serpapi --version")
assert_match "search", shell_output("#{bin}/serpapi --help")
assert_match "No API key", shell_output("#{bin}/serpapi account 2>&1", 2)
assert_match "No API key", shell_output("#{bin}/serpapi archive abc123 2>&1", 2)
assert_match "Invalid archive ID", shell_output("#{bin}/serpapi --api-key x archive ../bad 2>&1", 2)
end
end
FORMULA
# Set up SSH with deploy key
mkdir -p ~/.ssh
echo "$HOMEBREW_TAP_DEPLOY_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan github.com >> ~/.ssh/known_hosts
export GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key -o IdentitiesOnly=yes"
# Clone, update formula, push
git clone git@github.com:serpapi/homebrew-tap.git
cp /tmp/serpapi-cli.rb homebrew-tap/Formula/serpapi-cli.rb
cd homebrew-tap
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add Formula/serpapi-cli.rb
git commit -m "serpapi-cli ${VERSION}"
git push