Skip to content

Commit

Permalink
action: add contrib-lint in smoke test
Browse files Browse the repository at this point in the history
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 <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high committed Feb 20, 2024
1 parent 5fb8096 commit e14263a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 9 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
4 changes: 3 additions & 1 deletion contrib/ctr-remote/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
2 changes: 1 addition & 1 deletion contrib/ctr-remote/commands/rpull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion contrib/nydus-overlayfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
4 changes: 3 additions & 1 deletion contrib/nydusify/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion contrib/nydusify/pkg/converter/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions contrib/nydusify/pkg/provider/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contrib/nydusify/pkg/utils/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
)
Expand Down

0 comments on commit e14263a

Please sign in to comment.