From 57af30fdd27badafd6d1ae892f121ec4eaef9852 Mon Sep 17 00:00:00 2001 From: Daniel Arroyo Date: Wed, 9 Sep 2026 12:10:17 -0300 Subject: [PATCH] fix: read_pom fallback returned both artifactId and version When xmllint is not in PATH, the grep fallback in read_pom() captured both and in a single multi-line string and returned it for every call. Concatenating it with ':' produced an invalid Docker tag like: test-quarkus\n1.0.0-SNAPSHOT:test-quarkus\n1.0.0-SNAPSHOT causing 'docker build' to fail with 'invalid reference format'. Add a third 'tag' argument to read_pom() so the fallback extracts only the requested element, and pass 'artifactId' / 'version' from the call sites. Also enrich pom.xml with and for Maven/IDE metadata, without changing the image identity. Tests cover the no-xmllint path explicitly (PATH stripped to reproduce the vm-compilador environment) and the override path. --- pom.xml | 5 +++++ scripts/build-and-push.sh | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 598ab42..383d922 100644 --- a/pom.xml +++ b/pom.xml @@ -5,6 +5,11 @@ com.example test-quarkus 1.0.0-SNAPSHOT + jar + + Test Quarkus + Sample Quarkus application exposing /status and /q/health endpoints + 3.15.0 17 diff --git a/scripts/build-and-push.sh b/scripts/build-and-push.sh index fc61487..eda4c5d 100755 --- a/scripts/build-and-push.sh +++ b/scripts/build-and-push.sh @@ -102,14 +102,14 @@ EOF } read_pom() { - local xpath="$1" fallback="$2" + local xpath="$1" fallback="$2" tag="${3:-}" local value="" if command -v xmllint >/dev/null 2>&1; then value=$(xmllint --xpath "string($xpath)" pom.xml 2>/dev/null || true) fi - if [[ -z "$value" ]]; then - value=$(grep -E "|" pom.xml | head -2 \ - | sed -E 's:.*<(artifactId|version)>(.*).*:\2:') + if [[ -z "$value" && -n "$tag" ]]; then + value=$(grep -E "<${tag}>" pom.xml | head -1 \ + | sed -E "s:.*<${tag}>(.*).*:\1:") fi printf '%s' "${value:-$fallback}" } @@ -201,8 +201,8 @@ fi PROJECT_DIR="$(pwd)" # ---------- defaults ---------- -[[ -z "$IMAGE_NAME" ]] && IMAGE_NAME=$(read_pom "/*[local-name()='project']/*[local-name()='artifactId']" "test-quarkus") -[[ -z "$IMAGE_TAG" ]] && IMAGE_TAG=$(read_pom "/*[local-name()='project']/*[local-name()='version']" "1.0.0-SNAPSHOT") +[[ -z "$IMAGE_NAME" ]] && IMAGE_NAME=$(read_pom "/*[local-name()='project']/*[local-name()='artifactId']" "test-quarkus" "artifactId") +[[ -z "$IMAGE_TAG" ]] && IMAGE_TAG=$(read_pom "/*[local-name()='project']/*[local-name()='version']" "1.0.0-SNAPSHOT" "version") [[ -z "$REMOTE" ]] && die "Missing --remote USER@HOST[:PORT] (use --help)." IMAGE_REF="${IMAGE_NAME}:${IMAGE_TAG}"