Skip to content

Commit f36f819

Browse files
XSAMdmathieu
authored andcommitted
Protect released changelog in CI (open-telemetry#5906)
Mirror of open-telemetry/opentelemetry-go#5560. It also includes the fix from open-telemetry/opentelemetry-go#5616 --------- Co-authored-by: Damien Mathieu <[email protected]>
1 parent 3ff3156 commit f36f819

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This action against that any PR targeting the main branch touches released
2+
# sections in CHANGELOG file. If change to released CHANGELOG is required, like
3+
# doing a release, add the \"Unlock Released Changelog\" label to disable this action.
4+
5+
name: Protect released changelog
6+
7+
on:
8+
pull_request:
9+
types: [opened, synchronize, reopened, labeled, unlabeled]
10+
jobs:
11+
protect-released-changelog:
12+
runs-on: ubuntu-latest
13+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'Unlock Released Changelog')}}
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Protect the released changelog
19+
run: |
20+
./tools/verify_released_changelog.sh ${{ github.base_ref }}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1818

1919
- The deprecated `go.opentelemetry.io/contrib/processors/baggagecopy` package is removed. (#5853)
2020

21+
<!-- Released section -->
22+
<!-- Don't change this section unless doing release -->
23+
2124
## [1.28.0/0.53.0/0.22.0/0.8.0/0.3.0/0.1.0] - 2024-07-02
2225

2326
### Added
@@ -1133,6 +1136,8 @@ First official tagged release of `contrib` repository.
11331136
[0.7.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.7.0
11341137
[0.6.1]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.6.1
11351138

1139+
<!-- Released section ended -->
1140+
11361141
[Go 1.22]: https://go.dev/doc/go1.22
11371142
[Go 1.21]: https://go.dev/doc/go1.21
11381143
[Go 1.20]: https://go.dev/doc/go1.20

RELEASING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ since the last release tag.
108108
git --no-pager log --pretty=oneline "<last tag>..HEAD"
109109
```
110110

111+
Make sure the new released section is under the comment for released section,
112+
like `<!-- Released section -->`, so it is protected from being overwritten in the future.
113+
111114
Be sure to update all the appropriate links at the bottom of the file.
112115

113116
Finally, commit this change to your release branch.

tools/verify_released_changelog.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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."

0 commit comments

Comments
 (0)