Skip to content

Refactor get-version#4

Open
ngonzalezpazFC wants to merge 2 commits intomainfrom
fix-2
Open

Refactor get-version#4
ngonzalezpazFC wants to merge 2 commits intomainfrom
fix-2

Conversation

@ngonzalezpazFC
Copy link
Copy Markdown

@ngonzalezpazFC ngonzalezpazFC commented Apr 21, 2026

Instead of capturing the first occurrence of the tag, which often points to the parent-pom in Maven architectures, it now identifies the project's specific version by targeting the second occurrence in the document hierarchy.

Logic Breakdown:

  1. Tag Isolation: The grep "<version>" command scans the pom.xml and retrieves all lines containing versioning information, preserving their document order.
  2. Stream Cleaning: Using sed -E 's/.*<version>(.*)<\/version>.*/\1/', the script applies a Regular Expression to strip XML tags and leading/trailing whitespace, isolating the raw version string (e.g., 1.1.0-SNAPSHOT).
  3. Positional Selection: In a standard Maven POM with a parent, the first match is the Parent Version. The second match (sed -n '2p') is the Project Artifact Version.
  4. Conditional Fallback: The script includes a safety check: if no second line exists (indicating a standalone project without a parent), it defaults to the first match (sed -n '1p').
  5. Environment Integration: The resulting string is piped through xargs to ensure absolute character purity before being injected into the $GITHUB_ENV for downstream validation steps.

Close #2

Get version identifies the project's specific version by targeting the second occurrence in the document hierarchy.
Contains conditional fallback if pom does not have parent.

Close #2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check-commits does not support parent POM

1 participant