git commit -m "feat: add GoReleaser for automated releases and Homebrew integration

- Replace manual GitHub Actions workflow
- Add automated Formula updates to homebrew-sshm tap
- Support pre-releases with auto-detection
- Standardize cross-platform binary distribution"
This commit is contained in:
Gu1llaum-3 2025-09-17 14:14:49 +02:00
parent ed6ea2939a
commit 0975ae2fe2
4 changed files with 219 additions and 136 deletions

View File

@ -1,136 +0,0 @@
name: Build Binaries
on:
push:
tags:
- '*'
release:
types: [created]
workflow_dispatch:
permissions:
contents: write
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Linux AMD64
- goos: linux
goarch: amd64
suffix: linux-amd64
# Linux ARM64
- goos: linux
goarch: arm64
suffix: linux-arm64
# macOS AMD64 (Intel)
- goos: darwin
goarch: amd64
suffix: darwin-amd64
# macOS ARM64 (Apple Silicon)
- goos: darwin
goarch: arm64
suffix: darwin-arm64
# Windows AMD64
- goos: windows
goarch: amd64
suffix: windows-amd64
# Windows ARM64
- goos: windows
goarch: arm64
suffix: windows-arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
mkdir -p dist
VERSION=${GITHUB_REF#refs/tags/}
# Remove 'v' prefix if present for version injection
VERSION_CLEAN=${VERSION#v}
if [ "${{ matrix.goos }}" = "windows" ]; then
go build -ldflags="-s -w -X github.com/Gu1llaum-3/sshm/cmd.AppVersion=${VERSION_CLEAN}" -o dist/sshm-${{ matrix.suffix }}.exe .
else
go build -ldflags="-s -w -X github.com/Gu1llaum-3/sshm/cmd.AppVersion=${VERSION_CLEAN}" -o dist/sshm-${{ matrix.suffix }} .
fi
- name: Create archive
run: |
cd dist
if [ "${{ matrix.goos }}" = "windows" ]; then
zip sshm-${{ matrix.suffix }}.zip sshm-${{ matrix.suffix }}.exe
rm sshm-${{ matrix.suffix }}.exe
else
tar -czf sshm-${{ matrix.suffix }}.tar.gz sshm-${{ matrix.suffix }}
rm sshm-${{ matrix.suffix }}
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: sshm-${{ matrix.suffix }}
path: |
dist/sshm-${{ matrix.suffix }}.tar.gz
dist/sshm-${{ matrix.suffix }}.zip
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
merge-multiple: true
- name: Prepare release assets
run: |
mkdir -p release
find ./artifacts -name "*.tar.gz" -exec cp {} ./release/ \;
find ./artifacts -name "*.zip" -exec cp {} ./release/ \;
ls -la ./release/
- name: Check if pre-release
id: check_prerelease
run: |
if [[ "${GITHUB_REF#refs/tags/}" == *"-beta"* ]] || [[ "${GITHUB_REF#refs/tags/}" == *"-alpha"* ]] || [[ "${GITHUB_REF#refs/tags/}" == *"-rc"* ]] || [[ "${GITHUB_REF#refs/tags/}" == *"-dev"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: ./release/*
draft: false
prerelease: ${{ steps.check_prerelease.outputs.is_prerelease }}
generate_release_notes: true
name: ${{ github.ref_name }}${{ steps.check_prerelease.outputs.is_prerelease == 'true' && ' (Pre-release)' || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

39
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: Release with GoReleaser
on:
push:
tags:
- '*'
permissions:
contents: write
# Required for Homebrew tap updates
issues: write
pull-requests: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Fetch full history for changelog generation
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Token for updating Homebrew tap (create this secret in your repo settings)
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}

136
.goreleaser.yaml Normal file
View File

@ -0,0 +1,136 @@
version: 2
project_name: sshm
before:
hooks:
- go mod tidy
- go test ./...
builds:
- id: sshm
main: ./main.go
binary: sshm
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- "386"
- arm
ignore:
# Skip ARM for Windows (not commonly used)
- goos: windows
goarch: arm
- goos: windows
goarch: arm64
env:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X github.com/Gu1llaum-3/sshm/cmd.AppVersion={{.Version}}
flags:
- -trimpath
archives:
- id: sshm
formats: [ "tar.gz" ]
# Use zip for Windows
format_overrides:
- goos: windows
formats: [ "zip" ]
# Template for archive name
name_template: >-
{{ .ProjectName }}_ {{- title .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- LICENSE
- README.md
checksum:
name_template: "checksums.txt"
algorithm: sha256
changelog:
use: github
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^ci:"
- "^chore:"
- "^build:"
groups:
- title: Features
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 0
- title: Bug fixes
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 1
- title: Others
order: 999
# Homebrew tap configuration (Formula pour CLI)
brews:
- name: sshm
repository:
owner: Gu1llaum-3
name: homebrew-sshm
# Token with repo permissions for your homebrew-sshm repo
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
commit_author:
name: goreleaserbot
email: bot@goreleaser.com
commit_msg_template: "Brew formula update for {{ .ProjectName }} version {{ .Tag }}"
homepage: "https://github.com/Gu1llaum-3/sshm"
description: "A modern SSH connection manager for your terminal"
license: MIT
skip_upload: auto
# Test command to verify installation
test: |
system "#{bin}/sshm --version"
# Release configuration
release:
github:
owner: Gu1llaum-3
name: sshm
prerelease: auto
draft: false
replace_existing_draft: true
target_commitish: "{{ .Commit }}"
discussion_category_name: General
name_template: "{{.ProjectName}} {{.Version}}"
header: |
## SSHM {{.Version}}
Thank you for downloading SSHM!
### Installation
**Homebrew (macOS/Linux):**
```bash
brew tap Gu1llaum-3/sshm
brew install sshm
```
**Manual Installation:**
Download the appropriate binary for your platform from the assets below.
footer: |
## Full Changelog
See all changes at https://github.com/Gu1llaum-3/sshm/compare/{{.PreviousTag}}...{{.Tag}}
---
Released with ❤️ by [GoReleaser](https://github.com/goreleaser/goreleaser)
# Snapshot builds (for non-tag builds)
snapshot:
version_template: "{{ .Tag }}-snapshot-{{.ShortCommit}}"
# Metadata for package managers
metadata:
mod_timestamp: "{{ .CommitTimestamp }}"

44
Makefile Normal file
View File

@ -0,0 +1,44 @@
.PHONY: build build-local test clean release snapshot
# Version can be overridden via environment variable or command line
VERSION ?= dev
# Go build flags
LDFLAGS := -s -w -X github.com/Gu1llaum-3/sshm/cmd.AppVersion=$(VERSION)
# Build with specific version
build:
@mkdir -p dist
go build -ldflags="$(LDFLAGS)" -o dist/sshm .
# Build with git version
build-local: VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
build-local: build
# Run tests
test:
go test ./...
# Clean build artifacts
clean:
rm -rf dist
# Release with GoReleaser (requires tag)
release:
@if [ -z "$(shell git tag --points-at HEAD)" ]; then \
echo "Error: No git tag found at current commit. Create a tag first with: git tag vX.Y.Z"; \
exit 1; \
fi
goreleaser release --clean
# Build snapshot (without tag)
snapshot:
goreleaser release --snapshot --clean
# Check GoReleaser config
release-check:
goreleaser check
# Run GoReleaser in dry-run mode
release-dry-run:
goreleaser release --snapshot --skip=publish --clean