refactor: remove handling of sole repository, always require both repo and tag
This commit is contained in:
@@ -11,7 +11,7 @@ A reusable Gitea Action that extracts Docker image references from selected file
|
||||
| **Dockerfile** | `FROM` lines; the image ref is the last token (handles `FROM --platform=... <image>`). |
|
||||
| **Kubernetes manifests** | Lines with `image:` (e.g. under `containers` / `initContainers`); the value is taken as the image ref. |
|
||||
| **Docker Compose / Compose** | Same as Kubernetes: `image:` key under services. |
|
||||
| **Helmfile values** | Pairs of `repository` and optional `tag` at the same indent; ref is `repository` or `repository:tag`. A lone `tag` without `repository` is skipped. |
|
||||
| **Helmfile values** | Pairs of `repository` and `tag` (both required) at the same indent; ref is `repository:tag`. A lone `tag` without `repository` is skipped. |
|
||||
|
||||
Other files are supported if they use one of these patterns (e.g. `image:` or `FROM`).
|
||||
|
||||
|
||||
@@ -32,17 +32,15 @@ runs:
|
||||
awk '/^[[:space:]]*FROM[[:space:]]/ { print $NF }' "$f" 2>/dev/null || true
|
||||
# Kubernetes / Docker Compose: image: <ref>
|
||||
grep -E '[[:space:]]image:[[:space:]]' "$f" 2>/dev/null | sed 's/.*image:[[:space:]]*//' | awk '{ print $1 }' || true
|
||||
# Helmfile values: repository (required), tag optional (by indent); tag without repo is skipped
|
||||
# Helmfile values: repository + tag (both required, by indent); tag without repo is skipped
|
||||
awk '
|
||||
match($0, /^[[:space:]]*/) { indent = RLENGTH }
|
||||
/^[[:space:]]*repository:[[:space:]]/ {
|
||||
v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); repo[indent] = v;
|
||||
if (tag[indent] != "") { print repo[indent] ":" tag[indent] } else { print repo[indent] };
|
||||
delete repo[indent]; delete tag[indent]; next
|
||||
v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); repo[indent] = v; next
|
||||
}
|
||||
/^[[:space:]]*tag:[[:space:]]/ {
|
||||
v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); tag[indent] = v;
|
||||
if (repo[indent] != "") { print repo[indent] ":" tag[indent]; delete repo[indent]; delete tag[indent] } else { delete tag[indent] }; next
|
||||
v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v);
|
||||
if (repo[indent] != "") { print repo[indent] ":" v; delete repo[indent] }; next
|
||||
}
|
||||
' "$f" 2>/dev/null || true
|
||||
done | grep -E '/' | sort -u | paste -sd,
|
||||
|
||||
@@ -12,9 +12,3 @@ images:
|
||||
helper:
|
||||
repository: example.com/myproject/helper
|
||||
tag: "2.0@sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
|
||||
# Repository only (no tag) — should be extracted
|
||||
repo_only:
|
||||
repository: example.com/helmfile/repo-only
|
||||
# Tag only (no repository) — should be skipped
|
||||
tag_only:
|
||||
tag: "v99"
|
||||
|
||||
Reference in New Issue
Block a user