mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-24 23:00:39 +00:00
fix: fix auto_tag behavior to avoid unexpected publishing (#68)
BREAKING CHANGE: `latest` has been removed from the default `tags` list, which is now empty. You must specify `auto_tag` or `tags` option, otherwise the plugin will build but __never__ tag and push the image.
This commit is contained in:
parent
a3e33afdf6
commit
17016c9f49
@ -117,7 +117,6 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
|||||||
Name: "tags",
|
Name: "tags",
|
||||||
EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"},
|
EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"},
|
||||||
Usage: "sets repository tags to use for the image",
|
Usage: "sets repository tags to use for the image",
|
||||||
Value: cli.NewStringSlice([]string{"latest"}...),
|
|
||||||
FilePath: ".tags",
|
FilePath: ".tags",
|
||||||
Destination: &settings.Build.Tags,
|
Destination: &settings.Build.Tags,
|
||||||
},
|
},
|
||||||
|
@ -84,7 +84,7 @@ func commandBuild(build Build, dryrun bool) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, build.Context)
|
args = append(args, build.Context)
|
||||||
if !dryrun {
|
if !dryrun && len(build.Tags.Value()) > 0 {
|
||||||
args = append(args, "--push")
|
args = append(args, "--push")
|
||||||
}
|
}
|
||||||
if build.Compress {
|
if build.Compress {
|
||||||
|
@ -87,12 +87,12 @@ func (p *Plugin) Validate() error {
|
|||||||
p.settings.Build.TagsSuffix,
|
p.settings.Build.TagsSuffix,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Printf("cannot build docker image for %s, invalid semantic version", p.settings.Build.Ref)
|
logrus.Printf("cannot generate tags from %s, invalid semantic version", p.settings.Build.Ref)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.settings.Build.Tags = *cli.NewStringSlice(tag...)
|
p.settings.Build.Tags = *cli.NewStringSlice(tag...)
|
||||||
} else {
|
} else {
|
||||||
logrus.Printf("skipping automated docker build for %s", p.settings.Build.Ref)
|
logrus.Printf("skip auto-tagging for %s, not on default branch or tag", p.settings.Build.Ref)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func TestDefaultTags(t *testing.T) {
|
|||||||
After []string
|
After []string
|
||||||
}{
|
}{
|
||||||
{"", []string{"latest"}},
|
{"", []string{"latest"}},
|
||||||
{"refs/heads/master", []string{"latest"}},
|
{"refs/heads/main", []string{"latest"}},
|
||||||
{"refs/tags/0.9.0", []string{"0.9", "0.9.0"}},
|
{"refs/tags/0.9.0", []string{"0.9", "0.9.0"}},
|
||||||
{"refs/tags/1.0.0", []string{"1", "1.0", "1.0.0"}},
|
{"refs/tags/1.0.0", []string{"1", "1.0", "1.0.0"}},
|
||||||
{"refs/tags/v1.0.0", []string{"1", "1.0", "1.0.0"}},
|
{"refs/tags/v1.0.0", []string{"1", "1.0", "1.0.0"}},
|
||||||
@ -142,9 +142,9 @@ func Test_stripHeadPrefix(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
args: args{
|
args: args{
|
||||||
ref: "refs/heads/master",
|
ref: "refs/heads/main",
|
||||||
},
|
},
|
||||||
want: "master",
|
want: "main",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@ -167,8 +167,8 @@ func TestUseDefaultTag(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "latest tag for default branch",
|
name: "latest tag for default branch",
|
||||||
args: args{
|
args: args{
|
||||||
ref: "refs/heads/master",
|
ref: "refs/heads/main",
|
||||||
defaultBranch: "master",
|
defaultBranch: "main",
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
@ -176,7 +176,7 @@ func TestUseDefaultTag(t *testing.T) {
|
|||||||
name: "build from tags",
|
name: "build from tags",
|
||||||
args: args{
|
args: args{
|
||||||
ref: "refs/tags/v1.0.0",
|
ref: "refs/tags/v1.0.0",
|
||||||
defaultBranch: "master",
|
defaultBranch: "main",
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
@ -184,7 +184,7 @@ func TestUseDefaultTag(t *testing.T) {
|
|||||||
name: "skip build for not default branch",
|
name: "skip build for not default branch",
|
||||||
args: args{
|
args: args{
|
||||||
ref: "refs/heads/develop",
|
ref: "refs/heads/develop",
|
||||||
defaultBranch: "master",
|
defaultBranch: "main",
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user