Skip to content

Commit 4bec90f

Browse files
committed
feat: add prepare release workflow
1 parent 8d5c0d7 commit 4bec90f

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Prepare Release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node-verions:
7+
description: 'Node.js version to use.'
8+
required: false
9+
type: string
10+
default: '20'
11+
commit-user-name:
12+
description: 'Git user name for commit'
13+
required: false
14+
type: string
15+
default: 'github-actions[bot]'
16+
commit-user-email:
17+
description: 'Git user email for commit.'
18+
required: false
19+
type: string
20+
default: 'github-actions[bot]@users.noreply.github.com'
21+
secrets:
22+
GITHUB_TOKEN:
23+
required: true
24+
description: 'GitHub Token for authentication.'
25+
26+
jobs:
27+
prepare-release:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout Code
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Checkout Config
36+
uses: actions/checkout@v4
37+
with:
38+
repository: 'leoweyr/github-release-workflow'
39+
path: .change-log-config
40+
sparse-checkout: cliff.toml
41+
42+
- name: Setup Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: ${{ inputs.node-verions }}
46+
47+
- name: Set Environment Variables
48+
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
49+
50+
- name: Create Release Branch
51+
run: |
52+
git config --global user.name "${{ inputs.commit-user-name }}"
53+
git config --global user.email "${{ inputs.commit-user-email }}"
54+
git checkout -b release/${{ env.TAG_NAME }}
55+
56+
- name: Generate Changelog Content for PR Body
57+
env:
58+
GITHUB_REPO: ${{ github.repository }}
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
run: |
61+
npx git-cliff --config .change-log-config/cliff.toml --verbose --latest --strip all > pr_body_raw.md
62+
63+
- name: Save PR Body to File
64+
run: |
65+
cat pr_body_raw.md | tail -n +2 > pr_body_cleaned.md
66+
67+
- name: Update CHANGELOG.md File
68+
env:
69+
GITHUB_REPO: ${{ github.repository }}
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
run: |
72+
if [ -f "CHANGELOG.md" ]; then
73+
# File exists: Prepend new changes (git-cliff intelligently handles headers).
74+
npx git-cliff --config .change-log-config/cliff.toml --verbose --latest --prepend CHANGELOG.md
75+
else
76+
# File missing: Create new with full history and header.
77+
npx git-cliff --config .change-log-config/cliff.toml --verbose --output CHANGELOG.md
78+
fi
79+
80+
- name: Commit and Push
81+
run: |
82+
git add CHANGELOG.md
83+
git commit -m "release: ${{ env.TAG_NAME }}"
84+
git push origin release/${{ env.TAG_NAME }}
85+
86+
- name: Create Pull Request
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
run: |
90+
gh pr create \
91+
--title "release: ${{ env.TAG_NAME }}" \
92+
--body-file pr_body_cleaned.md \
93+
--base master \
94+
--head release/${{ env.TAG_NAME }}

0 commit comments

Comments
 (0)