Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:
contents: write

jobs:
release:
all-release:
name: Release pushed tag
runs-on: ubuntu-latest
steps:
Expand All @@ -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:
Expand All @@ -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

29 changes: 26 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,48 @@

package=$1
if [[ -z "$package" ]]; then
echo "usage: $0 <package-name>"
echo "usage: $0 <package-name> <platform-name>"
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
Expand Down
Loading