From 8c7b755354c616506eb493541b1b58e57b2ef38e Mon Sep 17 00:00:00 2001 From: Igor Troyanovsky Date: Mon, 3 Apr 2023 18:21:18 +0300 Subject: [PATCH] mac architectures build --- .github/workflows/go.yml | 7 ++++-- .github/workflows/release-artifacts.yml | 24 ++++++++++++++++++++ Makefile | 30 +++++++++++++++++++------ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 490ecf31..55ee66c8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml index 0d33df45..77682fc7 100644 --- a/.github/workflows/release-artifacts.yml +++ b/.github/workflows/release-artifacts.yml @@ -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 }} diff --git a/Makefile b/Makefile index 75564247..a9ce400f 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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