diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 09e8a32..f779757 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,42 +1,55 @@ +# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. +# +# Generated on 2024-02-09T18:15:12Z by kres b4106a7. + name: default +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true "on": push: branches: - main + - release-* tags: - v* - pull_request: {} -env: - CI_ARGS: --cache-from=type=registry,ref=registry.dev.siderolabs.io/${GITHUB_REPOSITORY}:buildcache --cache-to=type=registry,ref=registry.dev.siderolabs.io/${GITHUB_REPOSITORY}:buildcache,mode=max + pull_request: + branches: + - main + - release-* jobs: default: permissions: + actions: read contents: write + issues: read packages: write + pull-requests: read runs-on: - self-hosted - - X64 + - generic + if: (!startsWith(github.head_ref, 'renovate/') && !startsWith(github.head_ref, 'dependabot/')) + services: + buildkitd: + image: moby/buildkit:v0.12.5 + options: --privileged + ports: + - 1234:1234 + volumes: + - /var/lib/buildkit/${{ github.repository }}:/var/lib/buildkit + - /usr/etc/buildkit/buildkitd.toml:/etc/buildkit/buildkitd.toml steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Unshallow run: | git fetch --prune --unshallow - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 with: - config-inline: | - [worker.oci] - gc = true - gckeepstorage = 100000 # 100 GiB - - [[worker.oci.gcpolicy]] - keepBytes = 32212254720 # 30 GiB - keepDuration = 604800 - filters = [ "type==source.local", "type==exec.cachemount", "type==source.git.checkout"] - [[worker.oci.gcpolicy]] - all = true - keepBytes = 107374182400 # 100 GiB + driver: remote + endpoint: tcp://localhost:1234 + timeout-minutes: 1 - name: base run: | make base @@ -57,7 +70,7 @@ jobs: make lint - name: Login to registry if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io @@ -83,7 +96,7 @@ jobs: make release-notes - name: Release if: startsWith(github.ref, 'refs/tags/') - uses: crazy-max/ghaction-github-release@v1 + uses: crazy-max/ghaction-github-release@v2 with: body_path: _out/RELEASE_NOTES.md draft: "true" diff --git a/.github/workflows/slack-notify.yaml b/.github/workflows/slack-notify.yaml new file mode 100644 index 0000000..418e33d --- /dev/null +++ b/.github/workflows/slack-notify.yaml @@ -0,0 +1,92 @@ +# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. +# +# Generated on 2024-02-09T18:15:12Z by kres b4106a7. + +name: slack-notify +"on": + workflow_run: + workflows: + - default + types: + - completed +jobs: + slack-notify: + runs-on: + - self-hosted + - generic + if: github.event.workflow_run.conclusion != 'skipped' + steps: + - name: Get PR number + id: get-pr-number + if: github.event.workflow_run.event == 'pull_request' + env: + GH_TOKEN: ${{ github.token }} + run: | + echo pull_request_number=$(gh pr view -R ${{ github.repository }} ${{ github.event.workflow_run.head_repository.owner.login }}:${{ github.event.workflow_run.head_branch }} --json number --jq .number) >> $GITHUB_OUTPUT + - name: Slack Notify + uses: slackapi/slack-github-action@v1 + with: + channel-id: proj-talos-maintainers + payload: | + { + "attachments": [ + { + "color": "${{ github.event.workflow_run.conclusion == 'success' && '#2EB886' || github.event.workflow_run.conclusion == 'failure' && '#A30002' || '#FFCC00' }}", + "fallback": "test", + "blocks": [ + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "${{ github.event.workflow_run.event == 'pull_request' && format('*Pull Request:* {0} (`{1}`)\n<{2}/pull/{3}|{4}>', github.repository, github.ref_name, github.event.repository.html_url, steps.get-pr-number.outputs.pull_request_number, github.event.workflow_run.display_title) || format('*Build:* {0} (`{1}`)\n<{2}/commit/{3}|{4}>', github.repository, github.ref_name, github.event.repository.html_url, github.sha, github.event.workflow_run.display_title) }}" + }, + { + "type": "mrkdwn", + "text": "*Status:*\n`${{ github.event.workflow_run.conclusion }}`" + } + ] + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*Author:*\n`${{ github.actor }}`" + }, + { + "type": "mrkdwn", + "text": "*Event:*\n`${{ github.event.workflow_run.event }}`" + } + ] + }, + { + "type": "divider" + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Logs" + }, + "url": "${{ github.event.workflow_run.html_url }}" + }, + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Commit" + }, + "url": "${{ github.event.repository.html_url }}/commit/${{ github.sha }}" + } + ] + } + ] + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/.golangci.yml b/.golangci.yml index b4844a7..ebe61f9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-09-07T20:28:51Z by kres latest. +# Generated on 2024-02-09T18:10:43Z by kres b4106a7. # options for analysis running run: @@ -32,20 +32,13 @@ linters-settings: check-blank: true exhaustive: default-signifies-exhaustive: false - funlen: - lines: 60 - statements: 40 gci: - local-prefixes: github.com/siderolabs/importvet/ + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(github.com/siderolabs/importvet/) # Custom section: groups all imports with the specified Prefix. gocognit: min-complexity: 30 - ireturn: - allow: - - anon - - error - - empty - - stdlib - - github.com\/talos-systems\/kres\/internal\/dag.Node nestif: min-complexity: 5 goconst: @@ -55,27 +48,14 @@ linters-settings: disabled-checks: [] gocyclo: min-complexity: 20 - godot: - check-all: false - godox: - keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting - - NOTE - - OPTIMIZE # marks code that should be optimized before merging - - HACK # marks hack-arounds that should be removed before merging gofmt: simplify: true goimports: local-prefixes: github.com/siderolabs/importvet/ - golint: - min-confidence: 0.8 - gomnd: - settings: {} gomodguard: {} govet: check-shadowing: true enable-all: true - disable: - - loopclosure lll: line-length: 200 tab-width: 4 @@ -90,7 +70,6 @@ linters-settings: for-loops: false # Report preallocation suggestions on for loops, false by default nolintlint: allow-unused: false - allow-leading-space: false allow-no-explanation: [] require-explanation: false require-specific: true @@ -98,8 +77,6 @@ linters-settings: testpackage: {} unparam: check-exported: false - unused: - check-exported: false whitespace: multi-if: false # Enforces newlines (or comments) after every multi-line if statement multi-func: false # Enforces newlines (or comments) after every multi-line function signature @@ -127,29 +104,32 @@ linters: disable-all: false fast: false disable: - - exhaustruct - exhaustivestruct + - exhaustruct - forbidigo - funlen - - gas - gochecknoglobals - gochecknoinits - godox - goerr113 - gomnd - gomoddirectives + - gosec + - inamedparam - ireturn - nestif - nonamedreturns - nosnakecase - paralleltest + - tagalign - tagliatelle - thelper - - typecheck - varnamelen - wrapcheck - depguard # Disabled because starting with golangci-lint 1.53.0 it doesn't allow denylist alone anymore - - tagalign + - testifylint # complains about our assert recorder and has a number of false positives for assert.Greater(t, thing, 1) + - protogetter # complains about us using Value field on typed spec, instead of GetValue which has a different signature + - perfsprint # complains about us using fmt.Sprintf in non-performance critical code, updating just kres took too long # abandoned linters for which golangci shows the warning that the repo is archived by the owner - interfacer - maligned diff --git a/Dockerfile b/Dockerfile index bccfb40..23a7e1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,21 +2,21 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-09-07T20:28:51Z by kres latest. +# Generated on 2024-02-09T18:10:43Z by kres b4106a7. ARG TOOLCHAIN # cleaned up specs and compiled versions FROM scratch AS generate -FROM ghcr.io/siderolabs/ca-certificates:v1.6.0-alpha.0-10-gd3d7d29 AS image-ca-certificates +FROM ghcr.io/siderolabs/ca-certificates:v1.6.0 AS image-ca-certificates -FROM ghcr.io/siderolabs/fhs:v1.6.0-alpha.0-10-gd3d7d29 AS image-fhs +FROM ghcr.io/siderolabs/fhs:v1.6.0 AS image-fhs # runs markdownlint -FROM docker.io/node:20.5.1-alpine3.18 AS lint-markdown +FROM docker.io/node:21.6.1-alpine3.19 AS lint-markdown WORKDIR /src -RUN npm i -g markdownlint-cli@0.35.0 +RUN npm i -g markdownlint-cli@0.39.0 RUN npm i sentences-per-line@0.2.1 COPY .markdownlint.json . COPY ./README.md ./README.md diff --git a/Makefile b/Makefile index bb5baa2..c874ac4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-09-07T20:28:51Z by kres latest. +# Generated on 2024-02-09T18:10:43Z by kres b4106a7. # common variables @@ -14,20 +14,19 @@ WITH_RACE ?= false REGISTRY ?= ghcr.io USERNAME ?= siderolabs REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME) -PROTOBUF_GO_VERSION ?= 1.31.0 +PROTOBUF_GO_VERSION ?= 1.32.0 GRPC_GO_VERSION ?= 1.3.0 -GRPC_GATEWAY_VERSION ?= 2.17.1 -VTPROTOBUF_VERSION ?= 0.4.0 +GRPC_GATEWAY_VERSION ?= 2.19.1 +VTPROTOBUF_VERSION ?= 0.6.0 DEEPCOPY_VERSION ?= v0.5.5 -GOLANGCILINT_VERSION ?= v1.54.2 -GOFUMPT_VERSION ?= v0.5.0 -GO_VERSION ?= 1.21 -GOIMPORTS_VERSION ?= v0.12.0 +GOLANGCILINT_VERSION ?= v1.56.1 +GOFUMPT_VERSION ?= v0.6.0 +GO_VERSION ?= 1.22.0 +GOIMPORTS_VERSION ?= v0.17.0 GO_BUILDFLAGS ?= GO_LDFLAGS ?= CGO_ENABLED ?= 0 GOTOOLCHAIN ?= local -GOEXPERIMENT ?= loopvar TESTPKGS ?= ./... KRES_IMAGE ?= ghcr.io/siderolabs/kres:latest CONFORMANCE_IMAGE ?= ghcr.io/siderolabs/conform:latest @@ -65,7 +64,7 @@ COMMON_ARGS += --build-arg=GOLANGCILINT_VERSION="$(GOLANGCILINT_VERSION)" COMMON_ARGS += --build-arg=GOIMPORTS_VERSION="$(GOIMPORTS_VERSION)" COMMON_ARGS += --build-arg=GOFUMPT_VERSION="$(GOFUMPT_VERSION)" COMMON_ARGS += --build-arg=TESTPKGS="$(TESTPKGS)" -TOOLCHAIN ?= docker.io/golang:1.21-alpine +TOOLCHAIN ?= docker.io/golang:1.22-alpine # help menu @@ -88,6 +87,23 @@ To create a builder instance, run: docker buildx create --name local --use +If running builds that needs to be cached aggresively create a builder instance with the following: + + docker buildx create --name local --use --config=config.toml + +config.toml contents: + +[worker.oci] + gc = true + gckeepstorage = 50000 + + [[worker.oci.gcpolicy]] + keepBytes = 10737418240 + keepDuration = 604800 + filters = [ "type==source.local", "type==exec.cachemount", "type==source.git.checkout"] + [[worker.oci.gcpolicy]] + all = true + keepBytes = 53687091200 If you already have a compatible builder instance, you may use that instead. @@ -109,7 +125,7 @@ endif ifneq (, $(filter $(WITH_DEBUG), t true TRUE y yes 1)) GO_BUILDFLAGS += -tags sidero.debug else -GO_LDFLAGS += -s -w +GO_LDFLAGS += -s endif all: unit-tests importvet image-importvet lint @@ -133,7 +149,7 @@ lint-gofumpt: ## Runs gofumpt linter. .PHONY: fmt fmt: ## Formats the source code @docker run --rm -it -v $(PWD):/src -w /src golang:$(GO_VERSION) \ - bash -c "export GOEXPERIMENT=loopvar; export GOTOOLCHAIN=local; \ + bash -c "export GOTOOLCHAIN=local; \ export GO111MODULE=on; export GOPROXY=https://proxy.golang.org; \ go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION) && \ gofumpt -w ." @@ -191,7 +207,7 @@ image-importvet: ## Builds image for importvet. .PHONY: rekres rekres: @docker pull $(KRES_IMAGE) - @docker run --rm -v $(PWD):/src -w /src -e GITHUB_TOKEN $(KRES_IMAGE) + @docker run --rm --net=host --user $(shell id -u):$(shell id -g) -v $(PWD):/src -w /src -e GITHUB_TOKEN $(KRES_IMAGE) .PHONY: help help: ## This help menu. diff --git a/go.mod b/go.mod index f124be7..58fc276 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,16 @@ module github.com/siderolabs/importvet -go 1.20 +go 1.22.0 require ( - github.com/dghubble/trie v0.0.0-20230518162934-2f591ddf5713 + github.com/dghubble/trie v0.0.0-20230729160116-2bc358f28a8b github.com/stretchr/testify v1.8.4 - golang.org/x/tools v0.9.3 + golang.org/x/tools v0.17.0 gopkg.in/yaml.v3 v3.0.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/mod v0.10.0 // indirect - golang.org/x/sys v0.8.0 // indirect + golang.org/x/mod v0.15.0 // indirect ) diff --git a/go.sum b/go.sum index 9a1db93..da65119 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,17 @@ 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/dghubble/trie v0.0.0-20230518162934-2f591ddf5713 h1:zW8zUUgVC5KbkSvJKsMfajpf+bI2GNaOWe3nk/KJOO0= -github.com/dghubble/trie v0.0.0-20230518162934-2f591ddf5713/go.mod h1:sOmnzfBNH7H92ow2292dDFWNsVQuh/izuD7otCYb1ak= +github.com/dghubble/trie v0.0.0-20230729160116-2bc358f28a8b h1:WKIAjG75YSAoZfer6DUwkMNEnlbo+5hOFFg0ZJu2Ax0= +github.com/dghubble/trie v0.0.0-20230729160116-2bc358f28a8b/go.mod h1:sOmnzfBNH7H92ow2292dDFWNsVQuh/izuD7otCYb1ak= 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/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= -golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= 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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/pkg/importvet/fact.go b/pkg/importvet/fact.go index 453491d..25a557c 100644 --- a/pkg/importvet/fact.go +++ b/pkg/importvet/fact.go @@ -7,7 +7,7 @@ package importvet import ( "fmt" "go/types" - "sort" + "slices" "strings" "golang.org/x/tools/go/analysis" @@ -50,7 +50,7 @@ func (fact *importFact) String() string { imports = append(imports, pkg.Path()) } - sort.Strings(imports) + slices.Sort(imports) return fmt.Sprintf("importFact(%v)", imports) } diff --git a/pkg/importvet/importvet.go b/pkg/importvet/importvet.go index 2442441..280166f 100644 --- a/pkg/importvet/importvet.go +++ b/pkg/importvet/importvet.go @@ -33,7 +33,7 @@ func InitConfig(rootPath string) (err error) { return err } -func run(pass *analysis.Pass) (interface{}, error) { +func run(pass *analysis.Pass) (any, error) { if configTree == nil { return nil, fmt.Errorf("config tree wasn't initialized for importvet") } diff --git a/pkg/importvet/tree.go b/pkg/importvet/tree.go index 15a59fd..658fada 100644 --- a/pkg/importvet/tree.go +++ b/pkg/importvet/tree.go @@ -29,8 +29,12 @@ func NewConfigTree(rootPath string) (*ConfigTree, error) { return nil, err } - if err = filepath.Walk(rootPath, func(path string, info os.FileInfo, err error) error { - if info.Mode().IsRegular() && filepath.Base(path) == configFilename { + if err = filepath.WalkDir(rootPath, func(path string, info os.DirEntry, err error) error { + if err != nil { + return err + } + + if info.Type().IsRegular() && filepath.Base(path) == configFilename { cfg, err := LoadConfig(path) if err != nil { return err @@ -60,7 +64,7 @@ func NewConfigTree(rootPath string) (*ConfigTree, error) { func (cfgTree *ConfigTree) Match(path string) ([]*Config, error) { var configs []*Config - err := cfgTree.configTrie.WalkPath(path, func(key string, value interface{}) error { + err := cfgTree.configTrie.WalkPath(path, func(_ string, value any) error { configs = append(configs, value.(*Config)) //nolint:forcetypeassert return nil