Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ Homebrew tap for [kgrep](https://github.com/kgrep-org/kgrep) - a CLI for searchi

## Installation

To install kgrep using this tap:
### Latest Version

To install the latest version of kgrep using this tap:

```bash
# Add the tap
brew tap kgrep-org/kgrep

# Install kgrep
# Install kgrep (latest version)
brew install kgrep
```

Expand All @@ -20,6 +22,27 @@ Alternatively, you can install directly without adding the tap:
brew install kgrep-org/kgrep/kgrep
```

### Specific Versions

To install a specific version of kgrep:

```bash
# Add the tap first
brew tap kgrep-org/kgrep

# Install specific version (e.g., v0.4.1)
brew install kgrep@0.4.1

# Or install directly without adding the tap
brew install kgrep-org/kgrep/kgrep@0.4.1
```

To see all available versions:

```bash
brew search kgrep-org/kgrep/
```

## Prerequisites

- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - kgrep requires kubectl to be installed and configured
Expand Down Expand Up @@ -58,11 +81,18 @@ This tap contains the Homebrew formula for kgrep. The formula downloads pre-buil

When a new version of kgrep is released:

1. Update the version number in `kgrep.rb`
2. Update the URLs to point to the new release
3. Update the SHA256 checksums for each platform
4. Test the formula locally
5. Commit and push the changes
1. Run the update script: `./update-formula.sh NEW_VERSION`
2. This will automatically create a versioned formula for the current version (e.g., `kgrep@0.4.2.rb`) before updating to the new version
3. Test both the main and versioned formulas

The script automatically handles:

- Creating versioned formulas for the current version
- Downloading release binaries from GitHub
- Calculating SHA256 checksums for all platforms
- Updating the main formula with the new version

After running the script, you can commit and push the changes as needed.

### Testing Locally

Expand Down
91 changes: 71 additions & 20 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,34 @@ Use the provided script to update the formula:

```bash
cd homebrew-kgrep
./update-formula.sh 0.4.2 # Replace with actual version
./update-formula.sh 0.4.3 # Replace with actual version
```

This script will:
This script automatically:

- Download all platform binaries
- Calculate SHA256 checksums
- Update the formula with the new version and checksums
- Creates a versioned formula for the current version (preserves user choice and compatibility)
- Downloads all platform binaries for the new version
- Calculates SHA256 checksums
- Updates the main formula with the new version and checksums

**Why versioned formulas are automatically created:**
- Users can pin to specific versions for reproducible builds
- Allows parallel installation of multiple versions
- Maintains backward compatibility
- Follows Homebrew best practices (like `node@14`, `python@3.9`)

#### Automatic Versioned Formula Creation

The script automatically:

1. Detects the current version from `kgrep.rb` (e.g., v0.4.2)
2. Creates `kgrep@0.4.2.rb` with the current formula content
3. Updates the class name to `KgrepAT042`
4. Updates `kgrep.rb` to the new version (e.g., v0.4.3)

This allows users to install specific versions:
- `brew install kgrep-org/kgrep/kgrep` (latest version)
- `brew install kgrep-org/kgrep/kgrep@0.4.2` (specific version)

### 3. Test the Formula

Expand All @@ -41,18 +61,12 @@ kgrep version
kgrep --help
```

### 4. Commit and Push

```bash
git add kgrep.rb
git commit -m "Update to v0.4.2"
git push origin main
```

## User Installation

Once the tap is published, users can install kgrep with:

### Latest Version

```bash
# Method 1: Add tap then install
brew tap kgrep-org/kgrep
Expand All @@ -62,6 +76,26 @@ brew install kgrep
brew install kgrep-org/kgrep/kgrep
```

### Specific Versions

```bash
# Add tap first
brew tap kgrep-org/kgrep

# Install specific version
brew install kgrep@0.4.1

# Or install directly
brew install kgrep-org/kgrep/kgrep@0.4.1
```

### List Available Versions

```bash
# Show all available formulas in the tap
brew search kgrep-org/kgrep/
```

## Formula Structure

The `kgrep.rb` formula includes:
Expand Down Expand Up @@ -101,19 +135,36 @@ The GitHub Actions workflow automatically tests:

- **Solution**: Ensure script is executable: `chmod +x update-formula.sh`

## Creating Versioned Formulas for Existing Releases

If you need to create versioned formulas for existing kgrep releases:

```bash
# Create a versioned formula for a specific version
./create-versioned-formula.sh 0.4.1

# This will:
# 1. Download binaries for v0.4.1 from GitHub
# 2. Calculate SHA256 checksums
# 3. Create kgrep@0.4.1.rb with proper checksums
```

## File Structure

```sh
homebrew-kgrep/
├── .github/
│ └── workflows/
│ └── test.yml # CI tests for formula
├── .gitignore # Ignore backup and temp files
├── LICENSE # License file
├── README.md # User-facing documentation
├── SETUP.md # This setup guide
├── kgrep.rb # The Homebrew formula
└── update-formula.sh # Script to update formula
│ └── test.yml # CI tests for formula
├── .gitignore # Ignore backup and temp files
├── LICENSE # License file
├── README.md # User-facing documentation
├── SETUP.md # This setup guide
├── kgrep.rb # The main Homebrew formula (latest version)
├── kgrep@0.4.1.rb # Versioned formula for v0.4.1
├── kgrep@0.4.0.rb # Versioned formula for v0.4.0
├── update-formula.sh # Script to update formula
└── create-versioned-formula.sh # Script to create versioned formulas
```

## Resources
Expand Down
172 changes: 172 additions & 0 deletions create-versioned-formula.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/bin/bash

# Script to create a versioned Homebrew formula for kgrep
# Usage: ./create-versioned-formula.sh VERSION

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}

print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}

print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}

show_usage() {
echo "Usage: $0 VERSION"
echo ""
echo "Creates a versioned Homebrew formula for a specific kgrep release"
echo ""
echo "Example:"
echo " $0 0.4.1 # Create kgrep@0.4.1.rb"
echo ""
echo "NOTE: This script is for creating versioned formulas for existing releases."
echo "For updating to a new version, use: ./update-formula.sh VERSION"
echo ""
echo "This script will:"
echo " 1. Download release binaries from GitHub for the specified version"
echo " 2. Calculate SHA256 checksums"
echo " 3. Create a versioned formula file"
echo ""
}

download_and_hash() {
local version=$1
local platform=$2
local arch=$3
local filename="kgrep-${platform}-${arch}.tar.gz"
local url="https://github.com/kgrep-org/kgrep/releases/download/v${version}/${filename}"

print_status "Downloading ${filename}..." >&2

if ! curl -L -f -o "/tmp/${filename}" "${url}" 2>/dev/null; then
print_error "Failed to download ${filename} from ${url}" >&2
return 1
fi

local sha256=$(shasum -a 256 "/tmp/${filename}" | cut -d' ' -f1)
print_success "Downloaded ${filename}, SHA256: ${sha256}" >&2

# Clean up
rm -f "/tmp/${filename}"

# Return only the clean SHA256 value
printf "%s" "${sha256}"
}

create_versioned_formula() {
local version=$1
local versioned_file="kgrep@${version}.rb"
local class_name="KgrepAT$(echo $version | sed 's/\.//g')"

print_status "Creating versioned formula for v${version}..."

if [[ -f "$versioned_file" ]]; then
print_error "Versioned formula $versioned_file already exists"
exit 1
fi

# Download and get checksums for all platforms
local macos_amd64_sha256=$(download_and_hash "${version}" "macos" "amd64")
local macos_arm64_sha256=$(download_and_hash "${version}" "macos" "arm64")
local linux_amd64_sha256=$(download_and_hash "${version}" "linux" "amd64")
local linux_arm64_sha256=$(download_and_hash "${version}" "linux" "arm64")

if [[ -z "$macos_amd64_sha256" || -z "$macos_arm64_sha256" || -z "$linux_amd64_sha256" || -z "$linux_arm64_sha256" ]]; then
print_error "Failed to download all required binaries"
exit 1
fi

# Create the versioned formula file
cat > "$versioned_file" << EOF
class $class_name < Formula
desc "Search and analyze logs and resources in Kubernetes"
homepage "https://github.com/kgrep-org/kgrep"
license "Apache-2.0"

on_macos do
on_intel do
url "https://github.com/kgrep-org/kgrep/releases/download/v${version}/kgrep-macos-amd64.tar.gz"
sha256 "${macos_amd64_sha256}"
end

on_arm do
url "https://github.com/kgrep-org/kgrep/releases/download/v${version}/kgrep-macos-arm64.tar.gz"
sha256 "${macos_arm64_sha256}"
end
end

on_linux do
on_intel do
url "https://github.com/kgrep-org/kgrep/releases/download/v${version}/kgrep-linux-amd64.tar.gz"
sha256 "${linux_amd64_sha256}"
end

on_arm do
url "https://github.com/kgrep-org/kgrep/releases/download/v${version}/kgrep-linux-arm64.tar.gz"
sha256 "${linux_arm64_sha256}"
end
end

depends_on "kubectl"

def install
bin.install "kgrep"
end

test do
system "#{bin}/kgrep", "version"
assert_match "kgrep", shell_output("#{bin}/kgrep --help")
end
end
EOF

print_success "Created versioned formula: $versioned_file"
print_status " Class name: $class_name"
print_status " Version: v${version}"
print_status " SHA256 checksums:"
echo " macOS AMD64: ${macos_amd64_sha256}"
echo " macOS ARM64: ${macos_arm64_sha256}"
echo " Linux AMD64: ${linux_amd64_sha256}"
echo " Linux ARM64: ${linux_arm64_sha256}"
}

# Main script
if [[ $# -ne 1 ]]; then
print_error "Version argument is required"
show_usage
exit 1
fi

version="$1"

# Validate version format
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
print_error "Invalid version format: $version"
print_error "Use semantic versioning: MAJOR.MINOR.PATCH (e.g., 1.2.0)"
exit 1
fi

print_status "Creating versioned formula for kgrep v${version}"

create_versioned_formula "$version"

print_success "Versioned formula creation completed!"
print_status "File created:"
echo " - $versioned_file"
print_status ""
print_status "Test the formula:"
echo " brew install --formula ./$versioned_file"
echo " kgrep version"
Loading
Loading