@@ -137,56 +137,45 @@ jobs:
137
137
138
138
- name : Generate and Commit Changelog
139
139
run : |
140
- echo "Installing git-chglog..."
140
+ # Create a temporary directory for extraction
141
141
mkdir chglog_tmp
142
+
143
+ # Download git-chglog archive
142
144
wget https://github.com/git-chglog/git-chglog/releases/download/v0.15.4/git-chglog_0.15.4_linux_amd64.tar.gz
145
+
146
+ # Extract into the temporary directory
143
147
tar -xvzf git-chglog_0.15.4_linux_amd64.tar.gz -C chglog_tmp
144
-
145
- echo "Generating changelog..."
148
+
149
+ # Generate changelog using the extracted executable
146
150
./chglog_tmp/git-chglog -o ./CHANGELOG.md
147
-
148
- echo "Cleaning up git-chglog files..."
151
+
152
+ # Clean up downloaded archive and temporary directory
149
153
rm git-chglog_0.15.4_linux_amd64.tar.gz
150
154
rm -rf chglog_tmp
151
-
152
- echo "Configuring git user..."
155
+
156
+ # Configure git user
153
157
git config user.name "github-actions[bot]"
154
158
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
155
-
156
- echo "Fetching main branch..."
159
+
157
160
# Fetch the latest main branch from origin
161
+ # Use refs/heads/main to be explicit about fetching the branch, not a tag named main
158
162
git fetch origin refs/heads/main
159
-
160
- echo "Creating temporary branch based on origin/main..."
161
- # Create a new branch based on the fetched origin/main
162
- echo "Stashing generated CHANGELOG.md..."
163
- # Stash the generated changelog (include untracked files like CHANGELOG.md if new)
164
- git stash push -u -- CHANGELOG.md
165
163
164
+ # Create a new branch based on the fetched origin/main
166
165
git checkout -b changelog-update origin/main
167
166
168
- echo "Adding and committing CHANGELOG.md..."
169
- echo "Applying stashed CHANGELOG.md..."
170
- # Apply the stashed changes (the generated CHANGELOG.md)
171
- # Use || true in case stash is empty (e.g., changelog didn't change)
172
- git stash pop || true
173
-
167
+ # Add, commit the changelog to the new branch
174
168
git add ./CHANGELOG.md
175
- # Check if there are changes to commit to avoid empty commit error if file exists and is unchanged
176
- if ! git diff --staged --quiet; then
177
- git commit -m "chore(docs): update CHANGELOG for release ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }} [skip ci]"
178
- else
179
- echo "No changes to CHANGELOG.md to commit."
180
- fi
181
-
182
-
183
- echo "Cleaning up temporary local branch..."
184
- # Switch away from the branch before deleting it
185
- git checkout --detach
186
- git branch -D changelog-update
187
- echo "Pushing changelog commit to remote main branch..."
169
+ # Use --allow-empty in case the changelog hasn't changed (e.g., rerunning on same tag)
170
+ git commit --allow-empty -m "chore(docs): update CHANGELOG for release ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }} [skip ci]"
171
+
188
172
# Push the new local branch specifically to the remote *branch* main
189
173
git push origin changelog-update:refs/heads/main
174
+
175
+ # Clean up the temporary local branch (optional but good practice)
176
+ # We might need to checkout --detach first if this fails
177
+ git branch -D changelog-update || echo "Could not delete local branch changelog-update"
178
+
190
179
env :
191
180
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
192
181
0 commit comments