Skip to content

Commit 1b1e05a

Browse files
authored
Enhance post-merge workflow with manual triggers
Added manual trigger inputs for updating charts and custom changelog messages. Enhanced logic to determine charts to update based on manual triggers and push events. Signed-off-by: Finn Rades <64548817+zOnlyKroks@users.noreply.github.com>
1 parent 40178aa commit 1b1e05a

File tree

1 file changed

+101
-30
lines changed

1 file changed

+101
-30
lines changed

.github/workflows/post-merge.yaml

Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ on:
66
- main
77
paths:
88
- 'charts/**'
9+
workflow_dispatch: # Manual trigger
10+
inputs:
11+
update_all_charts:
12+
description: 'Update all charts (not just changed ones)'
13+
required: false
14+
type: boolean
15+
default: false
16+
custom_message:
17+
description: 'Custom changelog message (optional)'
18+
required: false
19+
type: string
920

1021
concurrency:
11-
group: ${{ github.workflow }}
22+
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
1223
cancel-in-progress: false
1324

1425
jobs:
@@ -40,36 +51,65 @@ jobs:
4051
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
4152
sudo chmod +x /usr/local/bin/yq
4253
43-
- name: Get changed charts from last commit
44-
id: list-changed
54+
- name: Determine charts to update
55+
id: charts-to-update
4556
run: |
46-
# Get the commit SHA before the merge
47-
BEFORE_SHA="${{ github.event.before }}"
48-
49-
# Find changed charts directories using git diff
50-
changed_files=$(git diff --name-only "${BEFORE_SHA}" HEAD -- 'charts/**')
51-
52-
if [[ -n "$changed_files" ]]; then
53-
# Extract unique chart directories
54-
changed_charts=$(echo "$changed_files" | grep '^charts/' | cut -d/ -f1-2 | sort -u | tr '\n' ' ')
55-
56-
if [[ -n "$changed_charts" ]]; then
57-
echo "Changed charts:"
58-
echo "$changed_charts"
59-
echo "changed=true" >> $GITHUB_OUTPUT
60-
echo "changedCharts=${changed_charts}" >> $GITHUB_OUTPUT
57+
# For manual trigger with update_all_charts enabled
58+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.update_all_charts }}" = "true" ]; then
59+
echo "Manual trigger: updating all charts"
60+
all_charts=$(find charts -mindepth 1 -maxdepth 1 -type d | sed 's|^charts/||' | tr '\n' ' ')
61+
echo "All charts: $all_charts"
62+
echo "changed=true" >> $GITHUB_OUTPUT
63+
echo "changedCharts=$all_charts" >> $GITHUB_OUTPUT
64+
echo "update_mode=all" >> $GITHUB_OUTPUT
65+
# For manual trigger without update_all_charts (default behavior - changed charts only)
66+
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
67+
echo "Manual trigger: finding changed charts from last commit"
68+
# Use the same logic as push event to find changed charts
69+
BEFORE_SHA=$(git rev-parse HEAD~1)
70+
changed_files=$(git diff --name-only "${BEFORE_SHA}" HEAD -- 'charts/**')
71+
72+
if [[ -n "$changed_files" ]]; then
73+
changed_charts=$(echo "$changed_files" | grep '^charts/' | cut -d/ -f1-2 | sort -u | tr '\n' ' ')
74+
if [[ -n "$changed_charts" ]]; then
75+
echo "Changed charts: $changed_charts"
76+
echo "changed=true" >> $GITHUB_OUTPUT
77+
echo "changedCharts=${changed_charts}" >> $GITHUB_OUTPUT
78+
echo "update_mode=changed" >> $GITHUB_OUTPUT
79+
else
80+
echo "No chart changes detected in last commit"
81+
echo "changed=false" >> $GITHUB_OUTPUT
82+
fi
6183
else
62-
echo "No chart changes detected"
84+
echo "No chart changes detected in last commit"
6385
echo "changed=false" >> $GITHUB_OUTPUT
6486
fi
87+
# For push event (original behavior)
6588
else
66-
echo "No chart changes detected"
67-
echo "changed=false" >> $GITHUB_OUTPUT
89+
echo "Push event: finding changed charts from merge commit"
90+
BEFORE_SHA="${{ github.event.before }}"
91+
changed_files=$(git diff --name-only "${BEFORE_SHA}" HEAD -- 'charts/**')
92+
93+
if [[ -n "$changed_files" ]]; then
94+
changed_charts=$(echo "$changed_files" | grep '^charts/' | cut -d/ -f1-2 | sort -u | tr '\n' ' ')
95+
if [[ -n "$changed_charts" ]]; then
96+
echo "Changed charts: $changed_charts"
97+
echo "changed=true" >> $GITHUB_OUTPUT
98+
echo "changedCharts=${changed_charts}" >> $GITHUB_OUTPUT
99+
echo "update_mode=changed" >> $GITHUB_OUTPUT
100+
else
101+
echo "No chart changes detected"
102+
echo "changed=false" >> $GITHUB_OUTPUT
103+
fi
104+
else
105+
echo "No chart changes detected"
106+
echo "changed=false" >> $GITHUB_OUTPUT
107+
fi
68108
fi
69109
70-
- name: Get PR information
71-
id: pr-info
72-
if: steps.list-changed.outputs.changed == 'true'
110+
- name: Get PR information for push events
111+
id: pr-info-push
112+
if: github.event_name == 'push' && steps.charts-to-update.outputs.changed == 'true'
73113
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
74114
with:
75115
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -98,20 +138,40 @@ jobs:
98138
core.setOutput('pr_url', '');
99139
}
100140
141+
- name: Set manual trigger info
142+
id: manual-info
143+
if: github.event_name == 'workflow_dispatch' && steps.charts-to-update.outputs.changed == 'true'
144+
run: |
145+
if [ -n "${{ github.event.inputs.custom_message }}" ]; then
146+
PR_TITLE="${{ github.event.inputs.custom_message }}"
147+
else
148+
PR_TITLE="Manual changelog update triggered via workflow_dispatch"
149+
fi
150+
151+
echo "pr_number=manual" >> $GITHUB_OUTPUT
152+
echo "pr_title=${PR_TITLE}" >> $GITHUB_OUTPUT
153+
echo "pr_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT
154+
101155
- name: Generate changelog
102156
id: generate-changelog
103-
if: steps.list-changed.outputs.changed == 'true'
157+
if: steps.charts-to-update.outputs.changed == 'true'
104158
env:
105159
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
106160
GITHUB_REPOSITORY: "${{ github.repository }}"
107161
GITHUB_REPOSITORY_URL: "${{ github.server_url }}/${{ github.repository }}"
108-
PR_NUMBER: ${{ steps.pr-info.outputs.pr_number }}
109-
PR_TITLE: ${{ steps.pr-info.outputs.pr_title }}
110-
PR_URL: ${{ steps.pr-info.outputs.pr_url }}
162+
PR_NUMBER: ${{ github.event_name == 'push' && steps.pr-info-push.outputs.pr_number || steps.manual-info.outputs.pr_number }}
163+
PR_TITLE: ${{ github.event_name == 'push' && steps.pr-info-push.outputs.pr_title || steps.manual-info.outputs.pr_title }}
164+
PR_URL: ${{ github.event_name == 'push' && steps.pr-info-push.outputs.pr_url || steps.manual-info.outputs.pr_url }}
165+
UPDATE_MODE: ${{ steps.charts-to-update.outputs.update_mode }}
111166
run: |
112167
set -e
113168
114-
# Process each changed chart individually
169+
CHANGED_CHARTS="${{ steps.charts-to-update.outputs.changedCharts }}"
170+
171+
echo "Update mode: $UPDATE_MODE"
172+
echo "Processing charts: $CHANGED_CHARTS"
173+
174+
# Process each chart individually
115175
for chart_directory in $CHANGED_CHARTS; do
116176
CHART_NAME=${chart_directory#charts/}
117177
echo "Processing chart: $CHART_NAME"
@@ -128,6 +188,7 @@ jobs:
128188
if git status --porcelain | grep -q 'CHANGELOG.md'; then
129189
echo "has_changes=true" >> $GITHUB_OUTPUT
130190
echo "Changelog changes detected"
191+
git status --porcelain
131192
else
132193
echo "No CHANGELOG changes"
133194
echo "has_changes=false" >> $GITHUB_OUTPUT
@@ -137,7 +198,17 @@ jobs:
137198
if: steps.generate-changelog.outputs.has_changes == 'true'
138199
run: |
139200
git add charts/*/CHANGELOG.md
140-
git commit -m "chore: update CHANGELOG.md for merged changes" \
201+
202+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
203+
COMMIT_MSG="chore: update CHANGELOG.md via manual trigger"
204+
if [ "${{ github.event.inputs.update_all_charts }}" = "true" ]; then
205+
COMMIT_MSG="chore: update CHANGELOG.md for all charts via manual trigger"
206+
fi
207+
else
208+
COMMIT_MSG="chore: update CHANGELOG.md for merged changes"
209+
fi
210+
211+
git commit -m "$COMMIT_MSG" \
141212
-m "Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
142213
143214
# Pull latest changes and rebase our commit on top

0 commit comments

Comments
 (0)