diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 45180dc5..ee23ed2e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,8 +9,6 @@ updates: schedule: interval: "weekly" day: "sunday" - labels: - - area/dependency ignore: - dependency-name: k8s.io/* labels: diff --git a/.github/workflows/golang-build.yaml b/.github/workflows/golang.yaml similarity index 79% rename from .github/workflows/golang-build.yaml rename to .github/workflows/golang.yaml index b9423a16..07205159 100644 --- a/.github/workflows/golang-build.yaml +++ b/.github/workflows/golang.yaml @@ -36,16 +36,21 @@ jobs: version: latest args: -v --timeout 5m skip-cache: true + test: + name: Unit test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: '1.20' + - run: make test build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Build dev image - run: make .build-image - - name: Build run: make docker-build - - - name: Tests - run: make docker-coverage diff --git a/.github/workflows/build-images.yaml b/.github/workflows/images.yaml similarity index 99% rename from .github/workflows/build-images.yaml rename to .github/workflows/images.yaml index cfe91801..798dabde 100644 --- a/.github/workflows/build-images.yaml +++ b/.github/workflows/images.yaml @@ -74,4 +74,3 @@ jobs: run: | echo "${VERSION}" make -f deployments/container/Makefile build-${{ matrix.dist }} - diff --git a/.gitignore b/.gitignore index 250f4bdd..bbb463c6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /nvidia-dra-plugin .idea [._]*.sw[a-p] +coverage.out diff --git a/Makefile b/Makefile index 85438b89..f3713969 100644 --- a/Makefile +++ b/Makefile @@ -26,9 +26,6 @@ ifeq ($(IMAGE_NAME),) IMAGE_NAME = $(REGISTRY)/$(DRIVER_NAME) endif -BUILDIMAGE_TAG ?= golang$(GOLANG_VERSION) -BUILDIMAGE ?= $(IMAGE_NAME)-build:$(BUILDIMAGE_TAG) - CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/)))) CMD_TARGETS := $(patsubst %,cmd-%, $(CMDS)) @@ -89,7 +86,7 @@ golangci-lint: COVERAGE_FILE := coverage.out test: build cmds - go test -v -coverprofile=$(COVERAGE_FILE) $(MODULE)/... + go test -race -cover -v -coverprofile=$(COVERAGE_FILE) $(MODULE)/... coverage: test cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks @@ -138,34 +135,14 @@ generate-clientset: .remove-clientset .remove-deepcopy .remove-crds .remove-clientset: rm -rf $(CURDIR)/$(PKG_BASE)/clientset -# Generate an image for containerized builds -# Note: This image is local only -.PHONY: .build-image .pull-build-image .push-build-image -.build-image: docker/Dockerfile.devel - if [ x"$(SKIP_IMAGE_BUILD)" = x"" ]; then \ - $(DOCKER) build \ - --progress=plain \ - --build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \ - --tag $(BUILDIMAGE) \ - -f $(^) \ - docker; \ - fi - -.pull-build-image: - $(DOCKER) pull $(BUILDIMAGE) - -.push-build-image: - $(DOCKER) push $(BUILDIMAGE) - -$(DOCKER_TARGETS): docker-%: .build-image - @echo "Running 'make $(*)' in docker container $(BUILDIMAGE)" +$(DOCKER_TARGETS): docker-%: + @echo "Running 'make $(*)' in container image $(BUILDIMAGE)" $(DOCKER) run \ --rm \ - -e HOME=$(PWD) \ - -e GOCACHE=$(PWD)/.cache/go \ - -e GOPATH=$(PWD)/.cache/gopath \ - -v $(PWD):$(PWD) \ - -w $(PWD) \ + -e GOCACHE=/tmp/.cache/go \ + -e GOMODCACHE=/tmp/.cache/gomod \ + -v $(PWD):/work \ + -w /work \ --user $$(id -u):$$(id -g) \ $(BUILDIMAGE) \ make $(*) @@ -176,10 +153,9 @@ PHONY: .shell $(DOCKER) run \ --rm \ -ti \ - -e HOME=$(PWD) \ - -e GOCACHE=$(PWD)/.cache/go \ - -e GOPATH=$(PWD)/.cache/gopath \ - -v $(PWD):$(PWD) \ - -w $(PWD) \ + -e GOCACHE=/tmp/.cache/go \ + -e GOMODCACHE=/tmp/.cache/gomod \ + -v $(PWD):/work \ + -w /work \ --user $$(id -u):$$(id -g) \ $(BUILDIMAGE) diff --git a/docker/Dockerfile.devel b/docker/Dockerfile.devel deleted file mode 100644 index 9377d399..00000000 --- a/docker/Dockerfile.devel +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -ARG GOLANG_VERSION=x.x.x -FROM golang:${GOLANG_VERSION} - -RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.0 - -RUN go install github.com/matryer/moq@latest -RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.2 -RUN go install k8s.io/code-generator/cmd/client-gen@v0.26.1 diff --git a/versions.mk b/versions.mk index 6fcfd741..b187aad3 100644 --- a/versions.mk +++ b/versions.mk @@ -24,4 +24,7 @@ vVERSION := v$(VERSION:v%=%) GOLANG_VERSION ?= 1.20.4 CUDA_VERSION ?= 11.8.0 +BUILDIMAGE_TAG ?= devel-go$(GOLANG_VERSION) +BUILDIMAGE ?= ghcr.io/nvidia/k8s-test-infra:$(BUILDIMAGE_TAG) + GIT_COMMIT ?= $(shell git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "")