Skip to content

Commit

Permalink
add GitHub Actions workflows for building and releasing binaries and …
Browse files Browse the repository at this point in the history
…updating Docker image CI triggers
  • Loading branch information
KingPin committed Feb 28, 2025
1 parent 4c0660a commit aff6b54
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 5 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/binary-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build and Release FanOut

on:
push:
tags:
- 'v*' # Trigger on any tag starting with 'v'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21' # Use Go 1.21 or later

- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV

- name: Build for multiple platforms
run: |
mkdir -p dist
# Build for Linux (amd64)
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w -X main.Version=$VERSION" -o dist/fanout-linux-amd64
# Build for Linux (arm64)
GOOS=linux GOARCH=arm64 go build -trimpath -ldflags="-s -w -X main.Version=$VERSION" -o dist/fanout-linux-arm64
# Build for Linux (armv7)
GOOS=linux GOARCH=arm GOARM=7 go build -trimpath -ldflags="-s -w -X main.Version=$VERSION" -o dist/fanout-linux-armv7
# Build for macOS (amd64)
GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags="-s -w -X main.Version=$VERSION" -o dist/fanout-darwin-amd64
# Build for macOS (arm64 - Apple Silicon)
GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags="-s -w -X main.Version=$VERSION" -o dist/fanout-darwin-arm64
# Build for Windows
GOOS=windows GOARCH=amd64 go build -trimpath -ldflags="-s -w -X main.Version=$VERSION" -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 }}
13 changes: 8 additions & 5 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: Docker Image CI

on:
# push:
# branches: [ "main" ]
# pull_request:
# branches: [ "main" ]
push:
branches: [ "main" ]
tags:
- 'v*' # Add trigger for version tags
pull_request:
branches: [ "main" ]
workflow_dispatch:

env:
Expand Down Expand Up @@ -45,6 +47,7 @@ jobs:
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=,suffix=,format=short
Expand All @@ -53,7 +56,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down

0 comments on commit aff6b54

Please sign in to comment.