Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac architectures build #942

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
26 changes: 26 additions & 0 deletions .github/workflows/release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,29 @@ 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: Set Env Tags
run: echo RELEASE_TAG=$(echo $GITHUB_REF | cut -d '/' -f 3) >> $GITHUB_ENV

- 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