feat: patch for initial feature implementation (#3) #13
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Upload Binaries on Tag | |
on: | |
push: | |
tags: | |
- 'v*' # Trigger the workflow for tags like v1.0, v2.1, etc. | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# Set up Go environment | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: '1.23' | |
# Install necessary build tools for cgo | |
- name: Install build tools for cgo | |
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 | |
# Install necessary build tools for cgo | |
- name: Install build tools for cgo | |
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 | |
# Get the version from the tag | |
- name: Get version from tag | |
id: get_version | |
run: | | |
echo "VERSION=$(echo ${GITHUB_REF} | sed 's/refs\/tags\///')" >> $GITHUB_ENV | |
# Get the repository name from the GitHub context (e.g., steam-utils from github.com/bearaujus/steam-utils) | |
- name: Get repo 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}" | |
# Build binaries only if tag is new | |
- name: Build binaries | |
if: env.skip != 'true' | |
run: | | |
# Define a specific list of GOOS and GOARCH combinations | |
GOOS_ARCH_LIST=( | |
"windows/386" | |
"windows/amd64" | |
"windows/arm" | |
"windows/arm64" | |
"linux/386" | |
"linux/amd64" | |
"linux/arm" | |
"linux/arm64" | |
"darwin/amd64" | |
"darwin/arm64" | |
) | |
VERSION=${{ env.VERSION }} | |
REPO_NAME=${{ env.REPO_NAME }} | |
# Create a directory for the build outputs | |
mkdir -p binaries | |
# 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 [[ "$GOARCH" == "arm" || "$GOARCH" == "arm64" || "$GOOS" == "windows" ]]; then | |
export CGO_ENABLED=0 | |
else | |
export CGO_ENABLED=1 | |
fi | |
# Set environment variables | |
export GOOS | |
export GOARCH | |
# Construct the filename and add .exe for Windows | |
FILENAME="${REPO_NAME}-${VERSION}-${GOOS}-${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 "binaries/${FILENAME}" | |
echo "Built binary: ${FILENAME}" | |
done | |
# Upload binaries to GitHub Releases | |
- name: Upload binaries to release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: binaries/* | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |