From 4a9e1447f0d014cafbd39edee403370c7ed5d090 Mon Sep 17 00:00:00 2001 From: Sam Nelson Date: Sat, 8 Feb 2025 11:10:43 -0700 Subject: [PATCH] Disable default cross-compile for OSX and use MacOS github runner for automated builds --- .github/workflows/release.yml | 29 ++++++++++++++++++++++++++--- build.sh | 29 ++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 330b0b4..517cb6b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ permissions: contents: write jobs: - release: + all-release: name: Release pushed tag runs-on: ubuntu-latest steps: @@ -24,7 +24,7 @@ jobs: go-version-file: 'go.mod' - name: Run cross-compile script - run: ./build.sh github.com/sanelson/gopim + run: ./build.sh github.com/sanelson/gopim all - name: Create release env: @@ -35,8 +35,31 @@ jobs: --repo="$GITHUB_REPOSITORY" \ --title="${tag}" \ --generate-notes \ - gopim-darwin-amd64 \ gopim-linux-amd64 \ gopim-windows-386.exe \ gopim-windows-amd64.exe + osx-release: + name: Release pushed tag + runs-on: macos-latest + steps: + - name: Checkout repository @ Tag + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Run native OSX build + run: ./build.sh github.com/sanelson/gopim darwin/amd64 + + - name: Upload OSX binary to release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref_name }} + run: | + gh release upload "$tag" \ + --repo="$GITHUB_REPOSITORY" \ + gopim-darwin-amd64 + diff --git a/build.sh b/build.sh index 0cf6d54..7cc265e 100755 --- a/build.sh +++ b/build.sh @@ -2,25 +2,48 @@ package=$1 if [[ -z "$package" ]]; then - echo "usage: $0 " + echo "usage: $0 " exit 1 fi +platform_name=$2 package_split=(${package//\// }) package_name=${package_split[-1]} platforms=("windows/amd64" "windows/386" "darwin/amd64" "linux/amd64") +# Default platform is current platform +# Otherwise, build for all platforms if "all" is specified +if [[ -z "$platform_name" ]]; then + platform_name="$(go env GOOS)/$(go env GOARCH)" +elif [[ "$platform_name" == "darwin/amd64" ]]; then + if [[ $(go env GOOS) != "darwin" ]]; then + echo "Cross-compiling for darwin/amd64 is no longer supported" + exit 1 + fi +fi + for platform in "${platforms[@]}" do + # Check if platform is specified + if [[ "$platform_name" != "all" && "$platform" != "$platform_name" ]]; then + continue + fi platform_split=(${platform//\// }) GOOS=${platform_split[0]} GOARCH=${platform_split[1]} + CGO_ENABLED=0 output_name=$package_name'-'$GOOS'-'$GOARCH if [ $GOOS = "windows" ]; then output_name+='.exe' - fi + elif [ $GOOS = "darwin" ]; then + # Enable CGO for darwin/amd64 and only try to compile all platforms if on OSX + if [[ $(go env GOOS) != "darwin" ]]; then + continue + fi + CGO_ENABLED=1 + fi - env GOOS=$GOOS GOARCH=$GOARCH go build \ + env CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GOARCH=$GOARCH go build \ -ldflags="-X main.version=$(git describe --tags)" \ -o $output_name $package if [ $? -ne 0 ]; then