verify_released_changelog.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # Copyright The OpenTelemetry Authors
  3. # SPDX-License-Identifier: Apache-2.0
  4. set -euo pipefail
  5. TARGET="${1:?Must provide target ref}"
  6. FILE="CHANGELOG.md"
  7. TEMP_DIR=$(mktemp -d)
  8. echo "Temp folder: $TEMP_DIR"
  9. # Only the latest commit of the feature branch is available
  10. # automatically. To diff with the base branch, we need to
  11. # fetch that too (and we only need its latest commit).
  12. git fetch origin "${TARGET}" --depth=1
  13. # Checkout the previous version on the base branch of the changelog to tmpfolder
  14. git --work-tree="$TEMP_DIR" checkout FETCH_HEAD $FILE
  15. PREVIOUS_FILE="$TEMP_DIR/$FILE"
  16. CURRENT_FILE="$FILE"
  17. PREVIOUS_LOCKED_FILE="$TEMP_DIR/previous_locked_section.md"
  18. CURRENT_LOCKED_FILE="$TEMP_DIR/current_locked_section.md"
  19. # Extract released sections from the previous version
  20. awk '/^<!-- Released section -->/ {flag=1} /^<!-- Released section ended -->/ {flag=0} flag' "$PREVIOUS_FILE" > "$PREVIOUS_LOCKED_FILE"
  21. # Extract released sections from the current version
  22. awk '/^<!-- Released section -->/ {flag=1} /^<!-- Released section ended -->/ {flag=0} flag' "$CURRENT_FILE" > "$CURRENT_LOCKED_FILE"
  23. # Compare the released sections
  24. if ! diff -q "$PREVIOUS_LOCKED_FILE" "$CURRENT_LOCKED_FILE"; then
  25. echo "Error: The released sections of the changelog file have been modified."
  26. diff "$PREVIOUS_LOCKED_FILE" "$CURRENT_LOCKED_FILE"
  27. rm -rf "$TEMP_DIR"
  28. false
  29. fi
  30. rm -rf "$TEMP_DIR"
  31. echo "The released sections remain unchanged."