Skip to content

Commit 1161c48

Browse files
authored
Merge pull request #24 from PeterVinter/fix/prevent-changelog-cascade
fix: prevent changelog cascade updates
2 parents ff3dafd + 96db91b commit 1161c48

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

.github/workflows/update-changelog.yml

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ on:
88

99
jobs:
1010
update-changelog:
11-
if: github.event.pull_request.merged == true
11+
if: |
12+
github.event.pull_request.merged == true &&
13+
!startsWith(github.event.pull_request.title, 'docs: update changelog for v')
1214
runs-on: ubuntu-latest
1315
permissions:
1416
contents: write
@@ -29,7 +31,18 @@ jobs:
2931
echo "${{ github.event.pull_request.body }}" >> $GITHUB_OUTPUT
3032
echo "EOF" >> $GITHUB_OUTPUT
3133
34+
- name: Check if only changelog was modified
35+
id: changelog-check
36+
run: |
37+
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
38+
if [ "$CHANGED_FILES" = "CHANGELOG.md" ]; then
39+
echo "only_changelog=true" >> $GITHUB_OUTPUT
40+
else
41+
echo "only_changelog=false" >> $GITHUB_OUTPUT
42+
fi
43+
3244
- name: Update Changelog
45+
if: steps.changelog-check.outputs.only_changelog != 'true'
3346
run: |
3447
# Check if CHANGELOG.md exists
3548
if [ ! -f CHANGELOG.md ]; then
@@ -100,51 +113,39 @@ jobs:
100113
echo "Processing PR body for additional details"
101114
while IFS= read -r line; do
102115
# Skip PR template checkboxes and empty lines
103-
if [[ "$line" =~ ^-[[:space:]][^[\]]*$ && ! "$line" =~ "[ ]" ]]; then
104-
NEW_ENTRY+="$line\n"
116+
if [[ ! "$line" =~ ^\s*-\s*\[[ xX]\] ]]; then
117+
if [ ! -z "$line" ]; then
118+
NEW_ENTRY+=" - $line\n"
119+
fi
105120
fi
106121
done <<< "${{ steps.pr-info.outputs.body }}"
107122
fi
108123
109-
# Add version link at the end
124+
# Add version link
110125
NEW_ENTRY+="\n[v${NEW_VERSION}]: https://github.com/PeterVinter/Manage_linux_docker_containers/releases/tag/v${NEW_VERSION}\n"
111126
112-
echo "Creating temporary file with new changelog entry"
113-
echo -e "$NEW_ENTRY" > temp_entry
114-
115-
if [ -s CHANGELOG.md ]; then
116-
echo "Inserting new entry into existing CHANGELOG.md"
117-
sed -i '7r temp_entry' CHANGELOG.md
118-
else
119-
echo "Creating new CHANGELOG.md with initial entry"
120-
cat temp_entry >> CHANGELOG.md
121-
fi
122-
rm temp_entry
127+
# Create temporary file with new content
128+
echo -e "# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n${NEW_ENTRY}\n$(tail -n +7 CHANGELOG.md)" > CHANGELOG.md.new
129+
mv CHANGELOG.md.new CHANGELOG.md
123130
124131
# Configure Git
125-
echo "Configuring Git"
126-
git config --local user.email "github-actions[bot]@users.noreply.github.com"
127-
git config --local user.name "github-actions[bot]"
132+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
133+
git config --global user.name "github-actions[bot]"
128134
129-
# Create branch, commit and push
135+
# Create branch and commit changes
130136
BRANCH_NAME="bot/update-changelog-v${NEW_VERSION}"
131-
echo "Creating branch: $BRANCH_NAME"
132137
git checkout -b "$BRANCH_NAME"
133-
134-
echo "Committing changes"
135138
git add CHANGELOG.md
136139
git commit -m "docs: update changelog for v${NEW_VERSION}"
140+
git push origin "$BRANCH_NAME"
137141
138-
echo "Pushing changes"
139-
git push -f origin "$BRANCH_NAME"
140-
141-
echo "Creating pull request"
142+
# Create PR
142143
gh pr create \
143144
--title "docs: update changelog for v${NEW_VERSION}" \
144145
--body "Automated changelog update for version ${NEW_VERSION}" \
145146
--base main \
146147
--head "$BRANCH_NAME" || {
147-
echo "Warning: Failed to create PR. This might be because a PR already exists."
148+
echo "Failed to create PR, but continuing..."
148149
}
149150
env:
150151
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}

0 commit comments

Comments
 (0)