Skip to content

Commit 395898c

Browse files
authored
Add clean start option for CHANGELOG.md generation
Added a clean start option to delete existing CHANGELOG.md files before generating new ones. Updated the workflow to handle clean start logic during manual triggers. Signed-off-by: Finn Rades <64548817+zOnlyKroks@users.noreply.github.com>
1 parent 84cf67b commit 395898c

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

.github/workflows/post-merge.yaml

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ on:
1313
required: false
1414
type: boolean
1515
default: false
16+
clean_start:
17+
description: 'Delete existing CHANGELOG.md files and start fresh'
18+
required: false
19+
type: boolean
20+
default: false
1621
custom_message:
1722
description: 'Custom changelog message (optional)'
1823
required: false
@@ -107,6 +112,41 @@ jobs:
107112
fi
108113
fi
109114
115+
- name: Clean start - Delete existing CHANGELOG.md files
116+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.clean_start == 'true' && steps.charts-to-update.outputs.changed == 'true'
117+
run: |
118+
echo "Clean start enabled - deleting existing CHANGELOG.md files"
119+
CHANGED_CHARTS="${{ steps.charts-to-update.outputs.changedCharts }}"
120+
121+
for chart_directory in $CHANGED_CHARTS; do
122+
CHART_NAME=${chart_directory#charts/}
123+
CHANGELOG_FILE="charts/${CHART_NAME}/CHANGELOG.md"
124+
125+
if [ -f "$CHANGELOG_FILE" ]; then
126+
echo "Deleting $CHANGELOG_FILE"
127+
rm "$CHANGELOG_FILE"
128+
129+
# Check if directory is empty except for ignored files
130+
if [ -z "$(ls -A "charts/${CHART_NAME}" | grep -vE '^(Chart\.yaml|values\.yaml|\.helmignore|templates|crds|\.gitkeep)$')" ]; then
131+
echo "Directory charts/${CHART_NAME} would be empty after deletion, but keeping it"
132+
fi
133+
else
134+
echo "No CHANGELOG.md found at $CHANGELOG_FILE"
135+
fi
136+
done
137+
138+
# Commit the deletions if any files were removed
139+
if git status --porcelain | grep -q 'CHANGELOG.md'; then
140+
echo "CHANGELOG.md files deleted successfully"
141+
git add charts/*/CHANGELOG.md
142+
git commit -m "chore: remove existing CHANGELOG.md files for clean start" \
143+
-m "Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
144+
echo "clean_start_completed=true" >> $GITHUB_ENV
145+
else
146+
echo "No CHANGELOG.md files to delete"
147+
echo "clean_start_completed=false" >> $GITHUB_ENV
148+
fi
149+
110150
- name: Get PR information for push events
111151
id: pr-info-push
112152
if: github.event_name == 'push' && steps.charts-to-update.outputs.changed == 'true'
@@ -145,7 +185,11 @@ jobs:
145185
if [ -n "${{ github.event.inputs.custom_message }}" ]; then
146186
PR_TITLE="${{ github.event.inputs.custom_message }}"
147187
else
148-
PR_TITLE="Manual changelog update triggered via workflow_dispatch"
188+
if [ "${{ github.event.inputs.clean_start }}" = "true" ]; then
189+
PR_TITLE="Manual changelog update with clean start"
190+
else
191+
PR_TITLE="Manual changelog update triggered via workflow_dispatch"
192+
fi
149193
fi
150194
151195
echo "pr_number=manual" >> $GITHUB_OUTPUT
@@ -163,12 +207,14 @@ jobs:
163207
PR_TITLE: ${{ github.event_name == 'push' && steps.pr-info-push.outputs.pr_title || steps.manual-info.outputs.pr_title }}
164208
PR_URL: ${{ github.event_name == 'push' && steps.pr-info-push.outputs.pr_url || steps.manual-info.outputs.pr_url }}
165209
UPDATE_MODE: ${{ steps.charts-to-update.outputs.update_mode }}
210+
CLEAN_START: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.clean_start || 'false' }}
166211
run: |
167212
set -e
168213
169214
CHANGED_CHARTS="${{ steps.charts-to-update.outputs.changedCharts }}"
170215
171216
echo "Update mode: $UPDATE_MODE"
217+
echo "Clean start: $CLEAN_START"
172218
echo "Processing charts: $CHANGED_CHARTS"
173219
174220
# Process each chart individually
@@ -195,7 +241,7 @@ jobs:
195241
fi
196242
197243
- name: Commit and push changelog updates
198-
if: steps.generate-changelog.outputs.has_changes == 'true'
244+
if: steps.generate-changelog.outputs.has_changes == 'true' && env.clean_start_completed != 'true'
199245
run: |
200246
git add charts/*/CHANGELOG.md
201247
@@ -204,6 +250,9 @@ jobs:
204250
if [ "${{ github.event.inputs.update_all_charts }}" = "true" ]; then
205251
COMMIT_MSG="chore: update CHANGELOG.md for all charts via manual trigger"
206252
fi
253+
if [ "${{ github.event.inputs.clean_start }}" = "true" ]; then
254+
COMMIT_MSG="chore: regenerate CHANGELOG.md with clean start"
255+
fi
207256
else
208257
COMMIT_MSG="chore: update CHANGELOG.md for merged changes"
209258
fi

0 commit comments

Comments
 (0)