From d17ff57fda3de0885ec004f23d76b42aa41cb9d8 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 6 Nov 2022 14:29:57 +0100 Subject: [PATCH] Document auto_tag behaviour more explicite (#37) close #31 Co-authored-by: Lauris BH Reviewed-on: https://codeberg.org/woodpecker-plugins/plugin-docker-buildx/pulls/37 Reviewed-by: Lauris BH --- docs.md | 6 ++++++ plugin/impl.go | 2 +- plugin/tags.go | 10 +++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs.md b/docs.md index 5644519..0ea18ad 100644 --- a/docs.md +++ b/docs.md @@ -40,6 +40,12 @@ It will automatically generate buildkit configuration to use custom CA certifica | `tag`/`tags` | @".tags" | sets repository tags to use for the image | `platforms` | *none* | sets target platform for build +## auto_tag + +If set to ture, it will use the `default_tag` ("latest") on tag event or default branch. +If it's a tag event it will also asume sem versioning and add taggs acordingly (`x`, `x.x` and `x.x.x`). +If it's not a tag event, and no default branch, automated tags are skipped. + ## Examples ```yml diff --git a/plugin/impl.go b/plugin/impl.go index 4db6bb1..de2ec40 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -123,7 +123,7 @@ func (p *Plugin) Validate() error { } if p.settings.Build.TagsAuto { - // return true if tag event or default branch + // we only generate tags on default branch or an tag event if UseDefaultTag( p.settings.Build.Ref, p.settings.Build.Branch, diff --git a/plugin/tags.go b/plugin/tags.go index a141e89..99c188e 100644 --- a/plugin/tags.go +++ b/plugin/tags.go @@ -73,14 +73,10 @@ func DefaultTags(ref, defaultTag string) ([]string, error) { } // UseDefaultTag for keep only default branch for latest tag +// return true if tag event or default branch func UseDefaultTag(ref, defaultBranch string) bool { - if strings.HasPrefix(ref, "refs/tags/") { - return true - } - if stripHeadPrefix(ref) == defaultBranch { - return true - } - return false + return strings.HasPrefix(ref, "refs/tags/") || + stripHeadPrefix(ref) == defaultBranch } func stripHeadPrefix(ref string) string {