@@ -139,172 +139,3 @@ jobs:
139139 ./test-charts.sh "$CHART_NAME" --no-cleanup
140140 done
141141
142- update-changelog :
143- runs-on : ubuntu-latest
144- timeout-minutes : 15
145- needs : [lint-test]
146- name : Automatically update CHANGELOG
147- permissions :
148- contents : write
149- pull-requests : write
150- if : always() && needs.lint-test.outputs.changed == 'true'
151- steps :
152- - name : Checkout PR branch
153- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
154- with :
155- repository : ${{ github.event.pull_request.head.repo.full_name }}
156- ref : ${{ github.event.pull_request.head.ref }}
157- token : ${{ secrets.GITHUB_TOKEN }}
158- fetch-depth : 0
159-
160- - name : Configure Git
161- run : |
162- git config user.name 'github-actions[bot]'
163- git config user.email 'github-actions[bot]@users.noreply.github.com'
164-
165- - name : Add upstream remote and fetch tags
166- run : |
167- # Always fetch tags from the canonical upstream repository
168- UPSTREAM_REPO="CloudPirates-io/helm-charts"
169- echo "Fetching tags from upstream: ${UPSTREAM_REPO}"
170- git remote add upstream https://github.com/${UPSTREAM_REPO}.git || true
171- git fetch upstream --tags --force
172-
173- # Also fetch tags from origin (the fork/current repo)
174- git fetch origin --tags --force || true
175-
176- # List all tags for debugging
177- echo "Available tags:"
178- git tag -l | head -20
179-
180- - name : Install yq
181- run : |
182- sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
183- sudo chmod +x /usr/local/bin/yq
184-
185- - name : Generate changelog and commit
186- id : check-changes
187- shell : bash
188- env :
189- PULL_REQUEST_NUMBER : " ${{ github.event.pull_request.number }}"
190- PULL_REQUEST_URL : " ${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.number }}"
191- GITHUB_TOKEN : " ${{ github.token }}"
192- GITHUB_REPOSITORY : " ${{ github.repository }}"
193- GITHUB_REPOSITORY_URL : " ${{ github.server_url }}/${{ github.repository }}"
194- CHANGED_CHARTS : ${{ needs.lint-test.outputs.changedCharts }}
195- run : |
196- set -e
197- PR_TITLE="$(gh api "/repos/${GITHUB_REPOSITORY}/pulls/${PULL_REQUEST_NUMBER}" | jq -r '.title')"
198-
199- # Extract chart names from changed chart directories
200- CHART_NAMES=()
201- for chart_directory in ${CHANGED_CHARTS}; do
202- CHART_NAME=${chart_directory#charts/}
203- CHART_NAMES+=("--chart" "$CHART_NAME")
204- done
205-
206- # Run the changelog generation script
207- ./generate-changelog.sh \
208- "${CHART_NAMES[@]}" \
209- --pr-title "${PR_TITLE}" \
210- --pr-number "${PULL_REQUEST_NUMBER}" \
211- --pr-url "${PULL_REQUEST_URL}"
212-
213- # Check if there are changes
214- if git status --porcelain | grep -q 'CHANGELOG.md'; then
215- echo "has_changes=true" >> $GITHUB_OUTPUT
216- else
217- echo "No CHANGELOG changes"
218- echo "has_changes=false" >> $GITHUB_OUTPUT
219- fi
220-
221- - name : Commit and push via GitHub API
222- id : push-changes
223- if : steps.check-changes.outputs.has_changes == 'true'
224- uses : actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
225- with :
226- github-token : ${{ secrets.GITHUB_TOKEN }}
227- script : |
228- const { execSync } = require('child_process');
229- const fs = require('fs');
230-
231- try {
232- const headRef = '${{ github.event.pull_request.head.ref }}';
233- const headRepo = '${{ github.event.pull_request.head.repo.full_name }}';
234- const [owner, repo] = headRepo.split('/');
235-
236- // Get current branch SHA
237- const { data: refData } = await github.rest.git.getRef({
238- owner,
239- repo,
240- ref: `heads/${headRef}`
241- });
242- const currentSha = refData.object.sha;
243- console.log('Current branch SHA:', currentSha);
244-
245- // Get the tree for current commit
246- const { data: commitData } = await github.rest.git.getCommit({
247- owner,
248- repo,
249- commit_sha: currentSha
250- });
251- const baseTreeSha = commitData.tree.sha;
252-
253- // Get all changed CHANGELOG files
254- const changedFiles = execSync('git status --porcelain').toString()
255- .split('\n')
256- .filter(line => line.includes('CHANGELOG.md'))
257- .map(line => line.trim().split(/\s+/)[1])
258- .filter(Boolean);
259-
260- console.log('Changed files:', changedFiles);
261-
262- // Create blobs for each changed file
263- const blobs = await Promise.all(
264- changedFiles.map(async (file) => {
265- const content = fs.readFileSync(file, 'utf8');
266- const { data: blob } = await github.rest.git.createBlob({
267- owner,
268- repo,
269- content,
270- encoding: 'utf-8'
271- });
272- return { path: file, sha: blob.sha, mode: '100644', type: 'blob' };
273- })
274- );
275-
276- // Create new tree
277- const { data: newTree } = await github.rest.git.createTree({
278- owner,
279- repo,
280- base_tree: baseTreeSha,
281- tree: blobs
282- });
283-
284- // Create commit (this will be automatically signed by GitHub)
285- const { data: newCommit } = await github.rest.git.createCommit({
286- owner,
287- repo,
288- message: 'chore: update CHANGELOG.md for changed charts\n\nSigned-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>',
289- tree: newTree.sha,
290- parents: [currentSha]
291- });
292-
293- console.log('Created commit:', newCommit.sha);
294-
295- // Update reference
296- await github.rest.git.updateRef({
297- owner,
298- repo,
299- ref: `heads/${headRef}`,
300- sha: newCommit.sha,
301- force: false
302- });
303-
304- console.log('✅ Successfully committed and pushed changelog updates');
305- core.notice('✅ Changelog updated and pushed successfully');
306-
307- } catch (error) {
308- console.error('Failed to commit via GitHub API:', error);
309- core.setFailed(`Unable to push changelog updates: ${error.message}`);
310- }
0 commit comments