From cbc247dd6e56b210cd84b4d46cd16a9d8f96830c Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Wed, 13 Mar 2024 17:08:07 +0100 Subject: [PATCH 1/6] Add dependabot Signed-off-by: Carlos Eduardo Arango Gutierrez --- .github/dependabot.yml | 31 +++++++++++++++++++++---------- .github/workflows/pre-sanity.yml | 22 ---------------------- 2 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 .github/workflows/pre-sanity.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d93ce49..2f92365 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,13 +1,24 @@ +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + version: 2 updates: -- package-ecosystem: gomod - directory: "/" - schedule: - interval: weekly - open-pull-requests-limit: 10 + - package-ecosystem: "gomod" + target-branch: main + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + labels: + - dependencies + groups: + k8sio: + patterns: + - k8s.io/* + exclude-patterns: + - k8s.io/klog/* -- package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "daily" - open-pull-requests-limit: 10 + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" \ No newline at end of file diff --git a/.github/workflows/pre-sanity.yml b/.github/workflows/pre-sanity.yml deleted file mode 100644 index 15ccaf2..0000000 --- a/.github/workflows/pre-sanity.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Run pre sanity - -# run this workflow for each commit -on: [pull_request] - -jobs: - 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 - - - name: Checks - run: make docker-check From f0cb74e0849b90325b5f0b63c3920015efea2511 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Wed, 13 Mar 2024 17:26:35 +0100 Subject: [PATCH 2/6] Add github actions Signed-off-by: Carlos Eduardo Arango Gutierrez --- .github/dependabot.yml | 2 +- .github/workflows/golang.yml | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/golang.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2f92365..f1d8fab 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -21,4 +21,4 @@ updates: - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "daily" \ No newline at end of file + interval: "daily" diff --git a/.github/workflows/golang.yml b/.github/workflows/golang.yml new file mode 100644 index 0000000..a34a364 --- /dev/null +++ b/.github/workflows/golang.yml @@ -0,0 +1,72 @@ +# Copyright 2024 NVIDIA CORPORATION +# +# 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. + +name: Golang + +on: + pull_request: + branches: + - main + - release-* + push: + branches: + - main + - release-* + +jobs: + check: + # TODO: We disable checks for the time being since we need to address the linter errors. + if: false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + name: Checkout code + - name: Get Golang version + id: vars + run: | + GOLANG_VERSION=$( grep "GOLANG_VERSION ?=" versions.mk ) + echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GOLANG_VERSION }} + - name: Lint + uses: golangci/golangci-lint-action@v4 + with: + 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: Checks + run: make docker-test + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + name: Checkout code + - name: Get Golang version + id: vars + run: | + GOLANG_VERSION=$( grep "GOLANG_VERSION ?=" versions.mk ) + echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GOLANG_VERSION }} + - run: make build From c582fb32862289e8fe0e6593107e7f8cd488775c Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Wed, 13 Mar 2024 17:26:57 +0100 Subject: [PATCH 3/6] Add versions file Signed-off-by: Carlos Eduardo Arango Gutierrez --- Makefile | 21 +++++---------------- versions.mk | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 versions.mk diff --git a/Makefile b/Makefile index 099ca30..9310dd5 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +include $(CURDIR)/versions.mk + PWD := $(shell pwd) GEN_DIR := $(PWD)/gen PKG_DIR := $(PWD)/pkg @@ -25,18 +27,6 @@ else SED := sed endif -MODULE := github.com/NVIDIA/go-nvml/pkg - -GOLANG_VERSION ?= 1.20.4 -C_FOR_GO_TAG ?= 8eeee8c3b71f9c3c90c4a73db54ed08b0bba971d - -ifeq ($(IMAGE),) -REGISTRY ?= nvidia -IMAGE=$(REGISTRY)/go-nvml -endif -IMAGE_TAG ?= $(GOLANG_VERSION)-$(C_FOR_GO_TAG) -BUILDIMAGE ?= $(IMAGE):$(IMAGE_TAG)-devel - EXAMPLES := $(patsubst ./examples/%/,%,$(sort $(dir $(wildcard ./examples/*/)))) EXAMPLE_TARGETS := $(patsubst %,example-%, $(EXAMPLES)) @@ -55,7 +45,7 @@ DOCKER_TARGETS := $(patsubst %,docker-%, $(TARGETS)) .PHONY: $(TARGETS) $(DOCKER_TARGETS) build: - go build $(MODULE)/... + go build $(MODULE)/pkg/... examples: $(EXAMPLE_TARGETS) $(EXAMPLE_TARGETS): example-%: @@ -65,7 +55,7 @@ check: $(CHECK_TARGETS) # Apply go fmt to the codebase fmt: - go list -f '{{.Dir}}' $(MODULE)/... \ + go list -f '{{.Dir}}' $(MODULE)/pkg/... \ | xargs gofmt -s -l -w golangci-lint: @@ -76,7 +66,7 @@ generate: COVERAGE_FILE := coverage.out test: build - go test -v -coverprofile=$(COVERAGE_FILE) $(MODULE)/... + go test -v -coverprofile=$(COVERAGE_FILE) $(MODULE)/pkg/... coverage: test cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks @@ -231,4 +221,3 @@ update-nvml-h: markdownlint: MDL := $(DOCKER) run --rm -v "$(PWD):$(PWD)" -w "$(PWD)" markdownlint/markdownlint:latest markdownlint: @$(MDL) --rules=~no-hard-tabs,~line-length README.md - diff --git a/versions.mk b/versions.mk new file mode 100644 index 0000000..ed88d45 --- /dev/null +++ b/versions.mk @@ -0,0 +1,30 @@ +# Copyright (c) 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. + + +GIT_COMMIT ?= $(shell git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "") +GIT_TAG ?= $(patsubst v%,%,$(shell git describe --tags 2>/dev/null)) + +MODULE := github.com/NVIDIA/go-nvml +VERSION ?= $(GIT_TAG) + +GOLANG_VERSION ?= 1.20.4 +C_FOR_GO_TAG ?= 8eeee8c3b71f9c3c90c4a73db54ed08b0bba971d + +ifeq ($(IMAGE),) +REGISTRY ?= nvidia +IMAGE=$(REGISTRY)/go-nvml +endif +IMAGE_TAG ?= $(GOLANG_VERSION)-$(C_FOR_GO_TAG) +BUILDIMAGE ?= $(IMAGE):$(IMAGE_TAG)-devel From 2bfaea6577eb9076028b95b2dfc559c50dc891c6 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 15 Mar 2024 12:14:13 +0200 Subject: [PATCH 4/6] Update golangci config Signed-off-by: Evan Lezar --- .golangci.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index af85b9e..dae0009 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,6 +1,6 @@ -# please keep this alphabetized linters: - enable: [] + enable: + - goimports disable: - asciicheck - contextcheck @@ -8,10 +8,12 @@ linters: - gocritic - godot - gofmt - - goimports - misspell - stylecheck run: - tests: true - timeout: 10m + deadline: 10m + +linters-settings: + goimports: + local-prefixes: github.com/NVIDIA/go-nvml From 1923dc3ad87f32d1dfc7fae702a4c080253c220a Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 15 Mar 2024 12:20:05 +0200 Subject: [PATCH 5/6] Bump go.mod version to go1.20 Signed-off-by: Evan Lezar --- go.mod | 8 +++++++- go.sum | 9 --------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 29f80c1..80fb5c4 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,11 @@ module github.com/NVIDIA/go-nvml -go 1.15 +go 1.20 require github.com/stretchr/testify v1.9.0 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum index 8f0c6a1..60ce688 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,10 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From f3f18092e4586d5738631eee8bb247aebe52165c Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 15 Mar 2024 12:24:06 +0200 Subject: [PATCH 6/6] Don't rebuild bindings on build Signed-off-by: Evan Lezar --- Makefile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Makefile b/Makefile index 9310dd5..bc980ea 100644 --- a/Makefile +++ b/Makefile @@ -124,11 +124,6 @@ PHONY: .shell SOURCES = $(shell find $(GEN_BINDINGS_DIR) -type f) .DEFAULT_GOAL = bindings - -# In order to build the packages we need to patch the nvml.h file -build: bindings - -test: test-bindings clean: clean-bindings $(PKG_BINDINGS_DIR):