From 19cf9c7dd62fed2d4e3acdb924a0b3af261c078d Mon Sep 17 00:00:00 2001 From: "t.behrendt" Date: Thu, 5 Feb 2026 17:15:14 +0100 Subject: [PATCH] refactor: remove handling of sole repository, always require both repo and tag --- .gitea/workflows/ci.yaml | 5 +---- get-images-from-files/README.md | 2 +- get-images-from-files/action.yaml | 10 ++++------ get-images-from-files/test-values-helmfile.yaml | 6 ------ 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index d74f49a..d83e40c 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -69,9 +69,6 @@ jobs: check "Helmfile image (repository+tag)" "example.com/helmfile/app:v4" check "Helmfile images.worker (repository+tag)" "example.com/helmfile/worker:v5" check "Helmfile images.helper (repository+tag with digest)" "example.com/myproject/helper:2.0@sha256:cccc" - check "Helmfile repository only (no tag)" "example.com/helmfile/repo-only" - echo -n " Helmfile tag only (skipped, no output): " - echo "$images" | grep -q ':v99' && { echo "FAIL (orphan tag should be skipped)"; exit 1; } || echo "OK" # Shared ref (in both files) — must appear exactly once check "Shared ref present (distroless/static:nonroot)" "example.com/distroless/static:nonroot" @@ -80,7 +77,7 @@ jobs: [ "$count" -eq 1 ] && echo "OK (count=$count)" || { echo "FAIL (count=$count, expected 1)"; exit 1; } total=$(echo "$images" | tr ',' '\n' | grep -c . || true) echo -n " Total unique refs: " - [ "$total" -eq 11 ] && echo "OK ($total)" || { echo "FAIL (got $total, expected 11)"; exit 1; } + [ "$total" -eq 10 ] && echo "OK ($total)" || { echo "FAIL (got $total, expected 10)"; exit 1; } echo "" echo "All checks passed." diff --git a/get-images-from-files/README.md b/get-images-from-files/README.md index b267087..faa70bf 100644 --- a/get-images-from-files/README.md +++ b/get-images-from-files/README.md @@ -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=... `). | | **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`). diff --git a/get-images-from-files/action.yaml b/get-images-from-files/action.yaml index 0b35e4f..5fe4084 100644 --- a/get-images-from-files/action.yaml +++ b/get-images-from-files/action.yaml @@ -32,17 +32,15 @@ runs: awk '/^[[:space:]]*FROM[[:space:]]/ { print $NF }' "$f" 2>/dev/null || true # Kubernetes / Docker Compose: image: 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, diff --git a/get-images-from-files/test-values-helmfile.yaml b/get-images-from-files/test-values-helmfile.yaml index 8ec7997..7eebf02 100644 --- a/get-images-from-files/test-values-helmfile.yaml +++ b/get-images-from-files/test-values-helmfile.yaml @@ -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"