diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c344342..952a2af 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,11 +20,11 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.21 - name: lint run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.0 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.57.1 ./bin/golangci-lint run - name: Build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d80c3d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.dapper diff --git a/.golangci.yaml b/.golangci.yaml index 82fbfe3..153b2dc 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -7,13 +7,14 @@ linters: - revive - gosec - prealloc -run: - skip-files: +issues: + exclude-files: - /zz_generated_ - _generated - skip-dirs: + exclude-dirs: - generated - deadline: 5m +run: + timeout: 5m tests: true build-tags: - - test \ No newline at end of file + - test diff --git a/Dockerfile.dapper b/Dockerfile.dapper new file mode 100644 index 0000000..09b1799 --- /dev/null +++ b/Dockerfile.dapper @@ -0,0 +1,21 @@ +FROM registry.suse.com/bci/golang:1.21 + +ARG DAPPER_HOST_ARCH +ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH} + +RUN zypper -n rm container-suseconnect && \ + zypper -n install git curl docker gzip tar wget awk + +## install golangci +RUN if [ "${ARCH}" == "amd64" ]; then \ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.57.1; \ + fi + +ENV DAPPER_ENV REPO TAG DRONE_TAG +ENV DAPPER_SOURCE /go/src/github.com/harvester/go-common/ +ENV DAPPER_DOCKER_SOCKET true +ENV HOME ${DAPPER_SOURCE} +WORKDIR ${DAPPER_SOURCE} + +ENTRYPOINT ["./scripts/entry"] +CMD ["ci"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5d7b47e --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +TARGETS := $(shell ls scripts) + +.dapper: + @echo Downloading dapper + @curl -sL https://releases.rancher.com/dapper/latest/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp + @@chmod +x .dapper.tmp + @./.dapper.tmp -v + @mv .dapper.tmp .dapper + +$(TARGETS): .dapper + ./.dapper $@ + +.DEFAULT_GOAL := default + +.PHONY: $(TARGETS) diff --git a/go.mod b/go.mod index b3ada28..bc9fe71 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/harvester/go-common -go 1.20 +go 1.21 require ( github.com/coreos/go-systemd/v22 v22.5.0 @@ -8,7 +8,6 @@ require ( github.com/godbus/dbus/v5 v5.0.4 github.com/sirupsen/logrus v1.9.2 github.com/stretchr/testify v1.7.0 - golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 1d758d3..aa265da 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,6 @@ github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8= -golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956 h1:XeJjHH1KiLpKGb6lvMiksZ9l0fVUh+AmGcm0nOMEBOY= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/scripts/entry b/scripts/entry new file mode 100755 index 0000000..78fb567 --- /dev/null +++ b/scripts/entry @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +mkdir -p bin dist +if [ -e ./scripts/$1 ]; then + ./scripts/"$@" +else + exec "$@" +fi + +chown -R $DAPPER_UID:$DAPPER_GID . diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..0866243 --- /dev/null +++ b/scripts/test @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +cd $(dirname $0)/.. + +echo Running tests +go test -cover -tags=test ./... diff --git a/scripts/validate b/scripts/validate new file mode 100755 index 0000000..7f98128 --- /dev/null +++ b/scripts/validate @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +cd $(dirname $0)/.. + +echo Running validation + +PACKAGES="$(go list ./...)" + +if ! command -v golangci-lint; then + echo Skipping validation: no golangci-lint available + exit +fi + +echo Running validation + +echo Running: golangci-lint +golangci-lint run + +echo Running: go fmt +test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)" diff --git a/slice.go b/slice.go index 8e734cf..a9df4c1 100644 --- a/slice.go +++ b/slice.go @@ -1,6 +1,6 @@ package gocommon -import "golang.org/x/exp/slices" +import "slices" // SliceContentCmp compares two slices and returns true if they have the same content with any order. func SliceContentCmp[T comparable](x, y []T) bool {