diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d93ce49..f1d8fab 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: + - package-ecosystem: "github-actions" + directory: "/" + schedule: interval: "daily" - open-pull-requests-limit: 10 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 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 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 diff --git a/Makefile b/Makefile index 099ca30..bc980ea 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 @@ -134,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): @@ -231,4 +216,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/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= 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