-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (92 loc) · 3.39 KB
/
reusable-prepare-release.yml
File metadata and controls
110 lines (92 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Prepare Release
on:
workflow_call:
inputs:
node-verions:
description: 'Node.js version to use.'
required: false
type: string
default: '20'
base-branch:
description: 'Base branch name for release pull requests.'
required: false
type: string
default: 'master'
commit-user-name:
description: 'Git user name for commit'
required: false
type: string
default: 'github-actions[bot]'
commit-user-email:
description: 'Git user email for commit.'
required: false
type: string
default: 'github-actions[bot]@users.noreply.github.com'
secrets:
ACCESS_TOKEN:
required: true
description: 'GitHub Token for authentication.'
jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- name: 👣 Track Workflow Run
continue-on-error: true
run: |
curl -s "https://abacus.jasoncameron.dev/hit/leoweyr/github-release-workflow-usage" > /dev/null
- name: 📂 Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔄 Sync Changelog Config
uses: actions/checkout@v4
with:
repository: 'leoweyr/github-release-workflow'
path: .change-log-config
sparse-checkout: src/cliff.toml
- name: 📦 Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-verions }}
- name: 🛠️ Set Environment Variables
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Create Release Branch
run: |
git config --global user.name "${{ inputs.commit-user-name }}"
git config --global user.email "${{ inputs.commit-user-email }}"
git checkout -b release/${{ env.TAG_NAME }}
- name: 📝 Generate Changelog Content for PR Body
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
run: |
npx git-cliff --config .change-log-config/src/cliff.toml --verbose --latest --strip all > pr_body_raw.md
- name: 📂 Save PR Body to File
run: |
cat pr_body_raw.md | tail -n +2 > pr_body_cleaned.md
- name: 📝 Update Changelog File
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
run: |
if [ -f "CHANGELOG.md" ]; then
# File exists: Prepend new changes (git-cliff intelligently handles headers).
npx git-cliff --config .change-log-config/src/cliff.toml --verbose --latest --prepend CHANGELOG.md
else
# File missing: Create new with full history and header.
npx git-cliff --config .change-log-config/src/cliff.toml --verbose --output CHANGELOG.md
fi
- name: 🔄 Sync Commit and Push
run: |
git add CHANGELOG.md
git commit -m "release: ${{ env.TAG_NAME }}"
git push origin release/${{ env.TAG_NAME }}
- name: 🚀 Deploy Pull Request
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
run: |
gh pr create \
--title "release: ${{ env.TAG_NAME }}" \
--body-file pr_body_cleaned.md \
--base ${{ inputs.base-branch }} \
--head release/${{ env.TAG_NAME }}