Build and Release FanOut #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release FanOut | |
on: | |
push: | |
tags: | |
- 'v*' # Trigger on any tag starting with 'v' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # This is required for creating releases | |
packages: write # This is needed if you're also pushing to GHCR | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for proper versioning | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.24' | |
- name: Extract version info | |
id: version_info | |
run: | | |
# Extract version from tag (without 'v' prefix) | |
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV | |
# Get commit hash | |
echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
# Generate build timestamp | |
echo "TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV | |
- name: Run unit tests | |
run: | | |
go mod download | |
go test -v ./... | |
- name: Build for multiple platforms | |
run: | | |
mkdir -p dist | |
FLAGS="-s -w -X main.Version=$VERSION -X main.GitCommit=$COMMIT -X main.BuildTime=$TIMESTAMP" | |
# Build for Linux (amd64) | |
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="$FLAGS" -o dist/fanout-linux-amd64 | |
# Build for Linux (arm64) | |
GOOS=linux GOARCH=arm64 go build -trimpath -ldflags="$FLAGS" -o dist/fanout-linux-arm64 | |
# Build for Linux (armv7) | |
GOOS=linux GOARCH=arm GOARM=7 go build -trimpath -ldflags="$FLAGS" -o dist/fanout-linux-armv7 | |
# Build for macOS (amd64) | |
GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags="$FLAGS" -o dist/fanout-darwin-amd64 | |
# Build for macOS (arm64 - Apple Silicon) | |
GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags="$FLAGS" -o dist/fanout-darwin-arm64 | |
# Build for Windows | |
GOOS=windows GOARCH=amd64 go build -trimpath -ldflags="$FLAGS" -o dist/fanout-windows-amd64.exe | |
# Create checksums | |
cd dist && sha256sum * > checksums.txt | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
dist/fanout-linux-amd64 | |
dist/fanout-linux-arm64 | |
dist/fanout-linux-armv7 | |
dist/fanout-darwin-amd64 | |
dist/fanout-darwin-arm64 | |
dist/fanout-windows-amd64.exe | |
dist/checksums.txt | |
draft: false | |
prerelease: false | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
docker: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
tags: | | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=raw,value=latest | |
- name: Build and push container | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |