From 4009ada30bf6529fea3f291f66393cb1231dec2f Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Wed, 13 Mar 2024 17:26:57 +0100 Subject: [PATCH] Add versions file Signed-off-by: Carlos Eduardo Arango Gutierrez --- .github/dependabot.yml | 2 +- .github/workflows/golang.yml | 48 +++++++++++------------------------- Makefile | 15 ++++------- go.mod | 8 +++++- go.sum | 9 ------- versions.mk | 27 ++++++++++++++++++++ 6 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 versions.mk 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 index a625a39..1a25d1d 100644 --- a/.github/workflows/golang.yml +++ b/.github/workflows/golang.yml @@ -28,40 +28,22 @@ jobs: check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - name: Checkout code - - name: Build dev image - run: make .build-image - - name: Checks - run: make docker-check + - uses: actions/checkout@v4 + name: Checkout code + - name: Checks + run: make docker-check test: - name: Unit test - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - 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 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 \ No newline at end of file + - name: Checkout code + uses: actions/checkout@v4 + - name: Checks + run: make docker-build diff --git a/Makefile b/Makefile index 099ca30..cdf6ce6 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +include versions.mk + PWD := $(shell pwd) GEN_DIR := $(PWD)/gen PKG_DIR := $(PWD)/pkg @@ -25,17 +27,11 @@ 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 +51,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 +61,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 +72,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 +227,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..8e0a275 --- /dev/null +++ b/versions.mk @@ -0,0 +1,27 @@ +# 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. + +MODULE := github.com/NVIDIA/go-nvml + +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)) +PARTS := $(subst -, ,$(GIT_TAG)) +VERSION ?= $(word 1,$(PARTS)) + +# vVERSION represents the version with a guaranteed v-prefix +vVERSION := v$(VERSION:v%=%) + +GOLANG_VERSION ?= 1.20.4 +C_FOR_GO_TAG ?= 8eeee8c3b71f9c3c90c4a73db54ed08b0bba971d +BUILDIMAGE ?= $(IMAGE):$(IMAGE_TAG)-devel