Skip to content

Commit 0028053

Browse files
committed
Update workflows and Makefile to avoid referencing the vendor directory
Signed-off-by: timflannagan <[email protected]>
1 parent e03e7fb commit 0028053

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

.github/workflows/go.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: Go
22
on:
33
push:
4-
branches:
4+
branches:
55
- master
66
pull_request:
7-
branches:
7+
branches:
88
- master
99
jobs:
1010
build:
@@ -18,8 +18,17 @@ jobs:
1818
id: go
1919
- name: Check out code into the Go module directory
2020
uses: actions/checkout@v2
21+
- name: Cache dependencies
22+
uses: actions/cache@v2
23+
with:
24+
path: |
25+
~/.cache/go-build
26+
~/go/pkg/mod
27+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
28+
restore-keys: |
29+
${{ runner.os }}-go-
2130
- name: unit-test
22-
run: go test -mod=vendor -v ./...
31+
run: go test -v ./...
2332

2433
go-apidiff:
2534
name: go-apidiff
@@ -31,6 +40,8 @@ jobs:
3140
with:
3241
go-version: 1.17
3342
id: go
43+
- name: Print out Go env
44+
run: go env
3445
- name: Check out code into the Go module directory
3546
uses: actions/checkout@v2
3647
with:

Makefile

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ endif
1212
REPO = github.com/operator-framework/api
1313
BUILD_PATH = $(REPO)/cmd/operator-verify
1414
PKGS = $(shell go list ./... | grep -v /vendor/)
15-
YQ := go run $(MOD_FLAGS) ./vendor/github.com/mikefarah/yq/v3/
1615

1716
.PHONY: help
1817
help: ## Show this help screen
@@ -25,7 +24,6 @@ help: ## Show this help screen
2524
.PHONY: install
2625

2726
install: ## Build & install operator-verify
28-
2927
$(Q)go install \
3028
-gcflags "all=-trimpath=${GOPATH}" \
3129
-asmflags "all=-trimpath=${GOPATH}" \
@@ -35,25 +33,25 @@ install: ## Build & install operator-verify
3533
" \
3634
$(BUILD_PATH)
3735

36+
###
3837
# Code management.
39-
.PHONY: format tidy clean vendor generate manifests
38+
###
39+
.PHONY: format tidy clean generate manifests
4040

4141
format: ## Format the source code
4242
$(Q)go fmt $(PKGS)
4343

4444
tidy: ## Update dependencies
4545
$(Q)go mod tidy -v
46-
47-
vendor: tidy ## Update vendor directory
48-
$(Q)go mod vendor
46+
$(Q)go mod verify
4947

5048
clean: ## Clean up the build artifacts
5149
$(Q)rm -rf build
5250

5351
generate: controller-gen ## Generate code
5452
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./...
5553

56-
manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc
54+
manifests: yq controller-gen ## Generate manifests e.g. CRD, RBAC etc
5755
@# Create CRDs for new APIs
5856
$(CONTROLLER_GEN) crd:crdVersions=v1 output:crd:dir=./crds paths=./pkg/operators/...
5957

@@ -88,9 +86,28 @@ test-unit: ## Run the unit tests
8886
verify: manifests generate format
8987
git diff --exit-code
9088

89+
###
9190
# Utilities.
92-
.PHONY: controller-gen
93-
94-
controller-gen: vendor ## Find or download controller-gen
95-
CONTROLLER_GEN=$(Q)go run -mod=vendor ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen
96-
91+
###
92+
93+
# go-get-tool will 'go get' any package $2 and install it to $1.
94+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
95+
define go-get-tool
96+
@[ -f $(1) ] || { \
97+
set -e ;\
98+
TMP_DIR=$$(mktemp -d) ;\
99+
cd $$TMP_DIR ;\
100+
go mod init tmp ;\
101+
echo "Downloading $(2)" ;\
102+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
103+
rm -rf $$TMP_DIR ;\
104+
}
105+
endef
106+
107+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
108+
controller-gen: ## Download controller-gen locally if necessary.
109+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
110+
111+
YQ = $(shell pwd)/bin/yq
112+
yq:
113+
$(call go-get-tool,$(YQ),github.com/mikefarah/yq/v3)

0 commit comments

Comments
 (0)