Skip to content

Commit dac339c

Browse files
committed
feature(bake): add additional tag input
1 parent e5aac2d commit dac339c

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

buildx-bake/promote/action.yml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ inputs:
3030
description: 'Also tag with major.minor version'
3131
required: false
3232
default: 'true'
33+
additional-tags:
34+
description: 'Additional tags to apply (comma-separated, e.g. "stable,prod")'
35+
required: false
36+
default: ''
3337
runs:
3438
using: "composite"
3539
steps:
@@ -51,43 +55,46 @@ runs:
5155
TAG_LATEST: ${{ inputs.tag-latest }}
5256
TAG_MAJOR: ${{ inputs.tag-major }}
5357
TAG_MINOR: ${{ inputs.tag-minor }}
58+
ADDITIONAL_TAGS: ${{ inputs.additional-tags }}
5459
run: |
5560
import json, os, re, subprocess
5661
62+
# Parse inputs
5763
version = os.environ["VERSION"]
5864
image_digests = json.loads(os.environ["IMAGE_DIGESTS"])
59-
tag_latest = os.environ["TAG_LATEST"].lower() == "true"
60-
tag_major = os.environ["TAG_MAJOR"].lower() == "true"
61-
tag_minor = os.environ["TAG_MINOR"].lower() == "true"
65+
66+
is_true = lambda v: v.lower() in {"true", "1", "yes"}
67+
flags = {k: is_true(os.environ.get(k, "false"))
68+
for k in ("TAG_LATEST", "TAG_MAJOR", "TAG_MINOR")}
6269
6370
# Parse semantic version
6471
m = re.match(r"^v?(\d+)\.(\d+)\.(\d+)", version)
6572
if not m:
6673
raise ValueError(f"Invalid semantic version: {version}")
6774
major, minor, patch = m.groups()
68-
version_clean = f"{major}.{minor}.{patch}"
6975
7076
# Build tag list
71-
tags = [version_clean]
72-
if tag_minor:
77+
tags = [f"{major}.{minor}.{patch}"]
78+
if flags["TAG_MINOR"]:
7379
tags.append(f"{major}.{minor}")
74-
if tag_major:
80+
if flags["TAG_MAJOR"]:
7581
tags.append(major)
76-
if tag_latest:
82+
if flags["TAG_LATEST"]:
7783
tags.append("latest")
7884
79-
print(f"Promoting version: {version_clean}", flush=True)
80-
print(f"Tags: {', '.join(tags)}", flush=True)
85+
# Add additional tags
86+
if extra := os.environ.get("ADDITIONAL_TAGS", "").strip():
87+
tags.extend(filter(None, (t.strip() for t in extra.split(","))))
8188
82-
def run(cmd):
83-
print(f"+ {' '.join(cmd)}", flush=True)
84-
subprocess.run(cmd, check=True)
89+
print(f"Promoting: {tags[0]}", flush=True)
90+
print(f"Flags: latest={flags['TAG_LATEST']}, major={flags['TAG_MAJOR']}, minor={flags['TAG_MINOR']}")
91+
print(f"Tags: {', '.join(tags)}\n", flush=True)
8592
8693
# Promote each image
8794
for item in image_digests:
88-
image_name = item["name"]
89-
digest = item["digest"]
90-
source = f"{image_name}@{digest}"
91-
tag_args = [a for t in tags for a in ("-t", f"{image_name}:{t}")]
92-
print(f"\nPromoting: {source}", flush=True)
93-
run(["docker", "buildx", "imagetools", "create", *tag_args, source])
95+
name, digest = item["name"], item["digest"]
96+
source = f"{name}@{digest}"
97+
cmd = ["docker", "buildx", "imagetools", "create",
98+
*[a for t in tags for a in ("-t", f"{name}:{t}")], source]
99+
print(f"+ {' '.join(cmd)}", flush=True)
100+
subprocess.run(cmd, check=True)

0 commit comments

Comments
 (0)