|
| 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