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
  • Loading branch information
timflannagan committed Jan 18, 2022
1 parent e03e7fb commit ddb5e8a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Go
on:
push:
branches:
branches:
- master
- main
pull_request:
branches:
branches:
- master
- main
jobs:
build:
name: Build
Expand All @@ -18,8 +20,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 Down
1 change: 1 addition & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- main
pull_request:
paths:
- '**'
Expand Down
43 changes: 30 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ 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/
PKGS = $(shell go list ./...)

.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.6.2)

YQ = $(shell pwd)/bin/yq
yq:
$(call go-get-tool,$(YQ),github.com/mikefarah/yq/v3)

0 comments on commit ddb5e8a

Please sign in to comment.