Skip to content

Commit 87ed487

Browse files
committed
Add version validation
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
1 parent f4d0ed9 commit 87ed487

File tree

2 files changed

+198
-1
lines changed

2 files changed

+198
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ DISTRIBUTIONS ?= "otelcol,otelcol-contrib,otelcol-k8s,otelcol-otlp,otelcol-ebpf-
2323
BINARIES ?= "builder,opampsupervisor"
2424

2525
ci: check build
26-
check: ensure-goreleaser-up-to-date validate-components
26+
check: ensure-goreleaser-up-to-date validate-components validate-version-consistency
2727

2828
build: go ocb
2929
@./scripts/build.sh -d "${DISTRIBUTIONS}" -b ${OTELCOL_BUILDER}
@@ -49,6 +49,9 @@ ensure-goreleaser-up-to-date: generate-goreleaser
4949
validate-components:
5050
@./scripts/validate-components.sh
5151

52+
validate-version-consistency:
53+
@./scripts/validate-version-consistency.sh
54+
5255
.PHONY: ocb
5356
ocb:
5457
ifeq (, $(shell command -v ocb 2>/dev/null))
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/bin/bash
2+
3+
# Copyright The OpenTelemetry Authors
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# This script validates version consistency across manifest files.
7+
8+
set -euo pipefail
9+
10+
MANIFEST_DIR="distributions"
11+
12+
check_dependencies() {
13+
if ! command -v yq &> /dev/null; then
14+
echo "ERROR: This script requires 'yq'. Please install it and try again."
15+
exit 1
16+
fi
17+
}
18+
19+
find_manifest_files() {
20+
find "$MANIFEST_DIR" -type f -name "manifest.yaml" | sort
21+
}
22+
23+
get_dist_version() {
24+
local manifest_file="$1"
25+
yq -r '.dist.version' "$manifest_file"
26+
}
27+
28+
# Check if a module should have its version validated against dist.version
29+
# Returns 0 (true) if it should be validated, 1 (false) otherwise
30+
should_validate_module_version() {
31+
local module_path="$1"
32+
33+
# Validate contrib components
34+
if [[ "$module_path" == github.com/open-telemetry/opentelemetry-collector-contrib/* ]]; then
35+
return 0
36+
fi
37+
38+
# Validate core collector components, EXCEPT providers (they use different versioning like v1.x)
39+
if [[ "$module_path" == go.opentelemetry.io/collector/* ]] && \
40+
[[ "$module_path" != go.opentelemetry.io/collector/confmap/provider/* ]]; then
41+
return 0
42+
fi
43+
44+
# Don't validate:
45+
# - Core providers (go.opentelemetry.io/collector/confmap/provider/*) - use v1.x versioning
46+
# - eBPF profiler (go.opentelemetry.io/ebpf-profiler) - has its own versioning
47+
return 1
48+
}
49+
50+
# Extract all components from a manifest that should be version-validated
51+
get_validatable_components() {
52+
local manifest_file="$1"
53+
54+
yq -r '
55+
(
56+
.extensions[]?.gomod,
57+
.receivers[]?.gomod,
58+
.connectors[]?.gomod,
59+
.processors[]?.gomod,
60+
.exporters[]?.gomod,
61+
.providers[]?.gomod
62+
)
63+
' "$manifest_file" 2>/dev/null
64+
}
65+
66+
# Check that all distributions have the same dist.version
67+
validate_dist_versions_match() {
68+
echo "Checking all distributions have the same version..."
69+
70+
local versions_tmp
71+
versions_tmp="$(mktemp)"
72+
73+
while IFS= read -r manifest_file; do
74+
local version
75+
version=$(get_dist_version "$manifest_file")
76+
echo "$version $manifest_file" >> "$versions_tmp"
77+
done < <(find_manifest_files)
78+
79+
local unique_versions
80+
unique_versions=$(awk '{print $1}' "$versions_tmp" | sort -u)
81+
local version_count
82+
version_count=$(echo "$unique_versions" | wc -l | tr -d ' ')
83+
84+
if [[ "$version_count" -gt 1 ]]; then
85+
echo
86+
echo "ERROR: Distributions have different dist.version values:"
87+
echo
88+
while IFS= read -r line; do
89+
local version file
90+
version=$(echo "$line" | awk '{print $1}')
91+
file=$(echo "$line" | awk '{print $2}')
92+
echo " $file: $version"
93+
done < "$versions_tmp"
94+
echo
95+
echo "All distributions must use the same version."
96+
rm -f "$versions_tmp"
97+
return 1
98+
fi
99+
100+
echo " All distributions use version: $unique_versions"
101+
rm -f "$versions_tmp"
102+
return 0
103+
}
104+
105+
# Check that components in a manifest match the distribution version
106+
validate_components_match_dist_version() {
107+
local manifest_file="$1"
108+
local dist_version="$2"
109+
local expected_version="v${dist_version}"
110+
local errors=""
111+
112+
while IFS= read -r line; do
113+
[[ -z "$line" ]] && continue
114+
115+
local module_path version
116+
module_path=$(echo "$line" | awk '{print $1}')
117+
version=$(echo "$line" | awk '{print $2}')
118+
119+
[[ -z "$module_path" || -z "$version" ]] && continue
120+
121+
if should_validate_module_version "$module_path"; then
122+
if [[ "$version" != "$expected_version" ]]; then
123+
errors+=" $module_path: found $version, expected $expected_version\n"
124+
fi
125+
fi
126+
done < <(get_validatable_components "$manifest_file")
127+
128+
if [[ -n "$errors" ]]; then
129+
echo " ERROR in $manifest_file:"
130+
printf '%b' "$errors"
131+
return 1
132+
fi
133+
134+
return 0
135+
}
136+
137+
# Check all manifests for component version mismatches
138+
validate_all_component_versions() {
139+
echo
140+
echo "Checking components match their distribution version..."
141+
142+
local has_errors=false
143+
144+
while IFS= read -r manifest_file; do
145+
local dist_version
146+
dist_version=$(get_dist_version "$manifest_file")
147+
148+
if ! validate_components_match_dist_version "$manifest_file" "$dist_version"; then
149+
has_errors=true
150+
else
151+
echo " $manifest_file: OK"
152+
fi
153+
done < <(find_manifest_files)
154+
155+
if [[ "$has_errors" == "true" ]]; then
156+
echo
157+
echo "Components from opentelemetry-collector-contrib and core collector"
158+
echo "must use the same version as the distribution (v{dist.version})."
159+
echo
160+
echo "Excluded from validation:"
161+
echo " - Core providers (go.opentelemetry.io/collector/confmap/provider/*) - use v1.x versioning"
162+
echo " - eBPF profiler (go.opentelemetry.io/ebpf-profiler) - has its own versioning"
163+
return 1
164+
fi
165+
166+
return 0
167+
}
168+
169+
main() {
170+
echo "Validating component version consistency..."
171+
echo
172+
173+
check_dependencies
174+
175+
local has_errors=false
176+
177+
if ! validate_dist_versions_match; then
178+
has_errors=true
179+
fi
180+
181+
if ! validate_all_component_versions; then
182+
has_errors=true
183+
fi
184+
185+
echo
186+
if [[ "$has_errors" == "true" ]]; then
187+
echo "Validation FAILED. Please fix the version inconsistencies above."
188+
exit 1
189+
else
190+
echo "All version checks passed!"
191+
fi
192+
}
193+
194+
main "$@"

0 commit comments

Comments
 (0)