Skip to content

Instantly share code, notes, and snippets.

@davidecavestro
Created August 12, 2024 16:51
Show Gist options
  • Save davidecavestro/07b63a1e6d2c8a29ff3acff8361ed886 to your computer and use it in GitHub Desktop.
Save davidecavestro/07b63a1e6d2c8a29ff3acff8361ed886 to your computer and use it in GitHub Desktop.
Simple workflow to locally test GH action for building golang binaries using https://github.com/nektos/act
name: builder
on:
push:
branches:
- master
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Install dependencies
run: go get .
- name: Get repository and git ref
id: vars
run: |
echo "REPO_NAME=$(basename $GITHUB_REPOSITORY)" >> $GITHUB_ENV
echo "GIT_REF=$(echo $GITHUB_REF_NAME | sed 's/\//-/g')" >> $GITHUB_ENV
- name: Build binaries for multiple platforms
run: |
# List of OS and architecture combinations
targets=("windows/amd64" "linux/amd64" "darwin/amd64")
# Loop through each target and build the binary
for target in "${targets[@]}"; do
os=$(echo $target | cut -d'/' -f1)
arch=$(echo $target | cut -d'/' -f2)
binary_name="${REPO_NAME}_${GIT_REF}_${os}_${arch}"
if [ "$os" == "windows" ]; then
binary_name="${binary_name}.exe"
fi
echo "Building for $os/$arch..."
env GOOS=$os GOARCH=$arch go build -o ./output/${binary_name}
done
- name: list binaries
run: ls -lha ./output/*
@rogosprojects
Copy link

I'm OK with that manual action.

But, with the matrix approach, you should publish (or update if exists) the release each time an asset is built.
This will cause the first email/notification with just one asset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment