From d73fb5a4130bef4b4d6494e30d17b3b11a454d36 Mon Sep 17 00:00:00 2001 From: Walt Chen Date: Sun, 5 Jan 2025 16:48:36 -0500 Subject: [PATCH] windows build with .exe extension --- .github/workflows/go.yml | 6 ++--- .github/workflows/release.yml | 50 +++++++++++++++++++++++++++++++++++ Makefile | 12 +++++++-- 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 255fc77..29c6fea 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,7 +14,7 @@ jobs: build: strategy: matrix: - os: [ubuntu, windows, darwin] + os: [ubuntu-latest, windows-latest, MacOS-latest] go: [1.22] runs-on: ${{ matrix.os }} steps: @@ -27,11 +27,11 @@ jobs: - name: Build run: | - make build OS=${{ matrix.os }} ARCH=amd64 + make build ARCH=amd64 - name: Test run: | - if [[ "${{ matrix.os }}" == "windows" ]]; then + if [[ "${{ matrix.os }}" == "windows-latest" ]]; then echo "Skip gofmt check on windows" else gofmt -d */*.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5faac1a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +name: Build and Release Binaries + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - os: linux + arch: amd64 + extension: "" + - os: linux + arch: arm64 + extension: "" + - os: darwin + arch: amd64 + extension: "" + - os: darwin + arch: arm64 + extension: "" + - os: windows + arch: amd64 + extension: ".exe" + - os: windows + arch: arm64 + extension: ".exe" + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '>=1.22' + - name: Build binaries + run: | + make build OS=${{ matrix.os }} ARCH=${{ matrix.arch }} + - name: Upload release assets + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: bin + asset_name: | + beanstalk-cli.${{ matrix.os }}.${{ matrix.arch }}${{ matrix.extension }} + asset_content_type: application/octet-stream diff --git a/Makefile b/Makefile index a286d05..665c293 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,13 @@ ifndef GOARCH MACHINE=$(shell uname -m) ifeq ($(MACHINE), x86_64) GOARCH := amd64 + GOEXT := else ifeq ($(MACHINE), i386) GOARCH := i386 + GOEXT := else ifeq ($(MACHINE), arm) GOARCH := arm64 + GOEXT := .exe endif endif # Set build targets based on OS @@ -26,9 +29,11 @@ GO_BUILD := $(GO) build $(EXTRA_FLAGS) -ldflags "$(LDFLAGS_COMMON)" .PHONY: all build: beanstalk-cli + mkdir -p bin + cp -f $< bin/$<.$(GOARCH).$(GOOS)$(GOEXT) beanstalk-cli: cmd/main.go cmd/functions.go - GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO_BUILD) -o $@.$(GOARCH).$(GOOS) $^ + GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO_BUILD) -o $@ $^ format: gofmt -w */*.go @@ -36,4 +41,7 @@ format: .PHONY: all clean: - rm -rf beanstalk-cli.* + rm -rf beanstalk-cli + +superclean: clean + rm -rf bin/