Skip to content

Commit

Permalink
Update workflows and Makefile to avoid referencing the vendor directory
Browse files Browse the repository at this point in the history
Signed-off-by: timflannagan <timflannagan@gmail.com>
  • Loading branch information
timflannagan committed Jan 21, 2022
1 parent e03e7fb commit 0028053
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/go.yaml
@@ -1,10 +1,10 @@
name: Go
on:
push:
branches:
branches:
- master
pull_request:
branches:
branches:
- master
jobs:
build:
Expand All @@ -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
Expand All @@ -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:
Expand Down
41 changes: 29 additions & 12 deletions Makefile
Expand Up @@ -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
Expand All @@ -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}" \
Expand All @@ -35,25 +33,25 @@ 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

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/...

Expand Down Expand Up @@ -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)

0 comments on commit 0028053

Please sign in to comment.