mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
a9c76d7655
The PR fixes lint issues, pins `golangci-lint` to `v1.56.2`, disables `only-new-issues`, and enables `fail-on-issues` in the lint workflow. After this, all new lint issues will fail CI. The full log of fixed lint issues: ```sh ❯ golangci-lint run cmd/docs.go:24:14: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive) RunE: func(cmd *cobra.Command, args []string) error { ^ cmd/man.go:26:14: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive) RunE: func(cmd *cobra.Command, args []string) error { ^ cmd/healthcheck.go:36:14: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive) RunE: func(cmd *cobra.Command, args []string) error { ^ cmd/build.go:72:33: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive) RunE: timedRunE("build", func(cmd *cobra.Command, args []string) error { ^ cmd/schema.go:29:14: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive) RunE: func(cmd *cobra.Command, args []string) error { ^ internal/pipe/nix/nix_test.go:547:5: error-is-as: second argument to require.ErrorAs should not be *error (testifylint) require.ErrorAs(t, err, &tt.expectDefaultErrorIs) ^ internal/pipe/nix/nix_test.go:556:5: error-is-as: second argument to require.ErrorAs should not be *error (testifylint) require.ErrorAs(t, err, &tt.expectRunErrorIs) ^ internal/pipe/nix/nix_test.go:567:5: error-is-as: second argument to require.ErrorAs should not be *error (testifylint) require.ErrorAs(t, err, &tt.expectPublishErrorIs) ^ internal/pipe/winget/winget_test.go:709:5: error-is-as: second argument to require.ErrorAs should not be *error (testifylint) require.ErrorAs(t, err, &tt.expectPublishErrorIs) ^ internal/pipe/winget/winget_test.go:728:5: error-is-as: second argument to require.ErrorAs should not be *error (testifylint) require.ErrorAs(t, err, &tt.expectPublishErrorIs) ^ internal/pipe/docker/docker_test.go:56:29: unused-parameter: parameter 'use' seems to be unused, consider removing or renaming it as _ (revive) return func(t *testing.T, use string) { ^ internal/gio/safe_test.go:23:4: go-require: require must only be used in the goroutine running the test function (testifylint) require.Equal(t, 1, s) ^ internal/gio/safe_test.go:24:4: go-require: require must only be used in the goroutine running the test function (testifylint) require.NoError(t, err) ^ internal/pipe/gomod/gomod_proxy_test.go:126:3: useless-assert: asserting of the same variable (testifylint) require.Equal(t, ctx.ModulePath, ctx.ModulePath) ^ internal/pipe/gomod/gomod_proxy_test.go:152:3: useless-assert: asserting of the same variable (testifylint) require.Equal(t, ctx.ModulePath, ctx.ModulePath) ^ internal/pipe/gomod/gomod_proxy_test.go:178:3: useless-assert: asserting of the same variable (testifylint) require.Equal(t, ctx.ModulePath, ctx.ModulePath) ^ internal/pipe/gomod/gomod_proxy_test.go:239:3: useless-assert: asserting of the same variable (testifylint) require.Equal(t, ctx.ModulePath, ctx.ModulePath) ^ internal/artifact/artifact_test.go:638:46: unused-parameter: parameter 'a' seems to be unused, consider removing or renaming it as _ (revive) require.EqualError(t, artifacts.Visit(func(a *Artifact) error { ^ internal/pipe/milestone/milestone.go:79: File is not `gofumpt`-ed (gofumpt) internal/http/http_test.go:217:19: unused-parameter: parameter 'k' seems to be unused, consider removing or renaming it as _ (revive) assetOpen = func(k string, a *artifact.Artifact) (*asset, error) { ^ internal/middleware/logging/logging_test.go:12:37: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) require.NoError(t, Log("foo", func(ctx *context.Context) error { ^ internal/middleware/logging/logging_test.go:16:40: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) require.NoError(t, PadLog("foo", func(ctx *context.Context) error { ^ internal/pipe/chocolatey/chocolatey_test.go:277:15: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive) exec: func(cmd string, args ...string) ([]byte, error) { ^ internal/client/gitlab.go:325: File is not `gofumpt`-ed (gofumpt) internal/pipe/linkedin/client_test.go:58:77: unused-parameter: parameter 'req' seems to be unused, consider removing or renaming it as _ (revive) server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { ^ internal/middleware/errhandler/error_test.go:15:34: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) require.NoError(t, Handle(func(ctx *context.Context) error { ^ internal/middleware/errhandler/error_test.go:21:34: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) require.NoError(t, Handle(func(ctx *context.Context) error { ^ internal/middleware/errhandler/error_test.go:27:32: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) require.Error(t, Handle(func(ctx *context.Context) error { ^ internal/middleware/errhandler/error_test.go:36:37: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) require.NoError(t, memo.Wrap(func(ctx *context.Context) error { ^ internal/middleware/errhandler/error_test.go:42:37: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) require.NoError(t, memo.Wrap(func(ctx *context.Context) error { ^ internal/middleware/errhandler/error_test.go:48:37: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) require.NoError(t, memo.Wrap(func(ctx *context.Context) error { ^ internal/pipe/ko/ko.go:175:29: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) build.WithBaseImages(func(ctx stdctx.Context, s string) (name.Reference, build.Result, error) { ^ ```
108 lines
2.7 KiB
Go
108 lines
2.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os/exec"
|
|
"sync"
|
|
|
|
"github.com/caarlos0/ctrlc"
|
|
"github.com/caarlos0/log"
|
|
"github.com/charmbracelet/lipgloss"
|
|
"github.com/goreleaser/goreleaser/internal/middleware/skip"
|
|
"github.com/goreleaser/goreleaser/internal/pipe/defaults"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
"github.com/goreleaser/goreleaser/pkg/healthcheck"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type healthcheckCmd struct {
|
|
cmd *cobra.Command
|
|
config string
|
|
quiet bool
|
|
}
|
|
|
|
func newHealthcheckCmd() *healthcheckCmd {
|
|
root := &healthcheckCmd{}
|
|
cmd := &cobra.Command{
|
|
Use: "healthcheck",
|
|
Aliases: []string{"hc"},
|
|
Short: "Checks if needed tools are installed",
|
|
Long: `Check if the needed tools are available in your $PATH, exits 1 if any of them are missing.`,
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
Args: cobra.NoArgs,
|
|
ValidArgsFunction: cobra.NoFileCompletions,
|
|
RunE: func(_ *cobra.Command, _ []string) error {
|
|
if root.quiet {
|
|
log.Log = log.New(io.Discard)
|
|
}
|
|
|
|
cfg, err := loadConfig(root.config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ctx := context.New(cfg)
|
|
|
|
if err := ctrlc.Default.Run(ctx, func() error {
|
|
log.Info(boldStyle.Render("checking tools..."))
|
|
|
|
err := defaults.Pipe{}.Run(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.IncreasePadding()
|
|
defer log.ResetPadding()
|
|
|
|
var errs []error
|
|
for _, hc := range healthcheck.Healthcheckers {
|
|
_ = skip.Maybe(hc, func(ctx *context.Context) error {
|
|
for _, tool := range hc.Dependencies(ctx) {
|
|
if err := checkPath(tool); err != nil {
|
|
errs = append(errs, err)
|
|
}
|
|
}
|
|
return nil
|
|
})(ctx)
|
|
}
|
|
|
|
if len(errs) == 0 {
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("one or more needed tools are not present")
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Infof(boldStyle.Render("done!"))
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVarP(&root.config, "config", "f", "", "Configuration file")
|
|
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
|
|
cmd.Flags().BoolVarP(&root.quiet, "quiet", "q", false, "Quiet mode: no output")
|
|
_ = cmd.Flags().MarkHidden("deprecated")
|
|
|
|
root.cmd = cmd
|
|
return root
|
|
}
|
|
|
|
var toolsChecked = &sync.Map{}
|
|
|
|
func checkPath(tool string) error {
|
|
if _, ok := toolsChecked.LoadOrStore(tool, true); ok {
|
|
return nil
|
|
}
|
|
if _, err := exec.LookPath(tool); err != nil {
|
|
st := log.Styles[log.ErrorLevel]
|
|
log.Warnf("%s %s - %s", st.Render("⚠"), codeStyle.Render(tool), st.Render("not present in path"))
|
|
return err
|
|
}
|
|
st := lipgloss.NewStyle().Foreground(lipgloss.Color("2")).Bold(true)
|
|
log.Infof("%s %s", st.Render("✓"), codeStyle.Render(tool))
|
|
return nil
|
|
}
|