|
8 | 8 |
|
9 | 9 | jobs:
|
10 | 10 | 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') |
12 | 14 | runs-on: ubuntu-latest
|
13 | 15 | permissions:
|
14 | 16 | contents: write
|
|
29 | 31 | echo "${{ github.event.pull_request.body }}" >> $GITHUB_OUTPUT
|
30 | 32 | echo "EOF" >> $GITHUB_OUTPUT
|
31 | 33 |
|
| 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 | +
|
32 | 44 | - name: Update Changelog
|
| 45 | + if: steps.changelog-check.outputs.only_changelog != 'true' |
33 | 46 | run: |
|
34 | 47 | # Check if CHANGELOG.md exists
|
35 | 48 | if [ ! -f CHANGELOG.md ]; then
|
@@ -100,51 +113,39 @@ jobs:
|
100 | 113 | echo "Processing PR body for additional details"
|
101 | 114 | while IFS= read -r line; do
|
102 | 115 | # 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 |
105 | 120 | fi
|
106 | 121 | done <<< "${{ steps.pr-info.outputs.body }}"
|
107 | 122 | fi
|
108 | 123 |
|
109 |
| - # Add version link at the end |
| 124 | + # Add version link |
110 | 125 | NEW_ENTRY+="\n[v${NEW_VERSION}]: https://github.com/PeterVinter/Manage_linux_docker_containers/releases/tag/v${NEW_VERSION}\n"
|
111 | 126 |
|
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 |
123 | 130 |
|
124 | 131 | # 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]" |
128 | 134 |
|
129 |
| - # Create branch, commit and push |
| 135 | + # Create branch and commit changes |
130 | 136 | BRANCH_NAME="bot/update-changelog-v${NEW_VERSION}"
|
131 |
| - echo "Creating branch: $BRANCH_NAME" |
132 | 137 | git checkout -b "$BRANCH_NAME"
|
133 |
| - |
134 |
| - echo "Committing changes" |
135 | 138 | git add CHANGELOG.md
|
136 | 139 | git commit -m "docs: update changelog for v${NEW_VERSION}"
|
| 140 | + git push origin "$BRANCH_NAME" |
137 | 141 |
|
138 |
| - echo "Pushing changes" |
139 |
| - git push -f origin "$BRANCH_NAME" |
140 |
| - |
141 |
| - echo "Creating pull request" |
| 142 | + # Create PR |
142 | 143 | gh pr create \
|
143 | 144 | --title "docs: update changelog for v${NEW_VERSION}" \
|
144 | 145 | --body "Automated changelog update for version ${NEW_VERSION}" \
|
145 | 146 | --base main \
|
146 | 147 | --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..." |
148 | 149 | }
|
149 | 150 | env:
|
150 | 151 | GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
|
0 commit comments