From 002805390bece63d3c8eff4f8f9cfc17f6660861 Mon Sep 17 00:00:00 2001 From: timflannagan Date: Wed, 12 Jan 2022 22:22:53 -0500 Subject: [PATCH] Update workflows and Makefile to avoid referencing the vendor directory Signed-off-by: timflannagan --- .github/workflows/go.yaml | 17 +++++++++++++--- Makefile | 41 +++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 946e75b54..690f19a4c 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -1,10 +1,10 @@ name: Go on: push: - branches: + branches: - master pull_request: - branches: + branches: - master jobs: build: @@ -18,8 +18,17 @@ jobs: id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: unit-test - run: go test -mod=vendor -v ./... + run: go test -v ./... go-apidiff: name: go-apidiff @@ -31,6 +40,8 @@ jobs: with: go-version: 1.17 id: go + - name: Print out Go env + run: go env - name: Check out code into the Go module directory uses: actions/checkout@v2 with: diff --git a/Makefile b/Makefile index ada005e91..dc5e1f5cf 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,6 @@ endif REPO = github.com/operator-framework/api BUILD_PATH = $(REPO)/cmd/operator-verify PKGS = $(shell go list ./... | grep -v /vendor/) -YQ := go run $(MOD_FLAGS) ./vendor/github.com/mikefarah/yq/v3/ .PHONY: help help: ## Show this help screen @@ -25,7 +24,6 @@ help: ## Show this help screen .PHONY: install install: ## Build & install operator-verify - $(Q)go install \ -gcflags "all=-trimpath=${GOPATH}" \ -asmflags "all=-trimpath=${GOPATH}" \ @@ -35,17 +33,17 @@ install: ## Build & install operator-verify " \ $(BUILD_PATH) +### # Code management. -.PHONY: format tidy clean vendor generate manifests +### +.PHONY: format tidy clean generate manifests format: ## Format the source code $(Q)go fmt $(PKGS) tidy: ## Update dependencies $(Q)go mod tidy -v - -vendor: tidy ## Update vendor directory - $(Q)go mod vendor + $(Q)go mod verify clean: ## Clean up the build artifacts $(Q)rm -rf build @@ -53,7 +51,7 @@ clean: ## Clean up the build artifacts generate: controller-gen ## Generate code $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./... -manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc +manifests: yq controller-gen ## Generate manifests e.g. CRD, RBAC etc @# Create CRDs for new APIs $(CONTROLLER_GEN) crd:crdVersions=v1 output:crd:dir=./crds paths=./pkg/operators/... @@ -88,9 +86,28 @@ test-unit: ## Run the unit tests verify: manifests generate format git diff --exit-code +### # Utilities. -.PHONY: controller-gen - -controller-gen: vendor ## Find or download controller-gen -CONTROLLER_GEN=$(Q)go run -mod=vendor ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen - +### + +# go-get-tool will 'go get' any package $2 and install it to $1. +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) +define go-get-tool +@[ -f $(1) ] || { \ +set -e ;\ +TMP_DIR=$$(mktemp -d) ;\ +cd $$TMP_DIR ;\ +go mod init tmp ;\ +echo "Downloading $(2)" ;\ +GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\ +rm -rf $$TMP_DIR ;\ +} +endef + +CONTROLLER_GEN = $(shell pwd)/bin/controller-gen +controller-gen: ## Download controller-gen locally if necessary. + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0) + +YQ = $(shell pwd)/bin/yq +yq: + $(call go-get-tool,$(YQ),github.com/mikefarah/yq/v3)