Skip to content

Update distribute-binaries.yml #11

Update distribute-binaries.yml

Update distribute-binaries.yml #11

name: Distribute Binaries
on:
push:
tags:
- 'v*' # Trigger the workflow for tags like v1.0, v2.1, etc.
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
if: env.skip != 'true'
uses: actions/checkout@v2
- name: Set up Go
if: env.skip != 'true'
uses: actions/setup-go@v3
with:
go-version: '1.23'
- name: Install build tools
if: env.skip != 'true'
run: |
sudo apt-get update
sudo apt-get install -y gcc g++ libc6-dev gcc-multilib g++-x86-64-linux-gnu libc6-dev-amd64-cross
- name: Get version from tag
id: get_version
run: |
echo "VERSION=$(echo ${GITHUB_REF} | sed 's/refs\/tags\///')" >> $GITHUB_ENV
- name: Get repository name name
id: get_repo_name
run: |
REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f2)
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV
echo "Repository name: ${REPO_NAME}"
- name: Build binaries
if: env.skip != 'true'
run: |
GOOS_ARCH_LIST=(
"windows/amd64" # 64-bit Windows (most Steam users are on Windows)
"windows/386" # 32-bit Windows (for older or lower-end devices)
"linux/amd64" # 64-bit Linux (commonly used by Steam users on Linux)
"linux/386" # 32-bit Linux (for older or low-resource Linux devices)
"darwin/amd64" # 64-bit macOS (used by some Steam users on macOS)
)
VERSION=${{ env.VERSION }}
REPO_NAME=${{ env.REPO_NAME }}
# Create a directory for the build outputs
mkdir -p dist
# Loop through the GOOS and GOARCH combinations and build binaries
for GOOS_ARCH in "${GOOS_ARCH_LIST[@]}"; do
GOOS=$(echo $GOOS_ARCH | cut -d'/' -f1)
GOARCH=$(echo $GOOS_ARCH | cut -d'/' -f2)
# Disable cgo for ARM builds
if [[ "$GOOS" == "windows" ]]; then
export CGO_ENABLED=0
else
export CGO_ENABLED=1
fi
# Set environment variables
export GOOS
export GOARCH
# Standardize binary OS name
FILENAME_GOOS=$GOOS
if [[ "$GOOS" == "darwin" ]]; then
FILENAME_GOOS=mac
fi
# Standardize binary architecture
FILENAME_GOARCH=$GOARCH
if [[ "$GOARCH" == "amd64" ]]; then
FILENAME_GOARCH=x64
fi
if [[ "$GOARCH" == "386" ]]; then
FILENAME_GOARCH=x32
fi
# Construct the filename
FILENAME="${REPO_NAME}-${VERSION}-${FILENAME_GOOS}-${FILENAME_GOARCH}"
if [[ "$GOOS" == "windows" ]]; then
FILENAME="${FILENAME}.exe"
fi
# Build the binary with the required format and ldflags for version, name, arch, and goos
go build -ldflags "-X main.name=${REPO_NAME} -X main.version=${VERSION} -X main.arch=${GOARCH} -X main.goos=${GOOS} -X main.file=${FILENAME}" -o "dist/${FILENAME}"
echo "Built binary: ${FILENAME}"
done
- name: Upload binaries to release
uses: softprops/action-gh-release@v1
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}