Files
at-container-registry/scripts/update-homebrew-formula.sh
2025-11-02 22:11:19 -06:00

111 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# update-homebrew-formula.sh - Helper script to update Homebrew formula with new release
#
# Usage: ./scripts/update-homebrew-formula.sh <version>
#
# Example: ./scripts/update-homebrew-formula.sh v0.0.2
#
# This script:
# 1. Downloads the source tarball from GitHub
# 2. Calculates SHA256 checksum
# 3. Generates updated formula snippet
#
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check arguments
if [ $# -ne 1 ]; then
echo -e "${RED}Error: Missing required argument${NC}"
echo "Usage: $0 <version>"
echo ""
echo "Example: $0 v0.0.2"
echo " $0 0.0.2 (v prefix is optional)"
exit 1
fi
VERSION="$1"
# Add 'v' prefix if not present
if [[ ! "$VERSION" =~ ^v ]]; then
VERSION="v${VERSION}"
fi
echo -e "${GREEN}Updating Homebrew formula for version ${VERSION}${NC}"
echo ""
# GitHub repository details
GITHUB_REPO="atcr-io/atcr"
TARBALL_URL="https://github.com/${GITHUB_REPO}/archive/refs/tags/${VERSION}.tar.gz"
# Create temporary directory
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_DIR"' EXIT
TARBALL_FILE="${TEMP_DIR}/${VERSION}.tar.gz"
echo -e "${YELLOW}Downloading source tarball...${NC}"
echo "URL: ${TARBALL_URL}"
if curl -sSfL -o "$TARBALL_FILE" "$TARBALL_URL"; then
# Calculate SHA256
if command -v sha256sum &> /dev/null; then
CHECKSUM=$(sha256sum "$TARBALL_FILE" | awk '{print $1}')
elif command -v shasum &> /dev/null; then
CHECKSUM=$(shasum -a 256 "$TARBALL_FILE" | awk '{print $1}')
else
echo -e "${RED}Error: sha256sum or shasum command not found${NC}"
exit 1
fi
echo -e "${GREEN}✓ Downloaded successfully${NC}"
echo "SHA256: $CHECKSUM"
else
echo -e "${RED}✗ Failed to download source tarball${NC}"
echo ""
echo "Make sure the tag ${VERSION} exists on GitHub:"
echo " https://github.com/${GITHUB_REPO}/releases/tag/${VERSION}"
echo ""
echo "If you haven't pushed the tag yet, run:"
echo " git tag ${VERSION}"
echo " git push origin ${VERSION}"
exit 1
fi
echo ""
echo "======================================================================"
echo "Copy the following to Formula/docker-credential-atcr.rb:"
echo "======================================================================"
echo ""
cat << EOF
url "https://github.com/${GITHUB_REPO}/archive/refs/tags/${VERSION}.tar.gz"
sha256 "${CHECKSUM}"
license "MIT"
head "https://github.com/${GITHUB_REPO}.git", branch: "main"
EOF
echo ""
echo "======================================================================"
echo ""
echo -e "${YELLOW}Next steps:${NC}"
echo "1. Update Formula/docker-credential-atcr.rb with the url and sha256 above"
echo "2. Test the formula locally:"
echo " brew install --build-from-source Formula/docker-credential-atcr.rb"
echo " docker-credential-atcr version"
echo "3. Commit and push to your atcr-io/homebrew-tap repository:"
echo " cd /path/to/homebrew-tap"
echo " cp Formula/docker-credential-atcr.rb ."
echo " git add docker-credential-atcr.rb"
echo " git commit -m \"Update docker-credential-atcr to ${VERSION}\""
echo " git push"
echo "4. Users can upgrade with:"
echo " brew update"
echo " brew upgrade docker-credential-atcr"