Skip to content

Commit

Permalink
Merge pull request #29 from ArangoGutierrez/ghactions
Browse files Browse the repository at this point in the history
Update GItHub actions
  • Loading branch information
ArangoGutierrez authored Apr 4, 2024
2 parents 35b90cf + 48789b7 commit 3c1b6c2
Show file tree
Hide file tree
Showing 38 changed files with 485 additions and 351 deletions.
17 changes: 13 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ updates:
schedule:
interval: "weekly"
day: "sunday"
labels:
- area/dependency
ignore:
- dependency-name: k8s.io/*
labels:
- dependencies
groups:
k8sio:
patterns:
- k8s.io/*
exclude-patterns:
- k8s.io/klog/*

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
target-branch: gh-pages
directory: "/"
schedule:
interval: "weekly"
day: "monday"
80 changes: 80 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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:
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
- name: Check golang modules
run: make check-vendor
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
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
22 changes: 0 additions & 22 deletions .github/workflows/pre-sanity.yml

This file was deleted.

23 changes: 23 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# please keep this alphabetized
linters:
enable:
- asciicheck
- contextcheck
- godot
- gofmt
- goimports
- misspell
# TODO: re-enable once we have addressed the warnings
disable:
- unused
- gocritic
- stylecheck
- forcetypeassert

run:
tests: true
timeout: 10m

linters-settings:
goimports:
local-prefixes: "github.com/NVIDIA/go-nvlib"
71 changes: 37 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

MODULE := github.com/NVIDIA/go-nvlib
include versions.mk

DOCKER ?= docker

GOLANG_VERSION := 1.21.1

ifeq ($(IMAGE),)
REGISTRY ?= nvidia
IMAGE=$(REGISTRY)/go-nvlib
endif
IMAGE_TAG ?= $(GOLANG_VERSION)
BUILDIMAGE ?= $(IMAGE):$(IMAGE_TAG)-devel
PCI_IDS_URL ?= https://pci-ids.ucw.cz/v2.2/pci.ids

TARGETS := binary build all check fmt assert-fmt generate lint vet test coverage
DOCKER_TARGETS := $(patsubst %,docker-%, $(TARGETS))
.PHONY: $(TARGETS) $(DOCKER_TARGETS)
.PHONY: $(TARGETS) $(DOCKER_TARGETS) vendor check-vendor

GOOS := linux

Expand All @@ -38,6 +30,14 @@ build:
all: check build binary
check: assert-fmt lint vet

vendor:
go mod tidy
go mod vendor
go mod verify

check-vendor: vendor
git diff --quiet HEAD -- go.mod go.sum vendor

# Apply go fmt to the codebase
fmt:
go list -f '{{.Dir}}' $(MODULE)/... \
Expand All @@ -62,6 +62,14 @@ lint:
# We use `go list -f '{{.Dir}}' $(MODULE)/...` to skip the `vendor` folder.
go list -f '{{.Dir}}' $(MODULE)/... | grep -v pkg/nvml | xargs golint -set_exit_status

## goimports: Apply goimports -local to the codebase
goimports:
find . -name \*.go \
-not -name "zz_generated.deepcopy.go" \
-not -path "./vendor/*" \
-not -path "./pkg/nvidia.com/resource/clientset/versioned/*" \
-exec goimports -local $(MODULE) -w {} \;

vet:
go vet $(MODULE)/...

Expand All @@ -76,32 +84,27 @@ coverage: test
update-pcidb:
wget $(PCI_IDS_URL) -O $(CURDIR)/pkg/pciids/default_pci.ids

# 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 [ "$(SKIP_IMAGE_BUILD)" = "" ]; 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)"
build-image: $(DOCKERFILE_DEVEL)
$(DOCKER) build \
--progress=plain \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--build-arg CLIENT_GEN_VERSION="$(CLIENT_GEN_VERSION)" \
--build-arg CONTROLLER_GEN_VERSION="$(CONTROLLER_GEN_VERSION)" \
--build-arg GOLANGCI_LINT_VERSION="$(GOLANGCI_LINT_VERSION)" \
--build-arg MOQ_VERSION="$(MOQ_VERSION)" \
--tag $(BUILDIMAGE) \
-f $(DOCKERFILE_DEVEL) \
.

$(DOCKER_TARGETS): docker-%:
@echo "Running 'make $(*)' in container image $(BUILDIMAGE)"
$(DOCKER) run \
--rm \
-e GOCACHE=/tmp/.cache \
-v $(PWD):$(PWD) \
-w $(PWD) \
-e GOCACHE=/tmp/.cache/go \
-e GOMODCACHE=/tmp/.cache/gomod \
-e GOLANGCI_LINT_CACHE=/tmp/.cache/golangci-lint \
-v $(PWD):/work \
-w /work \
--user $$(id -u):$$(id -g) \
$(BUILDIMAGE) \
make $(*)
Expand Down
18 changes: 0 additions & 18 deletions docker/Dockerfile.devel

This file was deleted.

12 changes: 6 additions & 6 deletions pkg/nvlib/device/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/NVIDIA/go-nvlib/pkg/nvml"
)

// Interface provides the API to the 'device' package
// Interface provides the API to the 'device' package.
type Interface interface {
AssertValidMigProfileFormat(profile string) error
GetDevices() ([]Device, error)
Expand All @@ -46,7 +46,7 @@ type devicelib struct {

var _ Interface = &devicelib{}

// New creates a new instance of the 'device' interface
// New creates a new instance of the 'device' interface.
func New(opts ...Option) Interface {
d := &devicelib{}
for _, opt := range opts {
Expand All @@ -68,21 +68,21 @@ func New(opts ...Option) Interface {
return d
}

// WithNvml provides an Option to set the NVML library used by the 'device' interface
// WithNvml provides an Option to set the NVML library used by the 'device' interface.
func WithNvml(nvml nvml.Interface) Option {
return func(d *devicelib) {
d.nvml = nvml
}
}

// WithVerifySymbols provides an option to toggle whether to verify select symbols exist in dynamic libraries before calling them
// WithVerifySymbols provides an option to toggle whether to verify select symbols exist in dynamic libraries before calling them.
func WithVerifySymbols(verify bool) Option {
return func(d *devicelib) {
d.verifySymbols = &verify
}
}

// WithSkippedDevices provides an Option to set devices to be skipped by model name
// WithSkippedDevices provides an Option to set devices to be skipped by model name.
func WithSkippedDevices(names ...string) Option {
return func(d *devicelib) {
if d.skippedDevices == nil {
Expand All @@ -94,5 +94,5 @@ func WithSkippedDevices(names ...string) Option {
}
}

// Option defines a function for passing options to the New() call
// Option defines a function for passing options to the New() call.
type Option func(*devicelib)
Loading

0 comments on commit 3c1b6c2

Please sign in to comment.