1#!/bin/bash
2
3# Copyright The OpenTelemetry Authors
4# SPDX-License-Identifier: Apache-2.0
5
6set -euo pipefail
7
8TARGET="${1:?Must provide target ref}"
9
10FILE="CHANGELOG.md"
11TEMP_DIR=$(mktemp -d)
12echo "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).
17git fetch origin "${TARGET}" --depth=1
18
19# Checkout the previous version on the base branch of the changelog to tmpfolder
20git --work-tree="$TEMP_DIR" checkout FETCH_HEAD $FILE
21
22PREVIOUS_FILE="$TEMP_DIR/$FILE"
23CURRENT_FILE="$FILE"
24PREVIOUS_LOCKED_FILE="$TEMP_DIR/previous_locked_section.md"
25CURRENT_LOCKED_FILE="$TEMP_DIR/current_locked_section.md"
26
27# Extract released sections from the previous version
28awk '/^<!-- Released section -->/ {flag=1} /^<!-- Released section ended -->/ {flag=0} flag' "$PREVIOUS_FILE" > "$PREVIOUS_LOCKED_FILE"
29
30# Extract released sections from the current version
31awk '/^<!-- Released section -->/ {flag=1} /^<!-- Released section ended -->/ {flag=0} flag' "$CURRENT_FILE" > "$CURRENT_LOCKED_FILE"
32
33# Compare the released sections
34if ! 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
39fi
40
41rm -rf "$TEMP_DIR"
42echo "The released sections remain unchanged."