Skip to content

chore: simplify GitHub Actions build workflow by limiting OS matrix t… #7

chore: simplify GitHub Actions build workflow by limiting OS matrix t…

chore: simplify GitHub Actions build workflow by limiting OS matrix t… #7

Workflow file for this run

name: Build and Publish Golang Binary
on:
push:
branches: [ main, develop ]
tags: [ 'v*' ]
pull_request:
branches: [ main, develop ]
env:
BINARY_NAME: upgrade-test
jobs:
# Build and publish Golang binary
build:
name: Build and Publish Binary
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
go-version: [1.24.0]
arch: [amd64, arm64]
permissions:
contents: read
actions: write
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Build binary
env:
GOOS: ${{ matrix.os == 'ubuntu-latest' && 'linux' || matrix.os == 'windows-latest' && 'windows' || 'darwin' }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
run: |
# Set binary extension based on OS
if [ "${{ matrix.os }}" = "windows-latest" ]; then
EXT=".exe"
else
EXT=""
fi
# Build the binary
go build -ldflags="-s -w -X main.version=${{ github.ref_name }} -X main.commit=${{ github.sha }} -X main.date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
-o "dist/${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}$EXT" \
.
# Create checksum file
if [ "${{ matrix.os }}" = "windows-latest" ]; then
sha256sum "dist/${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}$EXT" > "dist/${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}$EXT.sha256"
else
shasum -a 256 "dist/${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}$EXT" > "dist/${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}$EXT.sha256"
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.os }}-${{ matrix.arch }}
path: dist/
retention-days: 30
# Create release
release:
name: Create Release
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
actions: read
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist/
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
draft: false
prerelease: false
generate_release_notes: true