From e14263aaa90ff8616f14ee1b163a0e38b2e1ca9b Mon Sep 17 00:00:00 2001 From: Yadong Ding Date: Tue, 20 Feb 2024 21:07:46 +0800 Subject: [PATCH] action: add contrib-lint in smoke test 1. Use the official GitHub action for golangci-lint from its authors. 2. fix golang lint error with v1.56 3. separate test and golang lint.Sometimes we need tests without golang lint and sometimes we just want to do golang lint. Signed-off-by: Yadong Ding --- .github/workflows/smoke.yml | 24 ++++++++++++++++++- Makefile | 12 ++++++++++ contrib/ctr-remote/Makefile | 4 +++- contrib/ctr-remote/commands/rpull.go | 2 +- contrib/nydus-overlayfs/Makefile | 4 +++- contrib/nydusify/Makefile | 4 +++- .../pkg/converter/provider/provider.go | 2 +- contrib/nydusify/pkg/provider/remote.go | 4 ++-- contrib/nydusify/pkg/utils/archive.go | 2 +- 9 files changed, 49 insertions(+), 9 deletions(-) diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index 847d543294a..f446a8537f4 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -39,6 +39,29 @@ jobs: name: nydusify-artifact path: contrib/nydusify/cmd + contrib-lint: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - path: contrib/nydusify + - path: contrib/ctr-remote + - path: contrib/nydus-overlayfs + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Golang + uses: actions/setup-go@v5 + with: + go-version-file: 'go.work' + cache: false + - name: Lint + uses: golangci/golangci-lint-action@v4 + with: + version: v1.56 + working-directory: ${{ matrix.path }} + args: --timeout=30m --issues-exit-code=0 + nydus-build: runs-on: ubuntu-latest strategy: @@ -192,7 +215,6 @@ jobs: cache-dependency-path: "**/*.sum" - name: Unit Test run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/bin v1.54.2 make -e DOCKER=false contrib-test - name: Upload contrib coverage file uses: actions/upload-artifact@v4 diff --git a/Makefile b/Makefile index 3f601b221c7..87bd8628a89 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,9 @@ contrib-release: nydusify-release ctr-remote-release \ contrib-test: nydusify-test ctr-remote-test \ nydus-overlayfs-test +contrib-lint: nydusify-lint ctr-remote-lint \ + nydus-overlayfs-lint + contrib-clean: nydusify-clean ctr-remote-clean \ nydus-overlayfs-clean @@ -167,6 +170,9 @@ nydusify-test: nydusify-clean: $(call build_golang,${NYDUSIFY_PATH},make clean) +nydusify-lint: + $(call build_golang,${NYDUSIFY_PATH},make lint) + ctr-remote: $(call build_golang,${CTR-REMOTE_PATH},make) @@ -179,6 +185,9 @@ ctr-remote-test: ctr-remote-clean: $(call build_golang,${CTR-REMOTE_PATH},make clean) +ctr-remote-lint: + $(call build_golang,${CTR-REMOTE_PATH},make lint) + nydus-overlayfs: $(call build_golang,${NYDUS-OVERLAYFS_PATH},make) @@ -191,6 +200,9 @@ nydus-overlayfs-test: nydus-overlayfs-clean: $(call build_golang,${NYDUS-OVERLAYFS_PATH},make clean) +nydus-overlayfs-lint: + $(call build_golang,${NYDUS-OVERLAYFS_PATH},make lint) + docker-static: docker build -t nydus-rs-static --build-arg RUST_TARGET=${RUST_TARGET_STATIC} misc/musl-static docker run --rm ${CARGO_BUILD_GEARS} -e RUST_TARGET=${RUST_TARGET_STATIC} --workdir /nydus-rs -v ${current_dir}:/nydus-rs nydus-rs-static diff --git a/contrib/ctr-remote/Makefile b/contrib/ctr-remote/Makefile index 7df0391cffe..d00b32f6106 100644 --- a/contrib/ctr-remote/Makefile +++ b/contrib/ctr-remote/Makefile @@ -20,8 +20,10 @@ release: test: go vet $(PACKAGES) - golangci-lint run go test -v -cover ${PACKAGES} +lint: + golangci-lint run + clean: rm -f bin/* diff --git a/contrib/ctr-remote/commands/rpull.go b/contrib/ctr-remote/commands/rpull.go index 87ad1dc47d6..e9b28604b1d 100644 --- a/contrib/ctr-remote/commands/rpull.go +++ b/contrib/ctr-remote/commands/rpull.go @@ -79,7 +79,7 @@ type rPullConfig struct { func pull(ctx context.Context, client *containerd.Client, ref string, config *rPullConfig) error { pCtx := ctx - h := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { + h := images.HandlerFunc(func(_ context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { if desc.MediaType != images.MediaTypeDockerSchema1Manifest { fmt.Printf("fetching %v... %v\n", desc.Digest.String()[:15], desc.MediaType) } diff --git a/contrib/nydus-overlayfs/Makefile b/contrib/nydus-overlayfs/Makefile index c5f7d98ab30..a70009d6cf8 100644 --- a/contrib/nydus-overlayfs/Makefile +++ b/contrib/nydus-overlayfs/Makefile @@ -20,8 +20,10 @@ release: test: build go vet $(PACKAGES) - golangci-lint run go test -v -cover ${PACKAGES} +lint: + golangci-lint run + clean: rm -f bin/* diff --git a/contrib/nydusify/Makefile b/contrib/nydusify/Makefile index f3bf210ce9d..39a5f06662d 100644 --- a/contrib/nydusify/Makefile +++ b/contrib/nydusify/Makefile @@ -28,9 +28,11 @@ plugin: test: @go vet $(PACKAGES) - golangci-lint run @go test -covermode=atomic -coverprofile=coverage.txt -count=1 -v -timeout 20m -parallel 16 -race ${PACKAGES} +lint: + golangci-lint run + coverage: test @go tool cover -func=coverage.txt diff --git a/contrib/nydusify/pkg/converter/provider/provider.go b/contrib/nydusify/pkg/converter/provider/provider.go index d2f0463c5f7..08a7988dba1 100644 --- a/contrib/nydusify/pkg/converter/provider/provider.go +++ b/contrib/nydusify/pkg/converter/provider/provider.go @@ -92,7 +92,7 @@ func newResolver(insecure, plainHTTP bool, credFunc remote.CredentialFunc, chunk ), ), docker.WithClient(newDefaultClient(insecure)), - docker.WithPlainHTTP(func(host string) (bool, error) { + docker.WithPlainHTTP(func(_ string) (bool, error) { return plainHTTP, nil }), docker.WithChunkSize(chunkSize), diff --git a/contrib/nydusify/pkg/provider/remote.go b/contrib/nydusify/pkg/provider/remote.go index b1b5583acaf..1bfadbef499 100644 --- a/contrib/nydusify/pkg/provider/remote.go +++ b/contrib/nydusify/pkg/provider/remote.go @@ -59,7 +59,7 @@ func withRemote(ref string, insecure bool, credFunc withCredentialFunc) (*remote ), ), docker.WithClient(newDefaultClient(insecure)), - docker.WithPlainHTTP(func(host string) (bool, error) { + docker.WithPlainHTTP(func(_ string) (bool, error) { return retryWithHTTP, nil }), ) @@ -97,7 +97,7 @@ func DefaultRemote(ref string, insecure bool) (*remote.Remote, error) { // DefaultRemoteWithAuth creates an remote instance, it parses base64 encoded auth string // to communicate with remote registry. func DefaultRemoteWithAuth(ref string, insecure bool, auth string) (*remote.Remote, error) { - return withRemote(ref, insecure, func(host string) (string, string, error) { + return withRemote(ref, insecure, func(_ string) (string, string, error) { // Leave auth empty if no authorization be required if strings.TrimSpace(auth) == "" { return "", "", nil diff --git a/contrib/nydusify/pkg/utils/archive.go b/contrib/nydusify/pkg/utils/archive.go index 153acea90ff..df8b46aaec6 100644 --- a/contrib/nydusify/pkg/utils/archive.go +++ b/contrib/nydusify/pkg/utils/archive.go @@ -158,7 +158,7 @@ func UnpackTargz(ctx context.Context, dst string, r io.Reader, overlay bool) err ctx, dst, ds, - archive.WithConvertWhiteout(func(hdr *tar.Header, file string) (bool, error) { + archive.WithConvertWhiteout(func(_ *tar.Header, _ string) (bool, error) { return true, nil }), )