Skip to content

feature: add build and release workflow for automated binary compilat… #3

feature: add build and release workflow for automated binary compilat…

feature: add build and release workflow for automated binary compilat… #3

name: Build and Release
on:
workflow_dispatch:
push:
tags:
- 'v*.*.*' # Trigger on tags matching vX.X.X
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.19'
- name: Build binaries
env:
PROJECT_NAME: ecutils
CODEVERSION: ${{ github.ref_name }} # Get the version from the tag
CODEBUILDREVISION: ${{ github.sha }}
run: |
# Define the build date
BUILDDATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
PKG="$PROJECT_NAME"
TARGETS=(
"linux/386"
"linux/amd64"
"linux/arm"
"linux/arm64"
"windows/386"
"windows/amd64"
"darwin/amd64"
)
mkdir -p "dist/$CODEBUILDREVISION"
for target in "${TARGETS[@]}"; do
IFS='/' read -r -a parts <<< "$target"
GOOS="${parts[0]}"
GOARCH="${parts[1]}"
EXTENSION=""
if [[ "$GOOS" == "windows" ]]; then
EXTENSION=".exe"
fi
echo " > Building binary for $GOOS/$GOARCH..."
GOOS="$GOOS" GOARCH="$GOARCH" BUILDDATE="$BUILDDATE" CODEBUILDREVISION="$CODEBUILDREVISION" \
go build -v -ldflags "-X main.GOOS=$GOOS -X main.GOARCH=$GOARCH -X main.CODEVERSION=$CODEVERSION -X main.CODEBUILDDATE=$BUILDDATE -X main.CODEBUILDREVISION=$CODEBUILDREVISION" \
-o "dist/$CODEBUILDREVISION/${PROJECT_NAME}-${GOOS}-${GOARCH}${EXTENSION}" cmd/main.go
done
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
files: |
dist/${{ github.sha }}/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}