Skip to content

Commit

Permalink
using new build pattern for multi-arch builds on GHA.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Jun 26, 2022
1 parent 8b0152b commit 23d42d0
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 37 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@ env:

jobs:

build:
name: Build
test:
name: Test
runs-on: ubuntu-latest
container: ghcr.io/packagrio/packagr:latest-golang
env:
PROJECT_PATH: /go/src/github.com/analogj/hatchet
CGO_ENABLED: 1
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Test
run: |
mkdir -p $(dirname "$PROJECT_PATH")
cp -a $GITHUB_WORKSPACE $PROJECT_PATH
cd $PROJECT_PATH
go mod vendor
go test -race -coverprofile=coverage.txt -covermode=atomic -v -tags "static" $(go list ./... | grep -v /vendor/)
make clean test-coverage
docker:
name: Docker
Expand Down
90 changes: 64 additions & 26 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ on:
default: 'pkg/version/version.go'

jobs:
build:
name: Build
release:
name: Create Release
runs-on: ubuntu-latest
container: ghcr.io/packagrio/packagr:latest-golang
env:
PROJECT_PATH: /go/src/github.com/analogj/hatchet
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -34,38 +32,78 @@ jobs:
version_metadata_path: ${{ github.event.inputs.version_metadata_path }}
- name: Test
run: |
mkdir -p $(dirname "$PROJECT_PATH")
cp -a $GITHUB_WORKSPACE $PROJECT_PATH
cd $PROJECT_PATH
go mod vendor
go test -v -tags "static" $(go list ./... | grep -v /vendor/)
- name: Build Binaries
run: |
cd $PROJECT_PATH
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.goos=darwin -X main.goarch=amd64" -o hatchet-darwin-amd64 -tags "static" $(go list ./cmd/...)
chmod +x hatchet-darwin-amd64
GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.goos=darwin -X main.goarch=arm64" -o hatchet-darwin-arm64 -tags "static" $(go list ./cmd/...)
chmod +x hatchet-darwin-arm64
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.goos=linux -X main.goarch=amd64" -o hatchet-linux-amd64 -tags "static" $(go list ./cmd/...)
chmod +x hatchet-linux-amd64
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.goos=windows -X main.goarch=amd64" -o hatchet-windows-amd64.exe -tags "static" $(go list ./cmd/...)
# restore modified dir to GH workspace.
cp -arf $PROJECT_PATH/. $GITHUB_WORKSPACE/
make clean test
- name: Commit Changes
id: commit
uses: packagrio/action-releasr-go@master
env:
# This is necessary in order to push a commit to the repo
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
build:
name: Build ${{ matrix.cfg.goos }}/${{ matrix.cfg.goarch }}
runs-on: ${{ matrix.cfg.on }}
env:
GOOS: ${{ matrix.cfg.goos }}
GOARCH: ${{ matrix.cfg.goarch }}
GOARM: ${{ matrix.cfg.goarm }}
strategy:
matrix:
cfg:
- { on: ubuntu-latest, goos: linux, goarch: amd64 }
- { on: ubuntu-latest, goos: linux, goarch: arm, goarm: 5 }
- { on: ubuntu-latest, goos: linux, goarch: arm, goarm: 6 }
- { on: ubuntu-latest, goos: linux, goarch: arm, goarm: 7 }
- { on: ubuntu-latest, goos: linux, goarch: arm64 }
- { on: macos-latest, goos: darwin, goarch: amd64 }
- { on: macos-latest, goos: darwin, goarch: arm64 }
- { on: macos-latest, goos: freebsd, goarch: amd64 }
- { on: macos-latest, goos: freebsd, goarch: arm64 }
- { on: windows-latest, goos: windows, goarch: amd64 }
- { on: windows-latest, goos: windows, goarch: arm64 }
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.18.3' # The Go version to download (if necessary) and use.
- name: Build
run: |
make clean build
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: hatchet
path: hatchet-${{ matrix.cfg.goos }}-${{ matrix.cfg.goarch }}*
retention-days: 1
release-binaries:
name: Release Binaries
needs: build
runs-on: ubuntu-latest
steps:
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: hatchet
- name: List
shell: bash
run: |
ls -alt
- name: Publish Release
id: publish
uses: packagrio/action-publishr-go@master
env:
# This is necessary in order to push a commit to the repo
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
with:
upload_assets: 'hatchet-darwin-amd64 hatchet-darwin-arm64 hatchet-linux-amd64 hatchet-windows-amd64.exe'
upload_assets: |
hatchet-linux-amd64
hatchet-linux-arm-5
hatchet-linux-arm-6
hatchet-linux-arm-7
hatchet-linux-arm64
hatchet-darwin-amd64
hatchet-darwin-arm64
hatchet-freebsd-amd64
hatchet-freebsd-arm64
hatchet-windows-amd64.exe
hatchet-windows-arm64.exe
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.ONESHELL: # Applies to every targets in the file! .ONESHELL instructs make to invoke a single instance of the shell and provide it with the entire recipe, regardless of how many lines it contains.

########################################################################################################################
# Global Env Settings
########################################################################################################################
BINARY_NAME = hatchet
LD_FLAGS =
ifdef STATIC
LD_FLAGS := $(LD_FLAGS) -extldflags=-static
endif
ifdef GOOS
BINARY_NAME := $(BINARY_NAME)-$(GOOS)
LD_FLAGS := $(LD_FLAGS) -X main.goos=$(GOOS)
endif
ifdef GOARCH
BINARY_NAME := $(BINARY_NAME)-$(GOARCH)
LD_FLAGS := $(LD_FLAGS) -X main.goarch=$(GOARCH)
endif
ifdef GOARM
BINARY_NAME := $(BINARY_NAME)-$(GOARM)
endif
ifeq ($(OS),Windows_NT)
BINARY_NAME := $(BINARY_NAME).exe
endif

########################################################################################################################
# Binary
########################################################################################################################
.PHONY: all
all: build

.PHONY: clean
clean:
go clean

.PHONY: generate
generate: dep
go generate ./...

.PHONY: dep
dep:
go mod vendor

.PHONY: test
test: dep
go test -v -tags "static" ./...

.PHONY: test-coverage
test-coverage: dep
go test -race -coverprofile=coverage.txt -covermode=atomic -v -tags "static" ./...

.PHONY: build
build: dep
go build -ldflags "$(LD_FLAGS)" -o $(BINARY_NAME) -tags "static" ./cmd/hatchet
ifneq ($(OS),Windows_NT)
chmod +x $(BINARY_NAME)
file $(BINARY_NAME) || true
ldd $(BINARY_NAME) || true
./$(BINARY_NAME) || true
endif

########################################################################################################################
# Docker
########################################################################################################################

0 comments on commit 23d42d0

Please sign in to comment.