1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00

fix: improve docker publish skipping (#3184)

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2022-06-23 08:49:33 -03:00 committed by GitHub
parent 8424c92102
commit 0a2e8fcada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 14 deletions

View File

@ -88,13 +88,18 @@ func validateImager(use string) error {
// Publish the docker images.
func (Pipe) Publish(ctx *context.Context) error {
skips := pipe.SkipMemento{}
images := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableDockerImage)).List()
for _, image := range images {
if err := dockerPush(ctx, image); err != nil {
if pipe.IsSkip(err) {
skips.Remember(err)
continue
}
return err
}
}
return nil
return skips.Evaluate()
}
// Run the pipe.
@ -187,15 +192,6 @@ func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.A
return err
}
if strings.TrimSpace(docker.SkipPush) == "true" {
return pipe.Skip("docker.skip_push is set")
}
if ctx.SkipPublish {
return pipe.ErrSkipPublishEnabled
}
if strings.TrimSpace(docker.SkipPush) == "auto" && ctx.Semver.Prerelease != "" {
return pipe.Skip("prerelease detected with 'auto' push, skipping docker publish")
}
for _, img := range images {
ctx.Artifacts.Add(&artifact.Artifact{
Type: artifact.PublishableDockerImage,
@ -245,10 +241,19 @@ func processBuildFlagTemplates(ctx *context.Context, docker config.Docker) ([]st
func dockerPush(ctx *context.Context, image *artifact.Artifact) error {
log.WithField("image", image.Name).Info("pushing")
docker := image.Extra[dockerConfigExtra].(config.Docker)
if strings.TrimSpace(docker.SkipPush) == "true" {
return pipe.Skip("docker.skip_push is set: " + image.Name)
}
if strings.TrimSpace(docker.SkipPush) == "auto" && ctx.Semver.Prerelease != "" {
return pipe.Skip("prerelease detected with 'auto' push, skipping docker publish: " + image.Name)
}
if err := imagers[docker.Use].Push(ctx, image.Name, docker.PushFlags); err != nil {
return err
}
art := &artifact.Artifact{
Type: artifact.DockerImage,
Name: image.Name,

View File

@ -656,7 +656,9 @@ func TestRunPipe(t *testing.T) {
registry + "goreleaser/test_run_pipe:latest",
},
assertImageLabels: noLabels,
assertError: testlib.AssertSkipped,
assertError: shouldNotErr,
pubAssertError: testlib.AssertSkipped,
manifestAssertError: shouldNotErr,
},
"one_img_error_with_skip_push": {
dockers: []config.Docker{
@ -840,7 +842,9 @@ func TestRunPipe(t *testing.T) {
registry + "goreleaser/mybin:latest",
},
assertImageLabels: noLabels,
assertError: testlib.AssertSkipped,
assertError: shouldNotErr,
pubAssertError: testlib.AssertSkipped,
manifestAssertError: shouldNotErr,
},
"no_permissions": {
dockers: []config.Docker{