Skip to content

Commit f88917c

Browse files
committed
add bom check
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 1815f1b commit f88917c

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

mise.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ run = "lychee --include-fragments ."
4646
[tasks.lint-gh-actions]
4747
run = "zizmor .github/"
4848

49+
[tasks.lint-bom]
50+
run = "scripts/lint-bom.sh"
51+
4952
[tasks.lint-rest]
5053
description = "All lints not covered by super linter"
51-
depends = ["lint-links", "lint-gh-actions"]
54+
depends = ["lint-links", "lint-gh-actions", "lint-bom"]
5255

5356
[tasks.acceptance-test]
5457
description = "Run OATs acceptance tests"

prometheus-metrics-bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
<artifactId>prometheus-metrics-exporter-opentelemetry-no-otel</artifactId>
5555
<version>${project.version}</version>
5656
</dependency>
57+
<dependency>
58+
<groupId>io.prometheus</groupId>
59+
<artifactId>prometheus-metrics-exporter-opentelemetry-otel-agent-resources</artifactId>
60+
<version>${project.version}</version>
61+
</dependency>
5762
<dependency>
5863
<groupId>io.prometheus</groupId>
5964
<artifactId>prometheus-metrics-exporter-pushgateway</artifactId>

scripts/lint-bom.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
function first_artifact_id() {
6+
local bom_file="$1"
7+
grep '<artifactId>' "$bom_file" | head -n 2 | tail -n 1 | sed 's/.*<artifactId>\(.*\)<\/artifactId>.*/\1/'
8+
}
9+
10+
function add_dir() {
11+
local dir="$1"
12+
if [[ ! -d "$dir" ]]; then
13+
echo "Directory $dir does not exist."
14+
exit 1
15+
fi
16+
17+
if [[ $ignore_dirs =~ $dir ]]; then
18+
echo "Skipping $dir"
19+
return
20+
fi
21+
22+
if [[ ! -f "$dir/pom.xml" ]]; then
23+
echo "File $dir/pom.xml does not exist."
24+
exit 1
25+
fi
26+
27+
artifact_id=$(first_artifact_id "$dir/pom.xml")
28+
if [[ -z "$artifact_id" ]]; then
29+
echo "No artifactId found in $dir/pom.xml"
30+
exit 1
31+
fi
32+
33+
echo "Found artifactId '$artifact_id' in $dir/pom.xml"
34+
# add to want
35+
if [[ -z "${want+x}" ]]; then
36+
want="$artifact_id"
37+
else
38+
want="$want
39+
$artifact_id"
40+
fi
41+
}
42+
43+
declare want
44+
ignore_dirs="prometheus-metrics-parent"
45+
46+
for dir in prometheus-metrics*; do
47+
add_dir "$dir"
48+
done
49+
for dir in prometheus-metrics-tracer/prometheus-metrics* ; do
50+
if [[ -d "$dir" ]]; then
51+
add_dir "$dir"
52+
fi
53+
done
54+
55+
want=$(echo "$want" | sort | uniq)
56+
have="$(grep '<artifactId>prometheus-metrics' prometheus-metrics-bom/pom.xml | sed 's/.*<artifactId>\(.*\)<\/artifactId>.*/\1/'| sort)"
57+
58+
if [[ "$want" != "$have" ]]; then
59+
echo "The BOM file prometheus-metrics-bom/bom.xml does not match the current directory contents."
60+
echo "Expected: $want"
61+
echo "Found: $have"
62+
63+
diff -u <(echo "$have" ) <(echo "$want")
64+
65+
exit 1
66+
else
67+
echo "BOM file is up to date."
68+
fi

0 commit comments

Comments
 (0)