Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 17016c9

Browse files
authored
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.
1 parent a3e33af commit 17016c9

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

cmd/drone-docker-buildx/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
117117
Name: "tags",
118118
EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"},
119119
Usage: "sets repository tags to use for the image",
120-
Value: cli.NewStringSlice([]string{"latest"}...),
121120
FilePath: ".tags",
122121
Destination: &settings.Build.Tags,
123122
},

plugin/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func commandBuild(build Build, dryrun bool) *exec.Cmd {
8484
}
8585

8686
args = append(args, build.Context)
87-
if !dryrun {
87+
if !dryrun && len(build.Tags.Value()) > 0 {
8888
args = append(args, "--push")
8989
}
9090
if build.Compress {

plugin/impl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ func (p *Plugin) Validate() error {
8787
p.settings.Build.TagsSuffix,
8888
)
8989
if err != nil {
90-
logrus.Printf("cannot build docker image for %s, invalid semantic version", p.settings.Build.Ref)
90+
logrus.Printf("cannot generate tags from %s, invalid semantic version", p.settings.Build.Ref)
9191
return err
9292
}
9393
p.settings.Build.Tags = *cli.NewStringSlice(tag...)
9494
} else {
95-
logrus.Printf("skipping automated docker build for %s", p.settings.Build.Ref)
95+
logrus.Printf("skip auto-tagging for %s, not on default branch or tag", p.settings.Build.Ref)
9696
return nil
9797
}
9898
}

plugin/tags_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestDefaultTags(t *testing.T) {
2929
After []string
3030
}{
3131
{"", []string{"latest"}},
32-
{"refs/heads/master", []string{"latest"}},
32+
{"refs/heads/main", []string{"latest"}},
3333
{"refs/tags/0.9.0", []string{"0.9", "0.9.0"}},
3434
{"refs/tags/1.0.0", []string{"1", "1.0", "1.0.0"}},
3535
{"refs/tags/v1.0.0", []string{"1", "1.0", "1.0.0"}},
@@ -142,9 +142,9 @@ func Test_stripHeadPrefix(t *testing.T) {
142142
}{
143143
{
144144
args: args{
145-
ref: "refs/heads/master",
145+
ref: "refs/heads/main",
146146
},
147-
want: "master",
147+
want: "main",
148148
},
149149
}
150150
for _, tt := range tests {
@@ -167,24 +167,24 @@ func TestUseDefaultTag(t *testing.T) {
167167
{
168168
name: "latest tag for default branch",
169169
args: args{
170-
ref: "refs/heads/master",
171-
defaultBranch: "master",
170+
ref: "refs/heads/main",
171+
defaultBranch: "main",
172172
},
173173
want: true,
174174
},
175175
{
176176
name: "build from tags",
177177
args: args{
178178
ref: "refs/tags/v1.0.0",
179-
defaultBranch: "master",
179+
defaultBranch: "main",
180180
},
181181
want: true,
182182
},
183183
{
184184
name: "skip build for not default branch",
185185
args: args{
186186
ref: "refs/heads/develop",
187-
defaultBranch: "master",
187+
defaultBranch: "main",
188188
},
189189
want: false,
190190
},

0 commit comments

Comments
 (0)