Skip to content

Commit cab0a24

Browse files
committed
refactor(release-changelog): extract release changelog into composite action
Move the release changelog generation and git staging logic from the promote workflow into a new release-changelog composite action. The action runs git-cliff and stages the output file, removing the need for the resolve-changelog-git-add-files step in promote.
1 parent 0c67a06 commit cab0a24

2 files changed

Lines changed: 62 additions & 25 deletions

File tree

.github/workflows/promote.yml

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -278,32 +278,15 @@ jobs:
278278
- name: release changelog
279279
id: release_changelog
280280
if: inputs.changelog-enabled
281-
uses: orhun/git-cliff-action@v4
282-
env:
283-
OUTPUT: ${{ inputs.changelog-prepend && '/tmp/cliff-changelog.md' || inputs.changelog-output || 'CHANGELOG.md' }}
281+
uses: getdevopspro/github-actions/release-changelog@v7.2.2
284282
with:
283+
version: ${{ steps.release_version.outputs.version }}
284+
previous-version: ${{ steps.release_version.outputs.previous-version }}
285+
token: ${{ inputs.changelog-token }}
286+
output: ${{ inputs.changelog-output }}
285287
config: ${{ inputs.changelog-config }}
286-
args: >-
287-
${{ steps.release_version.outputs.previous-version }}..${{ inputs.changelog-prepend && 'HEAD' || steps.release_version.outputs.version }}
288-
--tag ${{ steps.release_version.outputs.version }}
289-
${{ inputs.changelog-prepend && format('--prepend {0}', inputs.changelog-output || 'CHANGELOG.md') || '' }}
290-
${{ inputs.changelog-args }}
291-
github_token: ${{ inputs.changelog-token || github.token }}
292-
293-
- name: resolve changelog git-add-files
294-
id: resolve_changelog_git_add_files
295-
if: inputs.changelog-enabled
296-
shell: bash
297-
run: |
298-
set -euo pipefail
299-
CHANGELOG_FILE="${{ inputs.changelog-output }}"
300-
CHANGELOG_FILE="${CHANGELOG_FILE:-CHANGELOG.md}"
301-
FILES="${{ inputs.git-add-files }}"
302-
case " ${FILES} " in
303-
*" ${CHANGELOG_FILE} "*) ;;
304-
*) FILES="${FILES:+${FILES} }${CHANGELOG_FILE}" ;;
305-
esac
306-
echo "files=${FILES}" >> "$GITHUB_OUTPUT"
288+
args: ${{ inputs.changelog-args }}
289+
prepend: ${{ inputs.changelog-prepend }}
307290

308291
- name: push git version
309292
uses: getdevopspro/github-actions/release-git-push@v7.2.2
@@ -313,7 +296,7 @@ jobs:
313296
version: ${{ steps.release_version.outputs.version }}
314297
git-user-name: ${{ inputs.git-user-name }}
315298
git-user-email: ${{ inputs.git-user-email }}
316-
git-add-files: ${{ steps.resolve_changelog_git_add_files.outputs.files || inputs.git-add-files }}
299+
git-add-files: ${{ inputs.git-add-files }}
317300

318301
- name: publish github release
319302
if: inputs.update-release-enabled && inputs.push-git

release-changelog/action.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Release Changelog
2+
description: 'Generate a release changelog using git-cliff and stage the output file'
3+
inputs:
4+
version:
5+
description: 'The release version to tag the changelog with'
6+
required: true
7+
previous-version:
8+
description: 'The previous version to generate the changelog from'
9+
required: true
10+
token:
11+
description: 'GitHub token for changelog generation (defaults to current GitHub token)'
12+
required: false
13+
default: ''
14+
output:
15+
description: 'Output file path for the generated changelog'
16+
required: false
17+
default: 'CHANGELOG.md'
18+
config:
19+
description: 'Path to the cliff.toml config file passed to git-cliff'
20+
required: false
21+
default: 'cliff'
22+
args:
23+
description: 'Additional arguments to pass to git-cliff'
24+
required: false
25+
default: ''
26+
prepend:
27+
description: 'Prepend the generated changelog to the output file instead of overwriting it'
28+
required: false
29+
default: 'true'
30+
outputs:
31+
content:
32+
description: 'The generated changelog content'
33+
value: ${{ steps.git_cliff.outputs.content }}
34+
runs:
35+
using: "composite"
36+
steps:
37+
- name: release changelog
38+
id: git_cliff
39+
uses: orhun/git-cliff-action@v4
40+
env:
41+
OUTPUT: ${{ inputs.prepend == 'true' && '/tmp/cliff-changelog.md' || inputs.output }}
42+
with:
43+
config: ${{ inputs.config }}
44+
args: >-
45+
${{ inputs.previous-version }}..${{ inputs.prepend == 'true' && 'HEAD' || inputs.version }}
46+
--tag ${{ inputs.version }}
47+
${{ inputs.prepend == 'true' && format('--prepend {0}', inputs.output) || '' }}
48+
${{ inputs.args }}
49+
github_token: ${{ inputs.token || github.token }}
50+
51+
- name: add changelog to git staging
52+
shell: bash
53+
run: |
54+
git add "${{ inputs.output }}"

0 commit comments

Comments
 (0)