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