diff --git a/.core/release.yaml b/.core/release.yaml index 8cf8680..9362f1d 100644 --- a/.core/release.yaml +++ b/.core/release.yaml @@ -24,6 +24,9 @@ publishers: - type: github prerelease: false draft: false + - type: homebrew + tap: host-uk/homebrew-tap + formula: core changelog: include: diff --git a/.github/workflows/alpha-release.yml b/.github/workflows/alpha-release.yml index a5b2441..b41eb22 100644 --- a/.github/workflows/alpha-release.yml +++ b/.github/workflows/alpha-release.yml @@ -58,20 +58,37 @@ jobs: run: | EXT="" if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi - go build -o "./bin/core${EXT}" . + BINARY="core${EXT}" + ARCHIVE_PREFIX="core-${GOOS}-${GOARCH}" + + go build -ldflags "-s -w" -o "./bin/${BINARY}" . + + # Create tar.gz for Homebrew (non-Windows) + if [ "$GOOS" != "windows" ]; then + tar czf "./bin/${ARCHIVE_PREFIX}.tar.gz" -C ./bin "${BINARY}" + fi + + # Rename raw binary to platform-specific name for release + mv "./bin/${BINARY}" "./bin/${ARCHIVE_PREFIX}${EXT}" - name: Upload artifact uses: actions/upload-artifact@v4 with: name: core-${{ matrix.goos }}-${{ matrix.goarch }} - path: ./bin/core* + path: ./bin/core-* release: needs: build runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} steps: - uses: actions/checkout@v6 + - name: Set version + id: version + run: echo "version=v${{ env.NEXT_VERSION }}-alpha.${{ github.run_number }}" >> "$GITHUB_OUTPUT" + - name: Download artifacts uses: actions/download-artifact@v7 with: @@ -87,9 +104,8 @@ jobs: - name: Create alpha release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ steps.version.outputs.version }} run: | - VERSION="v${{ env.NEXT_VERSION }}-alpha.${{ github.run_number }}" - gh release create "$VERSION" \ --title "Alpha: $VERSION" \ --notes "Canary build from dev branch. @@ -110,7 +126,10 @@ jobs: ## Installation \`\`\`bash - # macOS/Linux + # Homebrew (macOS/Linux) + brew install host-uk/tap/core + + # Direct download (example: Linux amd64) curl -fsSL https://github.com/host-uk/core/releases/download/$VERSION/core-linux-amd64 -o core chmod +x core && sudo mv core /usr/local/bin/ \`\`\` @@ -118,3 +137,84 @@ jobs: --prerelease \ --target dev \ release/* + + update-tap: + needs: release + runs-on: ubuntu-latest + steps: + - name: Download artifacts + uses: actions/download-artifact@v7 + with: + path: dist + merge-multiple: true + + - name: Generate checksums + run: | + cd dist + for f in *.tar.gz; do + sha256sum "$f" | awk '{print $1}' > "${f}.sha256" + done + echo "=== Checksums ===" + cat *.sha256 + + - name: Update Homebrew formula + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ needs.release.outputs.version }} + run: | + # Strip leading 'v' for formula version + FORMULA_VERSION="${VERSION#v}" + + # Read checksums + DARWIN_ARM64=$(cat dist/core-darwin-arm64.tar.gz.sha256) + LINUX_AMD64=$(cat dist/core-linux-amd64.tar.gz.sha256) + LINUX_ARM64=$(cat dist/core-linux-arm64.tar.gz.sha256) + + # Clone tap repo + gh repo clone host-uk/homebrew-tap /tmp/tap -- --depth=1 + mkdir -p /tmp/tap/Formula + + # Write formula + cat > /tmp/tap/Formula/core.rb << FORMULA + # typed: false + # frozen_string_literal: true + + class Core < Formula + desc "Host UK development CLI" + homepage "https://github.com/host-uk/core" + version "${FORMULA_VERSION}" + license "EUPL-1.2" + + on_macos do + url "https://github.com/host-uk/core/releases/download/${VERSION}/core-darwin-arm64.tar.gz" + sha256 "${DARWIN_ARM64}" + end + + on_linux do + if Hardware::CPU.arm? + url "https://github.com/host-uk/core/releases/download/${VERSION}/core-linux-arm64.tar.gz" + sha256 "${LINUX_ARM64}" + else + url "https://github.com/host-uk/core/releases/download/${VERSION}/core-linux-amd64.tar.gz" + sha256 "${LINUX_AMD64}" + end + end + + def install + bin.install "core" + end + + test do + system "\#{bin}/core", "--version" + end + end + FORMULA + + # Remove leading whitespace from heredoc + sed -i 's/^ //' /tmp/tap/Formula/core.rb + + cd /tmp/tap + git add . + git diff --cached --quiet && echo "No changes to tap" && exit 0 + git commit -m "Update core to ${FORMULA_VERSION}" + git push diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 173e7c8..5add9d4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,13 +53,24 @@ jobs: run: | EXT="" if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi - go build -o "./bin/core${EXT}" . + BINARY="core${EXT}" + ARCHIVE_PREFIX="core-${GOOS}-${GOARCH}" + + go build -ldflags "-s -w" -o "./bin/${BINARY}" . + + # Create tar.gz for Homebrew (non-Windows) + if [ "$GOOS" != "windows" ]; then + tar czf "./bin/${ARCHIVE_PREFIX}.tar.gz" -C ./bin "${BINARY}" + fi + + # Rename raw binary to platform-specific name for release + mv "./bin/${BINARY}" "./bin/${ARCHIVE_PREFIX}${EXT}" - name: Upload artifact uses: actions/upload-artifact@v4 with: name: core-${{ matrix.goos }}-${{ matrix.goarch }} - path: ./bin/core* + path: ./bin/core-* release: needs: build