Skip to content

Commit 3d0983a

Browse files
authored
Add validate-components make target as part of CI (#794)
Verify that all components declared in manifest.yaml files are defined in the builder-config.yaml from the opentelemetry-collector-contrib repository, ensuring they were built and tested successfully.
1 parent 2747f2e commit 3d0983a

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CHLOGGEN_CONFIG := .chloggen/config.yaml
1919
DISTRIBUTIONS ?= "otelcol,otelcol-contrib,otelcol-k8s,otelcol-otlp"
2020

2121
ci: check build
22-
check: ensure-goreleaser-up-to-date
22+
check: ensure-goreleaser-up-to-date validate-components
2323

2424
build: go ocb
2525
@./scripts/build.sh -d "${DISTRIBUTIONS}" -b ${OTELCOL_BUILDER}
@@ -38,6 +38,9 @@ goreleaser-verify: goreleaser
3838
ensure-goreleaser-up-to-date: generate-goreleaser
3939
@git diff -s --exit-code distributions/*/.goreleaser.yaml || (echo "Check failed: The goreleaser templates have changed but the .goreleaser.yamls haven't. Run 'make generate-goreleaser' and update your PR." && exit 1)
4040

41+
validate-components:
42+
@./scripts/validate-components.sh
43+
4144
.PHONY: ocb
4245
ocb:
4346
ifeq (, $(shell command -v ocb 2>/dev/null))

scripts/validate-components.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
# Copyright The OpenTelemetry Authors
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# This script verifies that all components declared in manifest.yaml files are
7+
# defined in the builder-config.yaml from the opentelemetry-collector-contrib
8+
# repository, ensuring they were built and tested successfully.
9+
10+
set -euo pipefail
11+
12+
BUILDER_CONFIG_URL="https://raw.githubusercontent.com/open-telemetry/opentelemetry-collector-contrib/main/cmd/otelcontribcol/builder-config.yaml"
13+
MANIFEST_DIR="distributions"
14+
15+
# Ensure required tools are available
16+
if ! command -v curl &> /dev/null || ! command -v yq &> /dev/null; then
17+
echo "This script requires 'curl' and 'yq'. Please install them and try again."
18+
exit 1
19+
fi
20+
21+
# Fetch and parse valid components from builder-config.yaml
22+
echo "Fetching builder-config.yaml..."
23+
valid_components="$(
24+
curl -s "$BUILDER_CONFIG_URL" \
25+
| yq -r '
26+
(
27+
.extensions[]?.gomod,
28+
.receivers[]?.gomod,
29+
.connectors[]?.gomod,
30+
.processors[]?.gomod,
31+
.exporters[]?.gomod,
32+
.providers[]?.gomod
33+
)
34+
' \
35+
| awk '{print $1}' \
36+
| sort -u
37+
)"
38+
39+
if [[ -z "$valid_components" ]]; then
40+
echo "Error: No valid 'gomod' entries found in builder-config.yaml!"
41+
exit 1
42+
fi
43+
44+
echo "Verifying all manifest.yaml files in '${MANIFEST_DIR}'..."
45+
46+
# We accumulate invalid components here as a multi-line string
47+
invalid_components=""
48+
49+
# Use process substitution to avoid subshell issues
50+
while IFS= read -r manifest_file; do
51+
echo "Checking $manifest_file"
52+
53+
# Extract and trim components from the local manifest.yaml
54+
manifest_components="$(
55+
yq -r '
56+
(
57+
.extensions[]?.gomod,
58+
.receivers[]?.gomod,
59+
.connectors[]?.gomod,
60+
.processors[]?.gomod,
61+
.exporters[]?.gomod,
62+
.providers[]?.gomod
63+
)
64+
' "$manifest_file" \
65+
| awk '{print $1}' \
66+
| sort -u
67+
)"
68+
69+
# Compare each manifest component against the valid list
70+
while IFS= read -r component; do
71+
if ! printf '%s\n' "$valid_components" | grep -qxF "$component"; then
72+
invalid_components="${invalid_components}\n${component}"
73+
fi
74+
done <<< "$manifest_components"
75+
76+
done < <(find "$MANIFEST_DIR" -type f -name "manifest.yaml")
77+
78+
if [[ -n "$invalid_components" ]]; then
79+
echo
80+
echo "The following components MUST be listed in"
81+
echo "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/otelcontribcol/builder-config.yaml"
82+
echo "to ensure that they can be built:"
83+
printf '%b\n' "$invalid_components" | sort -u
84+
echo
85+
exit 1
86+
else
87+
echo "All manifest.yaml components are valid!"
88+
fi

0 commit comments

Comments
 (0)