Skip to content

Commit

Permalink
Update build-and-upload-binaries.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
bearaujus committed Dec 7, 2024
1 parent 280f07c commit dc45945
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions .github/workflows/build-and-upload-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout the code
- name: Checkout code
Expand All @@ -26,44 +25,59 @@ jobs:
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 bearaujus/steam-utils)
# 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
# Install dependencies for cgo (for android, aix, etc.)
- name: Install dependencies for cgo (if needed)
run: |
sudo apt-get update
sudo apt-get install -y gcc libc6-dev
# Build binaries for all GOOS and GOARCH combinations
# Build binaries only if tag is new
- name: Build binaries
if: env.skip != 'true'
run: |
# List of GOOS and GOARCH combinations
GOOS_ARCH_LIST=$(go tool dist list)
# 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
for GOOS_ARCH in "${GOOS_ARCH_LIST[@]}"; do
GOOS=$(echo $GOOS_ARCH | cut -d'/' -f1)
GOARCH=$(echo $GOOS_ARCH | cut -d'/' -f2)
# Skip problematic platforms if necessary (e.g., AIX or others)
if [[ "$GOOS" == "aix" && "$GOARCH" == "ppc64" ]]; then
echo "Skipping aix/ppc64 due to unsupported platform"
continue
fi
# Enable cgo for all builds
export CGO_ENABLED=1
# Set environment variables
export GOOS
export GOARCH
export CGO_ENABLED=1
# Build the binary with the required format and ldflags for version, name, arch, and goos
FILENAME="${REPO_NAME}-${VERSION}-${GOOS}-${GOARCH}"
go build -ldflags "-X main.name=${REPO_NAME} -X main.version=${VERSION} -X main.arch=${GOARCH} -X main.goos=${GOOS}" -o "binaries/${FILENAME}"
echo "Built binary: ${FILENAME}"
done
Expand Down

0 comments on commit dc45945

Please sign in to comment.