Skip to content

Commit 0592c3e

Browse files
committed
feat(melange/maven): enhance pombump pipeline with analyze mode and BOM detection
- Add analyze mode to pombump pipeline for intelligent dependency analysis before patching. - Supports BOM detection, JSON/YAML output, property search, and automated patch file generation. - Includes fail-on-bom-conflicts option for safer automated patching workflows. Signed-off-by: Kyle Steere <kyle.steere@chainguard.dev>
1 parent d10daea commit 0592c3e

File tree

1 file changed

+125
-30
lines changed

1 file changed

+125
-30
lines changed
Lines changed: 125 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
1-
name: Run pombump tool to update versions and properties in a Maven POM file
1+
name: Run pombump tool to analyze and update versions and properties in a Maven POM file
22
needs:
33
packages:
44
- busybox
55
- pombump
6+
- jq
67

78
inputs:
9+
# Mode selection
10+
mode:
11+
description: |
12+
Mode of operation: 'patch' to apply changes, 'analyze' to analyze POM and get recommendations
13+
default: patch
14+
15+
# Analysis inputs
16+
analyze-patches:
17+
description: |
18+
Space-separated list of patches to analyze (groupID@artifactID@version) for recommendations
19+
analyze-patch-file:
20+
description: |
21+
Patch file to analyze for recommendations
22+
output-format:
23+
description: |
24+
Output format for analysis: human, json, or yaml
25+
default: human
26+
search-properties:
27+
description: |
28+
Search for properties in parent POMs and modules (analyze mode only)
29+
default: false
30+
generate-patch-files:
31+
description: |
32+
Generate recommended patch files from analysis (creates pombump-deps.yaml and pombump-properties.yaml)
33+
default: false
34+
output-deps:
35+
description: |
36+
Output file for recommended dependency patches (analyze mode)
37+
default: ./pombump-deps.yaml
38+
output-properties:
39+
description: |
40+
Output file for recommended property patches (analyze mode)
41+
default: ./pombump-properties.yaml
42+
43+
# Patching inputs
844
patch-file:
945
description: |
1046
Patches file to use for updating the POM file
@@ -19,50 +55,109 @@ inputs:
1955
properties:
2056
description: |
2157
Properties to update / add the POM file via command line flag
58+
59+
# Common inputs
2260
pom:
2361
description: |
2462
Path to pom.xml
2563
default: pom.xml
2664
debug:
2765
description: |
28-
Enable debug mode, which will print out the diffs of the pom.xml file after running pombump
66+
Enable debug mode, which will print out the diffs of the pom.xml file after running pombump (patch mode) or detailed analysis (analyze mode)
2967
default: false
3068
show-dependency-tree:
3169
default: false
3270
description: Display a dependency tree for the existing pom.xml file
71+
72+
fail-on-bom-conflicts:
73+
description: |
74+
Fail if attempting to patch dependencies controlled by BOMs (analyze mode).
75+
Only use for strict BOM enforcement.
76+
default: false
77+
json-output-file:
78+
description: |
79+
File to save JSON analysis output (analyze mode only)
3380
3481
pipeline:
3582
- runs: |
36-
PATCH_FILE_FLAG=""
37-
PROPERTIES_FILE_FLAG=""
38-
DEPENDENCIES_FLAG=""
39-
PROPERTIES_FLAG=""
40-
41-
if [ -f "${{inputs.patch-file}}" ]; then
42-
PATCH_FILE_FLAG="--patch-file ${{inputs.patch-file}}"
43-
fi
44-
45-
if [ -f "${{inputs.properties-file}}" ]; then
46-
PROPERTIES_FILE_FLAG="--properties-file ${{inputs.properties-file}}"
47-
fi
48-
49-
if [ -n "${{inputs.dependencies}}" ]; then
50-
DEPENDENCIES_FLAG="--dependencies ${{inputs.dependencies}}"
51-
fi
52-
53-
if [ -n "${{inputs.properties}}" ]; then
54-
PROPERTIES_FLAG="--properties ${{inputs.properties}}"
55-
fi
56-
83+
# Show dependency tree if requested
5784
if [ "${{inputs.show-dependency-tree}}" = "true" ]; then
58-
mvn dependency:tree
85+
mvn dependency:tree || echo "Note: Maven dependency tree failed, continuing..."
5986
fi
6087
61-
pombump ${{inputs.pom}} $PATCH_FILE_FLAG $PROPERTIES_FILE_FLAG $DEPENDENCIES_FLAG $PROPERTIES_FLAG > "${{inputs.pom}}.new"
88+
if [ "${{inputs.mode}}" = "analyze" ]; then
89+
echo "Running pombump in analyze mode..."
90+
91+
# Build analyze command
92+
CMD="pombump analyze ${{inputs.pom}}"
93+
94+
[ -n "${{inputs.output-format}}" ] && CMD="$CMD --output ${{inputs.output-format}}"
95+
[ "${{inputs.search-properties}}" = "true" ] && CMD="$CMD --search-properties"
96+
[ -f "${{inputs.analyze-patch-file}}" ] && CMD="$CMD --patch-file ${{inputs.analyze-patch-file}}"
97+
98+
if [ "${{inputs.generate-patch-files}}" = "true" ]; then
99+
CMD="$CMD --output-deps ${{inputs.output-deps}} --output-properties ${{inputs.output-properties}}"
100+
fi
101+
102+
# Handle analyze-patches separately due to quoting needs
103+
if [ -n "${{inputs.analyze-patches}}" ]; then
104+
CMD="$CMD --patches \"${{inputs.analyze-patches}}\""
105+
fi
106+
107+
# Execute analyze command
108+
if [ -n "${{inputs.json-output-file}}" ]; then
109+
eval "$CMD" > "${{inputs.json-output-file}}"
110+
echo "Analysis saved to ${{inputs.json-output-file}}"
111+
112+
if [ "${{inputs.debug}}" = "true" ]; then
113+
echo "=== Analysis Summary ==="
114+
jq -r '
115+
"Dependencies: \(.dependencies.total) total, \(.dependencies.direct) direct",
116+
"Using properties: \(.dependencies.using_properties)",
117+
"From BOMs: \(.dependencies.from_boms // 0)",
118+
"BOMs detected: \(.boms | length // 0)",
119+
"Recommended property updates: \(.property_updates | length // 0)",
120+
"Recommended direct patches: \(.patches | length // 0)"
121+
' "${{inputs.json-output-file}}" || true
122+
fi
123+
124+
# Check for BOM conflicts
125+
if [ "${{inputs.fail-on-bom-conflicts}}" = "true" ]; then
126+
if jq -e '.warnings | map(select(contains("BOM"))) | length > 0' "${{inputs.json-output-file}}" > /dev/null 2>&1; then
127+
echo "ERROR: BOM conflicts detected. Dependencies are controlled by imported BOMs."
128+
echo "Please update the BOM version instead of individual dependencies."
129+
jq -r '.warnings[]' "${{inputs.json-output-file}}" 2>/dev/null || true
130+
exit 1
131+
fi
132+
fi
133+
else
134+
eval "$CMD"
135+
fi
136+
137+
# Show generated patch files
138+
if [ "${{inputs.generate-patch-files}}" = "true" ] && [ "${{inputs.debug}}" = "true" ]; then
139+
echo "=== Generated Patch Files ==="
140+
[ -f "${{inputs.output-deps}}" ] && echo "Dependency patches: ${{inputs.output-deps}}" && cat "${{inputs.output-deps}}"
141+
[ -f "${{inputs.output-properties}}" ] && echo "Property patches: ${{inputs.output-properties}}" && cat "${{inputs.output-properties}}"
142+
fi
143+
144+
else
145+
echo "Running pombump in patch mode..."
146+
147+
# Build patch command
148+
CMD="pombump \"${{inputs.pom}}\""
149+
150+
[ -f "${{inputs.patch-file}}" ] && CMD="$CMD --patch-file \"${{inputs.patch-file}}\""
151+
[ -f "${{inputs.properties-file}}" ] && CMD="$CMD --properties-file \"${{inputs.properties-file}}\""
152+
[ -n "${{inputs.dependencies}}" ] && CMD="$CMD --dependencies \"${{inputs.dependencies}}\""
153+
[ -n "${{inputs.properties}}" ] && CMD="$CMD --properties \"${{inputs.properties}}\""
154+
155+
eval "$CMD" > "${{inputs.pom}}.new"
62156
63-
if [ "${{inputs.debug}}" = "true" ]; then
64-
# If there are any differences, it will return a non-zero exit code, so we use `|| true` to ignore that
65-
diff -w "${{inputs.pom}}" "${{inputs.pom}}.new" || true
66-
fi
157+
if [ "${{inputs.debug}}" = "true" ]; then
158+
echo "=== POM Changes ==="
159+
diff -w "${{inputs.pom}}" "${{inputs.pom}}.new" || true
160+
fi
67161
68-
mv "${{inputs.pom}}.new" ${{inputs.pom}}
162+
mv "${{inputs.pom}}.new" "${{inputs.pom}}"
163+
fi

0 commit comments

Comments
 (0)