You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	fix: improve output a bit (#2174)
* fix: improve output a bit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve output a bit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: revert unwanted changes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip err Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: build Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							a9efdcab4a
						
					
				
				
					commit
					f61d8c820c
				
			| @@ -10,10 +10,14 @@ import ( | |||||||
| // errors. | // errors. | ||||||
| func ErrHandler(action Action) Action { | func ErrHandler(action Action) Action { | ||||||
| 	return func(ctx *context.Context) error { | 	return func(ctx *context.Context) error { | ||||||
| 		var err = action(ctx) | 		err := action(ctx) | ||||||
| 		if err == nil { | 		if err == nil { | ||||||
| 			return nil | 			return nil | ||||||
| 		} | 		} | ||||||
|  | 		if pipe.IsExpectedSkip(err) { | ||||||
|  | 			log.WithError(err).Debug("pipe skipped") | ||||||
|  | 			return nil | ||||||
|  | 		} | ||||||
| 		if pipe.IsSkip(err) { | 		if pipe.IsSkip(err) { | ||||||
| 			log.WithError(err).Warn("pipe skipped") | 			log.WithError(err).Warn("pipe skipped") | ||||||
| 			return nil | 			return nil | ||||||
|   | |||||||
| @@ -17,6 +17,10 @@ func TestError(t *testing.T) { | |||||||
| 		require.NoError(t, ErrHandler(mockAction(pipe.ErrSkipValidateEnabled))(ctx)) | 		require.NoError(t, ErrHandler(mockAction(pipe.ErrSkipValidateEnabled))(ctx)) | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
|  | 	t.Run("pipe expected skipped", func(t *testing.T) { | ||||||
|  | 		require.NoError(t, ErrHandler(mockAction(pipe.ErrSkipDisabledPipe))(ctx)) | ||||||
|  | 	}) | ||||||
|  |  | ||||||
| 	t.Run("some err", func(t *testing.T) { | 	t.Run("some err", func(t *testing.T) { | ||||||
| 		require.Error(t, ErrHandler(mockAction(fmt.Errorf("pipe errored")))(ctx)) | 		require.Error(t, ErrHandler(mockAction(fmt.Errorf("pipe errored")))(ctx)) | ||||||
| 	}) | 	}) | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ type Padding int | |||||||
| const DefaultInitialPadding Padding = 3 | const DefaultInitialPadding Padding = 3 | ||||||
|  |  | ||||||
| // ExtraPadding is the double of the DefaultInitialPadding. | // ExtraPadding is the double of the DefaultInitialPadding. | ||||||
| const ExtraPadding Padding = DefaultInitialPadding * 2 | const ExtraPadding = DefaultInitialPadding * 2 | ||||||
|  |  | ||||||
| // Logging pretty prints the given action and its title. | // Logging pretty prints the given action and its title. | ||||||
| // You can have different padding levels by providing different initial | // You can have different padding levels by providing different initial | ||||||
|   | |||||||
| @@ -36,7 +36,7 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
| // Docs: https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-Example-DeployinganArtifact | // Docs: https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-Example-DeployinganArtifact | ||||||
| func (Pipe) Publish(ctx *context.Context) error { | func (Pipe) Publish(ctx *context.Context) error { | ||||||
| 	if len(ctx.Config.Artifactories) == 0 { | 	if len(ctx.Config.Artifactories) == 0 { | ||||||
| 		return pipe.Skip("artifactory section is not configured") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Check requirements for every instance we have configured. | 	// Check requirements for every instance we have configured. | ||||||
|   | |||||||
| @@ -36,10 +36,10 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
| // Publish to specified blob bucket url. | // Publish to specified blob bucket url. | ||||||
| func (Pipe) Publish(ctx *context.Context) error { | func (Pipe) Publish(ctx *context.Context) error { | ||||||
| 	if len(ctx.Config.Blobs) == 0 { | 	if len(ctx.Config.Blobs) == 0 { | ||||||
| 		return pipe.Skip("blobs section is not configured") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var g = semerrgroup.New(ctx.Parallelism) | 	g := semerrgroup.New(ctx.Parallelism) | ||||||
| 	for _, conf := range ctx.Config.Blobs { | 	for _, conf := range ctx.Config.Blobs { | ||||||
| 		conf := conf | 		conf := conf | ||||||
| 		g.Go(func() error { | 		g.Go(func() error { | ||||||
|   | |||||||
| @@ -63,9 +63,9 @@ func (Pipe) Publish(ctx *context.Context) error { | |||||||
| func publishAll(ctx *context.Context, cli client.Client) error { | func publishAll(ctx *context.Context, cli client.Client) error { | ||||||
| 	// even if one of them skips, we run them all, and then show return the skips all at once. | 	// even if one of them skips, we run them all, and then show return the skips all at once. | ||||||
| 	// this is needed so we actually create the `dist/foo.rb` file, which is useful for debugging. | 	// this is needed so we actually create the `dist/foo.rb` file, which is useful for debugging. | ||||||
| 	var skips = pipe.SkipMemento{} | 	skips := pipe.SkipMemento{} | ||||||
| 	for _, brew := range ctx.Config.Brews { | 	for _, brew := range ctx.Config.Brews { | ||||||
| 		var err = doRun(ctx, brew, cli) | 		err := doRun(ctx, brew, cli) | ||||||
| 		if err != nil && pipe.IsSkip(err) { | 		if err != nil && pipe.IsSkip(err) { | ||||||
| 			skips.Remember(err) | 			skips.Remember(err) | ||||||
| 			continue | 			continue | ||||||
| @@ -80,7 +80,7 @@ func publishAll(ctx *context.Context, cli client.Client) error { | |||||||
| // Default sets the pipe defaults. | // Default sets the pipe defaults. | ||||||
| func (Pipe) Default(ctx *context.Context) error { | func (Pipe) Default(ctx *context.Context) error { | ||||||
| 	for i := range ctx.Config.Brews { | 	for i := range ctx.Config.Brews { | ||||||
| 		var brew = &ctx.Config.Brews[i] | 		brew := &ctx.Config.Brews[i] | ||||||
|  |  | ||||||
| 		if brew.Install == "" { | 		if brew.Install == "" { | ||||||
| 			brew.Install = fmt.Sprintf(`bin.install "%s"`, ctx.Config.ProjectName) | 			brew.Install = fmt.Sprintf(`bin.install "%s"`, ctx.Config.ProjectName) | ||||||
| @@ -105,7 +105,7 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
|  |  | ||||||
| func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error { | func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error { | ||||||
| 	if brew.Tap.Name == "" { | 	if brew.Tap.Name == "" { | ||||||
| 		return pipe.Skip("brew section is not configured") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if brew.Tap.Token != "" { | 	if brew.Tap.Token != "" { | ||||||
| @@ -122,7 +122,7 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// TODO: properly cover this with tests | 	// TODO: properly cover this with tests | ||||||
| 	var filters = []artifact.Filter{ | 	filters := []artifact.Filter{ | ||||||
| 		artifact.Or( | 		artifact.Or( | ||||||
| 			artifact.ByGoos("darwin"), | 			artifact.ByGoos("darwin"), | ||||||
| 			artifact.ByGoos("linux"), | 			artifact.ByGoos("linux"), | ||||||
| @@ -142,7 +142,7 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error { | |||||||
| 		filters = append(filters, artifact.ByIDs(brew.IDs...)) | 		filters = append(filters, artifact.ByIDs(brew.IDs...)) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var archives = ctx.Artifacts.Filter(artifact.And(filters...)).List() | 	archives := ctx.Artifacts.Filter(artifact.And(filters...)).List() | ||||||
| 	if len(archives) == 0 { | 	if len(archives) == 0 { | ||||||
| 		return ErrNoArchivesFound | 		return ErrNoArchivesFound | ||||||
| 	} | 	} | ||||||
| @@ -158,10 +158,10 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var filename = brew.Name + ".rb" | 	filename := brew.Name + ".rb" | ||||||
| 	var path = filepath.Join(ctx.Config.Dist, filename) | 	path := filepath.Join(ctx.Config.Dist, filename) | ||||||
| 	log.WithField("formula", path).Info("writing") | 	log.WithField("formula", path).Info("writing") | ||||||
| 	if err := ioutil.WriteFile(path, []byte(content), 0644); err != nil { //nolint: gosec | 	if err := ioutil.WriteFile(path, []byte(content), 0o644); err != nil { //nolint: gosec | ||||||
| 		return fmt.Errorf("failed to write brew formula: %w", err) | 		return fmt.Errorf("failed to write brew formula: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -177,12 +177,12 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error { | |||||||
|  |  | ||||||
| 	repo := client.RepoFromRef(brew.Tap) | 	repo := client.RepoFromRef(brew.Tap) | ||||||
|  |  | ||||||
| 	var gpath = buildFormulaPath(brew.Folder, filename) | 	gpath := buildFormulaPath(brew.Folder, filename) | ||||||
| 	log.WithField("formula", gpath). | 	log.WithField("formula", gpath). | ||||||
| 		WithField("repo", repo.String()). | 		WithField("repo", repo.String()). | ||||||
| 		Info("pushing") | 		Info("pushing") | ||||||
|  |  | ||||||
| 	var msg = fmt.Sprintf("Brew formula update for %s version %s", ctx.Config.ProjectName, ctx.Git.CurrentTag) | 	msg := fmt.Sprintf("Brew formula update for %s version %s", ctx.Config.ProjectName, ctx.Git.CurrentTag) | ||||||
| 	return cl.CreateFile(ctx, brew.CommitAuthor, repo, []byte(content), gpath, msg) | 	return cl.CreateFile(ctx, brew.CommitAuthor, repo, []byte(content), gpath, msg) | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -232,7 +232,7 @@ func doBuildFormula(ctx *context.Context, data templateData) (string, error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifacts []*artifact.Artifact) (templateData, error) { | func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifacts []*artifact.Artifact) (templateData, error) { | ||||||
| 	var result = templateData{ | 	result := templateData{ | ||||||
| 		Name:             formulaNameFor(cfg.Name), | 		Name:             formulaNameFor(cfg.Name), | ||||||
| 		Desc:             cfg.Description, | 		Desc:             cfg.Description, | ||||||
| 		Homepage:         cfg.Homepage, | 		Homepage:         cfg.Homepage, | ||||||
| @@ -270,7 +270,7 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifa | |||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return result, err | 			return result, err | ||||||
| 		} | 		} | ||||||
| 		var down = downloadable{ | 		down := downloadable{ | ||||||
| 			DownloadURL: url, | 			DownloadURL: url, | ||||||
| 			SHA256:      sum, | 			SHA256:      sum, | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ func (Pipe) Run(ctx *context.Context) error { | |||||||
| 		ctx.ReleaseNotes = notes | 		ctx.ReleaseNotes = notes | ||||||
| 	} | 	} | ||||||
| 	if ctx.Config.Changelog.Skip { | 	if ctx.Config.Changelog.Skip { | ||||||
| 		return pipe.Skip("changelog should not be built") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
| 	if ctx.Snapshot { | 	if ctx.Snapshot { | ||||||
| 		return pipe.Skip("not available for snapshots") | 		return pipe.Skip("not available for snapshots") | ||||||
| @@ -110,9 +110,9 @@ func (Pipe) Run(ctx *context.Context) error { | |||||||
| 		ctx.ReleaseNotes += "\n" | 		ctx.ReleaseNotes += "\n" | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var path = filepath.Join(ctx.Config.Dist, "CHANGELOG.md") | 	path := filepath.Join(ctx.Config.Dist, "CHANGELOG.md") | ||||||
| 	log.WithField("changelog", path).Info("writing") | 	log.WithField("changelog", path).Info("writing") | ||||||
| 	return ioutil.WriteFile(path, []byte(ctx.ReleaseNotes), 0644) //nolint: gosec | 	return ioutil.WriteFile(path, []byte(ctx.ReleaseNotes), 0o644) //nolint: gosec | ||||||
| } | } | ||||||
|  |  | ||||||
| func loadFromFile(file string) (string, error) { | func loadFromFile(file string) (string, error) { | ||||||
| @@ -140,7 +140,7 @@ func buildChangelog(ctx *context.Context) ([]string, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	var entries = strings.Split(log, "\n") | 	entries := strings.Split(log, "\n") | ||||||
| 	entries = entries[0 : len(entries)-1] | 	entries = entries[0 : len(entries)-1] | ||||||
| 	entries, err = filterEntries(ctx, entries) | 	entries, err = filterEntries(ctx, entries) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -161,15 +161,15 @@ func filterEntries(ctx *context.Context, entries []string) ([]string, error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func sortEntries(ctx *context.Context, entries []string) []string { | func sortEntries(ctx *context.Context, entries []string) []string { | ||||||
| 	var direction = ctx.Config.Changelog.Sort | 	direction := ctx.Config.Changelog.Sort | ||||||
| 	if direction == "" { | 	if direction == "" { | ||||||
| 		return entries | 		return entries | ||||||
| 	} | 	} | ||||||
| 	var result = make([]string, len(entries)) | 	result := make([]string, len(entries)) | ||||||
| 	copy(result, entries) | 	copy(result, entries) | ||||||
| 	sort.Slice(result, func(i, j int) bool { | 	sort.Slice(result, func(i, j int) bool { | ||||||
| 		var imsg = extractCommitInfo(result[i]) | 		imsg := extractCommitInfo(result[i]) | ||||||
| 		var jmsg = extractCommitInfo(result[j]) | 		jmsg := extractCommitInfo(result[j]) | ||||||
| 		if direction == "asc" { | 		if direction == "asc" { | ||||||
| 			return strings.Compare(imsg, jmsg) < 0 | 			return strings.Compare(imsg, jmsg) < 0 | ||||||
| 		} | 		} | ||||||
| @@ -203,7 +203,7 @@ func getChangelog(tag string) (string, error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func gitLog(refs ...string) (string, error) { | func gitLog(refs ...string) (string, error) { | ||||||
| 	var args = []string{"log", "--pretty=oneline", "--abbrev-commit", "--no-decorate", "--no-color"} | 	args := []string{"log", "--pretty=oneline", "--abbrev-commit", "--no-decorate", "--no-color"} | ||||||
| 	args = append(args, refs...) | 	args = append(args, refs...) | ||||||
| 	return git.Run(args...) | 	return git.Run(args...) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -38,7 +38,7 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
| // Run the pipe. | // Run the pipe. | ||||||
| func (Pipe) Run(ctx *context.Context) (err error) { | func (Pipe) Run(ctx *context.Context) (err error) { | ||||||
| 	if ctx.Config.Checksum.Disable { | 	if ctx.Config.Checksum.Disable { | ||||||
| 		return pipe.Skip("checksum.disable is set") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
| 	filter := artifact.Or( | 	filter := artifact.Or( | ||||||
| 		artifact.ByType(artifact.UploadableArchive), | 		artifact.ByType(artifact.UploadableArchive), | ||||||
| @@ -55,7 +55,7 @@ func (Pipe) Run(ctx *context.Context) (err error) { | |||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var g = semerrgroup.New(ctx.Parallelism) | 	g := semerrgroup.New(ctx.Parallelism) | ||||||
| 	sumLines := make([]string, len(artifactList)) | 	sumLines := make([]string, len(artifactList)) | ||||||
| 	for i, artifact := range artifactList { | 	for i, artifact := range artifactList { | ||||||
| 		i := i | 		i := i | ||||||
| @@ -82,7 +82,7 @@ func (Pipe) Run(ctx *context.Context) (err error) { | |||||||
| 	file, err := os.OpenFile( | 	file, err := os.OpenFile( | ||||||
| 		filepath.Join(ctx.Config.Dist, filename), | 		filepath.Join(ctx.Config.Dist, filename), | ||||||
| 		os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_TRUNC, | 		os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_TRUNC, | ||||||
| 		0644, | 		0o644, | ||||||
| 	) | 	) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ import ( | |||||||
| 	"testing" | 	"testing" | ||||||
|  |  | ||||||
| 	"github.com/goreleaser/goreleaser/internal/artifact" | 	"github.com/goreleaser/goreleaser/internal/artifact" | ||||||
|  | 	"github.com/goreleaser/goreleaser/internal/pipe" | ||||||
| 	"github.com/goreleaser/goreleaser/internal/testlib" | 	"github.com/goreleaser/goreleaser/internal/testlib" | ||||||
| 	"github.com/goreleaser/goreleaser/pkg/config" | 	"github.com/goreleaser/goreleaser/pkg/config" | ||||||
| 	"github.com/goreleaser/goreleaser/pkg/context" | 	"github.com/goreleaser/goreleaser/pkg/context" | ||||||
| @@ -114,7 +115,7 @@ func TestPipeSkipTrue(t *testing.T) { | |||||||
| 	) | 	) | ||||||
| 	var err = Pipe{}.Run(ctx) | 	var err = Pipe{}.Run(ctx) | ||||||
| 	testlib.AssertSkipped(t, err) | 	testlib.AssertSkipped(t, err) | ||||||
| 	require.EqualError(t, err, `checksum.disable is set`) | 	require.EqualError(t, err, pipe.ErrSkipDisabledPipe.Error()) | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestPipeFileNotExist(t *testing.T) { | func TestPipeFileNotExist(t *testing.T) { | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ func (Pipe) String() string { | |||||||
| // Publish artifacts. | // Publish artifacts. | ||||||
| func (Pipe) Publish(ctx *context.Context) error { | func (Pipe) Publish(ctx *context.Context) error { | ||||||
| 	if len(ctx.Config.Publishers) == 0 { | 	if len(ctx.Config.Publishers) == 0 { | ||||||
| 		return pipe.Skip("publishers section is not configured") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return exec.Execute(ctx, ctx.Config.Publishers) | 	return exec.Execute(ctx, ctx.Config.Publishers) | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ func (Pipe) String() string { | |||||||
| // Default sets the pipe defaults. | // Default sets the pipe defaults. | ||||||
| func (Pipe) Default(ctx *context.Context) error { | func (Pipe) Default(ctx *context.Context) error { | ||||||
| 	for i := range ctx.Config.Dockers { | 	for i := range ctx.Config.Dockers { | ||||||
| 		var docker = &ctx.Config.Dockers[i] | 		docker := &ctx.Config.Dockers[i] | ||||||
|  |  | ||||||
| 		if docker.Goos == "" { | 		if docker.Goos == "" { | ||||||
| 			docker.Goos = "linux" | 			docker.Goos = "linux" | ||||||
| @@ -62,7 +62,7 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
| // Run the pipe. | // Run the pipe. | ||||||
| func (Pipe) Run(ctx *context.Context) error { | func (Pipe) Run(ctx *context.Context) error { | ||||||
| 	if len(ctx.Config.Dockers) == 0 || len(ctx.Config.Dockers[0].ImageTemplates) == 0 { | 	if len(ctx.Config.Dockers) == 0 || len(ctx.Config.Dockers[0].ImageTemplates) == 0 { | ||||||
| 		return pipe.Skip("docker section is not configured") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
| 	_, err := exec.LookPath("docker") | 	_, err := exec.LookPath("docker") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -76,7 +76,7 @@ func (Pipe) Publish(ctx *context.Context) error { | |||||||
| 	if ctx.SkipPublish { | 	if ctx.SkipPublish { | ||||||
| 		return pipe.ErrSkipPublishEnabled | 		return pipe.ErrSkipPublishEnabled | ||||||
| 	} | 	} | ||||||
| 	var images = ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableDockerImage)).List() | 	images := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableDockerImage)).List() | ||||||
| 	for _, image := range images { | 	for _, image := range images { | ||||||
| 		if err := dockerPush(ctx, image); err != nil { | 		if err := dockerPush(ctx, image); err != nil { | ||||||
| 			return err | 			return err | ||||||
| @@ -86,12 +86,12 @@ func (Pipe) Publish(ctx *context.Context) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func doRun(ctx *context.Context) error { | func doRun(ctx *context.Context) error { | ||||||
| 	var g = semerrgroup.NewSkipAware(semerrgroup.New(ctx.Parallelism)) | 	g := semerrgroup.NewSkipAware(semerrgroup.New(ctx.Parallelism)) | ||||||
| 	for _, docker := range ctx.Config.Dockers { | 	for _, docker := range ctx.Config.Dockers { | ||||||
| 		docker := docker | 		docker := docker | ||||||
| 		g.Go(func() error { | 		g.Go(func() error { | ||||||
| 			log.WithField("docker", docker).Debug("looking for artifacts matching") | 			log.WithField("docker", docker).Debug("looking for artifacts matching") | ||||||
| 			var filters = []artifact.Filter{ | 			filters := []artifact.Filter{ | ||||||
| 				artifact.ByGoos(docker.Goos), | 				artifact.ByGoos(docker.Goos), | ||||||
| 				artifact.ByGoarch(docker.Goarch), | 				artifact.ByGoarch(docker.Goarch), | ||||||
| 				artifact.ByGoarm(docker.Goarm), | 				artifact.ByGoarm(docker.Goarm), | ||||||
| @@ -103,7 +103,7 @@ func doRun(ctx *context.Context) error { | |||||||
| 			if len(docker.IDs) > 0 { | 			if len(docker.IDs) > 0 { | ||||||
| 				filters = append(filters, artifact.ByIDs(docker.IDs...)) | 				filters = append(filters, artifact.ByIDs(docker.IDs...)) | ||||||
| 			} | 			} | ||||||
| 			var artifacts = ctx.Artifacts.Filter(artifact.And(filters...)) | 			artifacts := ctx.Artifacts.Filter(artifact.And(filters...)) | ||||||
| 			log.WithField("artifacts", artifacts.Paths()).Debug("found artifacts") | 			log.WithField("artifacts", artifacts.Paths()).Debug("found artifacts") | ||||||
| 			return process(ctx, docker, artifacts.List()) | 			return process(ctx, docker, artifacts.List()) | ||||||
| 		}) | 		}) | ||||||
| @@ -127,7 +127,7 @@ func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.A | |||||||
| 		return fmt.Errorf("failed to link dockerfile: %w", err) | 		return fmt.Errorf("failed to link dockerfile: %w", err) | ||||||
| 	} | 	} | ||||||
| 	for _, file := range docker.Files { | 	for _, file := range docker.Files { | ||||||
| 		if err := os.MkdirAll(filepath.Join(tmp, filepath.Dir(file)), 0755); err != nil { | 		if err := os.MkdirAll(filepath.Join(tmp, filepath.Dir(file)), 0o755); err != nil { | ||||||
| 			return fmt.Errorf("failed to link extra file '%s': %w", file, err) | 			return fmt.Errorf("failed to link extra file '%s': %w", file, err) | ||||||
| 		} | 		} | ||||||
| 		if err := link(file, filepath.Join(tmp, file)); err != nil { | 		if err := link(file, filepath.Join(tmp, file)); err != nil { | ||||||
| @@ -217,7 +217,7 @@ func link(src, dest string) error { | |||||||
| 		// - dest = "dist/linuxamd64/b" | 		// - dest = "dist/linuxamd64/b" | ||||||
| 		// - path = "a/b/c.txt" | 		// - path = "a/b/c.txt" | ||||||
| 		// So we join "a/b" with "c.txt" and use it as the destination. | 		// So we join "a/b" with "c.txt" and use it as the destination. | ||||||
| 		var dst = filepath.Join(dest, strings.Replace(path, src, "", 1)) | 		dst := filepath.Join(dest, strings.Replace(path, src, "", 1)) | ||||||
| 		log.WithFields(log.Fields{ | 		log.WithFields(log.Fields{ | ||||||
| 			"src": path, | 			"src": path, | ||||||
| 			"dst": dst, | 			"dst": dst, | ||||||
| @@ -232,7 +232,7 @@ func link(src, dest string) error { | |||||||
| func dockerBuild(ctx *context.Context, root string, images, flags []string, buildx bool) error { | func dockerBuild(ctx *context.Context, root string, images, flags []string, buildx bool) error { | ||||||
| 	log.WithField("image", images[0]).WithField("buildx", buildx).Info("building docker image") | 	log.WithField("image", images[0]).WithField("buildx", buildx).Info("building docker image") | ||||||
| 	/* #nosec */ | 	/* #nosec */ | ||||||
| 	var cmd = exec.CommandContext(ctx, "docker", buildCommand(buildx, images, flags)...) | 	cmd := exec.CommandContext(ctx, "docker", buildCommand(buildx, images, flags)...) | ||||||
| 	cmd.Dir = root | 	cmd.Dir = root | ||||||
| 	log.WithField("cmd", cmd.Args).WithField("cwd", cmd.Dir).Debug("running") | 	log.WithField("cmd", cmd.Args).WithField("cwd", cmd.Dir).Debug("running") | ||||||
| 	out, err := cmd.CombinedOutput() | 	out, err := cmd.CombinedOutput() | ||||||
| @@ -258,7 +258,7 @@ func buildCommand(buildx bool, images, flags []string) []string { | |||||||
| func dockerPush(ctx *context.Context, image *artifact.Artifact) error { | func dockerPush(ctx *context.Context, image *artifact.Artifact) error { | ||||||
| 	log.WithField("image", image.Name).Info("pushing docker image") | 	log.WithField("image", image.Name).Info("pushing docker image") | ||||||
| 	/* #nosec */ | 	/* #nosec */ | ||||||
| 	var cmd = exec.CommandContext(ctx, "docker", "push", image.Name) | 	cmd := exec.CommandContext(ctx, "docker", "push", image.Name) | ||||||
| 	log.WithField("cmd", cmd.Args).Debug("running") | 	log.WithField("cmd", cmd.Args).Debug("running") | ||||||
| 	out, err := cmd.CombinedOutput() | 	out, err := cmd.CombinedOutput() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -53,7 +53,7 @@ func (Pipe) Run(ctx *context.Context) error { | |||||||
| 	ctx.ModulePath = result | 	ctx.ModulePath = result | ||||||
|  |  | ||||||
| 	if !ctx.Config.GoMod.Proxy { | 	if !ctx.Config.GoMod.Proxy { | ||||||
| 		return pipe.Skip("gomod.proxy is disabled") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ctx.Snapshot { | 	if ctx.Snapshot { | ||||||
|   | |||||||
| @@ -63,11 +63,10 @@ func doPublish(ctx *context.Context, vcsClient client.Client) error { | |||||||
| 		milestone := &ctx.Config.Milestones[i] | 		milestone := &ctx.Config.Milestones[i] | ||||||
|  |  | ||||||
| 		if !milestone.Close { | 		if !milestone.Close { | ||||||
| 			return pipe.Skip("milestone pipe is disabled") | 			return pipe.ErrSkipDisabledPipe | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		name, err := tmpl.New(ctx).Apply(milestone.NameTemplate) | 		name, err := tmpl.New(ctx).Apply(milestone.NameTemplate) | ||||||
|  |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -22,14 +22,31 @@ var ErrSkipSignEnabled = Skip("artifact signing is disabled") | |||||||
| // It means that the part of a Piper that validates some things was not run. | // It means that the part of a Piper that validates some things was not run. | ||||||
| var ErrSkipValidateEnabled = Skip("validation is disabled") | var ErrSkipValidateEnabled = Skip("validation is disabled") | ||||||
|  |  | ||||||
|  | // ErrSkipDisabledPipe happens when a pipe is skipped because it is not configured. | ||||||
|  | var ErrSkipDisabledPipe = ErrSkip{ | ||||||
|  | 	reason: "pipe not configured/disabled", | ||||||
|  | 	expected: true, | ||||||
|  | } | ||||||
|  |  | ||||||
| // IsSkip returns true if the error is an ErrSkip. | // IsSkip returns true if the error is an ErrSkip. | ||||||
| func IsSkip(err error) bool { | func IsSkip(err error) bool { | ||||||
| 	return errors.As(err, &ErrSkip{}) | 	return errors.As(err, &ErrSkip{}) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // IsExpectedSkip returns true if the given error is ErrSkip and if it is an | ||||||
|  | // expected skip. | ||||||
|  | func IsExpectedSkip(err error) bool { | ||||||
|  | 	skipErr := ErrSkip{} | ||||||
|  | 	if !errors.As(err, &skipErr) { | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
|  | 	return skipErr.expected | ||||||
|  | } | ||||||
|  |  | ||||||
| // ErrSkip occurs when a pipe is skipped for some reason. | // ErrSkip occurs when a pipe is skipped for some reason. | ||||||
| type ErrSkip struct { | type ErrSkip struct { | ||||||
| 	reason string | 	reason   string | ||||||
|  | 	expected bool | ||||||
| } | } | ||||||
|  |  | ||||||
| // Error implements the error interface. returns the reason the pipe was skipped. | // Error implements the error interface. returns the reason the pipe was skipped. | ||||||
|   | |||||||
| @@ -8,19 +8,25 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| func TestSkipPipe(t *testing.T) { | func TestSkipPipe(t *testing.T) { | ||||||
| 	var reason = "this is a test" | 	reason := "this is a test" | ||||||
| 	var err = Skip(reason) | 	err := Skip(reason) | ||||||
| 	require.Error(t, err) | 	require.Error(t, err) | ||||||
| 	require.Equal(t, reason, err.Error()) | 	require.Equal(t, reason, err.Error()) | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestIsSkip(t *testing.T) { | func TestIsSkip(t *testing.T) { | ||||||
| 	require.True(t, IsSkip(Skip("whatever"))) | 	require.True(t, IsSkip(Skip("whatever"))) | ||||||
|  | 	require.True(t, IsSkip(ErrSkipDisabledPipe)) | ||||||
| 	require.False(t, IsSkip(errors.New("nope"))) | 	require.False(t, IsSkip(errors.New("nope"))) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestIsExpectedSkip(t *testing.T) { | ||||||
|  | 	require.True(t, IsSkip(ErrSkipDisabledPipe)) | ||||||
|  | 	require.True(t, IsSkip(Skip("nope"))) | ||||||
|  | } | ||||||
|  |  | ||||||
| func TestSkipMemento(t *testing.T) { | func TestSkipMemento(t *testing.T) { | ||||||
| 	var m = SkipMemento{} | 	m := SkipMemento{} | ||||||
| 	m.Remember(Skip("foo")) | 	m.Remember(Skip("foo")) | ||||||
| 	m.Remember(Skip("bar")) | 	m.Remember(Skip("bar")) | ||||||
| 	// test duplicated errors | 	// test duplicated errors | ||||||
|   | |||||||
| @@ -113,7 +113,7 @@ func (Pipe) Publish(ctx *context.Context) error { | |||||||
|  |  | ||||||
| func doPublish(ctx *context.Context, client client.Client) error { | func doPublish(ctx *context.Context, client client.Client) error { | ||||||
| 	if ctx.Config.Release.Disable { | 	if ctx.Config.Release.Disable { | ||||||
| 		return pipe.Skip("release pipe is disabled") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
| 	log.WithField("tag", ctx.Git.CurrentTag). | 	log.WithField("tag", ctx.Git.CurrentTag). | ||||||
| 		WithField("repo", ctx.Config.Release.GitHub.String()). | 		WithField("repo", ctx.Config.Release.GitHub.String()). | ||||||
| @@ -143,7 +143,7 @@ func doPublish(ctx *context.Context, client client.Client) error { | |||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var filters = artifact.Or( | 	filters := artifact.Or( | ||||||
| 		artifact.ByType(artifact.UploadableArchive), | 		artifact.ByType(artifact.UploadableArchive), | ||||||
| 		artifact.ByType(artifact.UploadableBinary), | 		artifact.ByType(artifact.UploadableBinary), | ||||||
| 		artifact.ByType(artifact.UploadableSourceArchive), | 		artifact.ByType(artifact.UploadableSourceArchive), | ||||||
| @@ -158,7 +158,7 @@ func doPublish(ctx *context.Context, client client.Client) error { | |||||||
|  |  | ||||||
| 	filters = artifact.Or(filters, artifact.ByType(artifact.UploadableFile)) | 	filters = artifact.Or(filters, artifact.ByType(artifact.UploadableFile)) | ||||||
|  |  | ||||||
| 	var g = semerrgroup.New(ctx.Parallelism) | 	g := semerrgroup.New(ctx.Parallelism) | ||||||
| 	for _, artifact := range ctx.Artifacts.Filter(filters).List() { | 	for _, artifact := range ctx.Artifacts.Filter(filters).List() { | ||||||
| 		artifact := artifact | 		artifact := artifact | ||||||
| 		g.Go(func() error { | 		g.Go(func() error { | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
| func doRun(ctx *context.Context, cl client.Client) error { | func doRun(ctx *context.Context, cl client.Client) error { | ||||||
| 	scoop := ctx.Config.Scoop | 	scoop := ctx.Config.Scoop | ||||||
| 	if scoop.Bucket.Name == "" { | 	if scoop.Bucket.Name == "" { | ||||||
| 		return pipe.Skip("scoop section is not configured") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if scoop.Bucket.Token != "" { | 	if scoop.Bucket.Token != "" { | ||||||
| @@ -85,7 +85,7 @@ func doRun(ctx *context.Context, cl client.Client) error { | |||||||
| 		return pipe.Skip("archive format is binary") | 		return pipe.Skip("archive format is binary") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var archives = ctx.Artifacts.Filter( | 	archives := ctx.Artifacts.Filter( | ||||||
| 		artifact.And( | 		artifact.And( | ||||||
| 			artifact.ByGoos("windows"), | 			artifact.ByGoos("windows"), | ||||||
| 			artifact.ByType(artifact.UploadableArchive), | 			artifact.ByType(artifact.UploadableArchive), | ||||||
| @@ -95,7 +95,7 @@ func doRun(ctx *context.Context, cl client.Client) error { | |||||||
| 		return ErrNoWindows | 		return ErrNoWindows | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var path = scoop.Name + ".json" | 	path := scoop.Name + ".json" | ||||||
|  |  | ||||||
| 	data, err := dataFor(ctx, cl, archives) | 	data, err := dataFor(ctx, cl, archives) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -170,7 +170,7 @@ func doBuildManifest(manifest Manifest) (bytes.Buffer, error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func dataFor(ctx *context.Context, cl client.Client, artifacts []*artifact.Artifact) (Manifest, error) { | func dataFor(ctx *context.Context, cl client.Client, artifacts []*artifact.Artifact) (Manifest, error) { | ||||||
| 	var manifest = Manifest{ | 	manifest := Manifest{ | ||||||
| 		Version:      ctx.Version, | 		Version:      ctx.Version, | ||||||
| 		Architecture: map[string]Resource{}, | 		Architecture: map[string]Resource{}, | ||||||
| 		Homepage:     ctx.Config.Scoop.Homepage, | 		Homepage:     ctx.Config.Scoop.Homepage, | ||||||
| @@ -239,7 +239,7 @@ func dataFor(ctx *context.Context, cl client.Client, artifacts []*artifact.Artif | |||||||
| func binaries(a *artifact.Artifact) []string { | func binaries(a *artifact.Artifact) []string { | ||||||
| 	// nolint: prealloc | 	// nolint: prealloc | ||||||
| 	var bins []string | 	var bins []string | ||||||
| 	var wrap = a.ExtraOr("WrappedIn", "").(string) | 	wrap := a.ExtraOr("WrappedIn", "").(string) | ||||||
| 	for _, b := range a.ExtraOr("Builds", []*artifact.Artifact{}).([]*artifact.Artifact) { | 	for _, b := range a.ExtraOr("Builds", []*artifact.Artifact{}).([]*artifact.Artifact) { | ||||||
| 		bins = append(bins, filepath.Join(wrap, b.Name)) | 		bins = append(bins, filepath.Join(wrap, b.Name)) | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -469,7 +469,7 @@ func Test_doRun(t *testing.T) { | |||||||
| 				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"}, | 				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"}, | ||||||
| 				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"}, | 				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"}, | ||||||
| 			}, | 			}, | ||||||
| 			shouldErr("scoop section is not configured"), | 			shouldErr(pipe.ErrSkipDisabledPipe.Error()), | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"no publish", | 			"no publish", | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
|  |  | ||||||
| func (Pipe) Run(ctx *context.Context) error { | func (Pipe) Run(ctx *context.Context) error { | ||||||
| 	if !ctx.Snapshot { | 	if !ctx.Snapshot { | ||||||
| 		return pipe.Skip("not a snapshot") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
| 	name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate) | 	name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -22,15 +22,15 @@ func (Pipe) String() string { | |||||||
| // Run the pipe. | // Run the pipe. | ||||||
| func (Pipe) Run(ctx *context.Context) (err error) { | func (Pipe) Run(ctx *context.Context) (err error) { | ||||||
| 	if !ctx.Config.Source.Enabled { | 	if !ctx.Config.Source.Enabled { | ||||||
| 		return pipe.Skip("source pipe is disabled") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	name, err := tmpl.New(ctx).Apply(ctx.Config.Source.NameTemplate) | 	name, err := tmpl.New(ctx).Apply(ctx.Config.Source.NameTemplate) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	var filename = name + "." + ctx.Config.Source.Format | 	filename := name + "." + ctx.Config.Source.Format | ||||||
| 	var path = filepath.Join(ctx.Config.Dist, filename) | 	path := filepath.Join(ctx.Config.Dist, filename) | ||||||
| 	log.WithField("file", filename).Info("creating source archive") | 	log.WithField("file", filename).Info("creating source archive") | ||||||
| 	out, err := git.Clean(git.Run("archive", "-o", path, ctx.Git.FullCommit)) | 	out, err := git.Clean(git.Run("archive", "-o", path, ctx.Git.FullCommit)) | ||||||
| 	log.Debug(out) | 	log.Debug(out) | ||||||
| @@ -47,7 +47,7 @@ func (Pipe) Run(ctx *context.Context) (err error) { | |||||||
|  |  | ||||||
| // Default sets the pipe defaults. | // Default sets the pipe defaults. | ||||||
| func (Pipe) Default(ctx *context.Context) error { | func (Pipe) Default(ctx *context.Context) error { | ||||||
| 	var archive = &ctx.Config.Source | 	archive := &ctx.Config.Source | ||||||
| 	if archive.Format == "" { | 	if archive.Format == "" { | ||||||
| 		archive.Format = "tar.gz" | 		archive.Format = "tar.gz" | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
| // Publish artifacts. | // Publish artifacts. | ||||||
| func (Pipe) Publish(ctx *context.Context) error { | func (Pipe) Publish(ctx *context.Context) error { | ||||||
| 	if len(ctx.Config.Uploads) == 0 { | 	if len(ctx.Config.Uploads) == 0 { | ||||||
| 		return pipe.Skip("uploads section is not configured") | 		return pipe.ErrSkipDisabledPipe | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Check requirements for every instance we have configured. | 	// Check requirements for every instance we have configured. | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ Configuration options available are described bellow. | |||||||
| gomod: | gomod: | ||||||
|   # Proxy a module from proxy.golang.org, making the builds verifiable. |   # Proxy a module from proxy.golang.org, making the builds verifiable. | ||||||
|   # This will only be effective if running against a tag. Snapshots will ignore this setting. |   # This will only be effective if running against a tag. Snapshots will ignore this setting. | ||||||
|   # PS: for this to work you `build.main` must be a package, not a `.go` file. |   # Notice: for this to work you `build.main` must be a package, not a `.go` file. | ||||||
|   # |   # | ||||||
|   # Default is false. |   # Default is false. | ||||||
|   proxy: true |   proxy: true | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user