Skip to content

Commit

Permalink
mac architectures build
Browse files Browse the repository at this point in the history
  • Loading branch information
itroyano committed Apr 3, 2024
1 parent d990640 commit 8c7b755
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: coverage.out

- name: Build Multi-arch
run: make build-multi-arch
- name: Build Multi-arch-linux
run: make build-multi-arch-linux

- name: Build Multi-arch-mac
run: make build-multi-arch-mac
24 changes: 24 additions & 0 deletions .github/workflows/release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,27 @@ jobs:
files: ${{ steps.extract.outputs.destination }}/preflight-${{ matrix.platform }}-${{ matrix.architecture }}
repo-token: ${{ secrets.token }}
release-tag: ${{ inputs.tag }}

# an ugly workaround to build binaries for mac. builds locally and pushes to the release.
add-darwin-bins:
name: Release binaries for MacOS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install system deps
run: 'sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev'
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build Multi-arch-mac
run: make build-multi-arch-mac

- name: Upload binaries to the release
uses: AButler/upload-release-assets@v3.0
id: upload-release-asset
with:
files: preflight-darwin-*
repo-token: ${{ secrets.token }}
release-tag: ${{ inputs.tag }}
30 changes: 23 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,38 @@ IMAGE_REPO?=quay.io/opdev
VERSION=$(shell git rev-parse HEAD)
RELEASE_TAG ?= "0.0.0"

PLATFORMS=linux
ARCHITECTURES=amd64 arm64 ppc64le s390x
PLATFORMS=linux darwin
ARCHITECTURES_LINUX=amd64 arm64 ppc64le s390x
ARCHITECTURES_MAC=amd64 arm64

.PHONY: build
build:
CGO_ENABLED=0 go build -o $(BINARY) -ldflags "-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.commit=$(VERSION) -X github.com/redhat-openshift-ecosystem/openshift-preflight/version.version=$(RELEASE_TAG)" cmd/preflight/main.go
@ls | grep -e '^preflight$$' &> /dev/null

.PHONY: build-multi-arch
build-multi-arch: $(addprefix build-linux-,$(ARCHITECTURES))
.PHONY: build-multi-arch-linux
build-multi-arch-linux: $(addprefix build-linux-,$(ARCHITECTURES_LINUX))

define ARCHITECTURE_template
define LINUX_ARCHITECTURE_template
.PHONY: build-linux-$(1)
build-linux-$(1):
GOOS=linux GOARCH=$(1) CGO_ENABLED=0 go build -o $(BINARY)-linux-$(1) -ldflags "-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.commit=$(VERSION) \
-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.version=$(RELEASE_TAG)" cmd/preflight/main.go
endef

$(foreach arch,$(ARCHITECTURES),$(eval $(call ARCHITECTURE_template,$(arch))))
$(foreach arch,$(ARCHITECTURES_LINUX),$(eval $(call LINUX_ARCHITECTURE_template,$(arch))))

.PHONY: build-multi-arch-mac
build-multi-arch-mac: $(addprefix build-mac-,$(ARCHITECTURES_MAC))

define MAC_ARCHITECTURE_template
.PHONY: build-mac-$(1)
build-mac-$(1):
GOOS=darwin GOARCH=$(1) go build -o $(BINARY)-darwin-$(1) -ldflags "-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.commit=$(VERSION) \
-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.version=$(RELEASE_TAG)" cmd/preflight/main.go
endef

$(foreach arch,$(ARCHITECTURES_MAC),$(eval $(call MAC_ARCHITECTURE_template,$(arch))))

.PHONY: fmt
fmt: gofumpt
Expand Down Expand Up @@ -93,7 +106,10 @@ clean:
$(shell if [ -f "$(BINARY)" ]; then rm -f $(BINARY); fi)
@# cleans all the binaries created by make build-multi-arch
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES),\
$(foreach GOARCH, $(ARCHITECTURES_LINUX),\
$(shell if [ -f "$(BINARY)-$(GOOS)-$(GOARCH)" ]; then rm -f $(BINARY)-$(GOOS)-$(GOARCH); fi)))
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES_MAC),\
$(shell if [ -f "$(BINARY)-$(GOOS)-$(GOARCH)" ]; then rm -f $(BINARY)-$(GOOS)-$(GOARCH); fi)))

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
Expand Down

0 comments on commit 8c7b755

Please sign in to comment.