-
-
Notifications
You must be signed in to change notification settings - Fork 1
146 lines (123 loc) · 4.89 KB
/
Copy pathrelease.yml
File metadata and controls
146 lines (123 loc) · 4.89 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Create Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.4.0)'
required: true
type: string
use_existing_changelog:
description: 'Use existing CHANGELOG_{VERSION}.md file instead of generating one'
required: false
type: boolean
default: false
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
name: Create GitHub Release
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
# Extract version from tag (e.g., v1.4.0 -> 1.4.0)
VERSION="${GITHUB_REF#refs/tags/v}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check for existing changelog
id: changelog_check
run: |
VERSION="${{ steps.version.outputs.version }}"
CHANGELOG_FILE="CHANGELOG_${VERSION}.md"
if [ "${{ github.event.inputs.use_existing_changelog }}" = "true" ] && [ -f "$CHANGELOG_FILE" ]; then
echo "changelog_exists=true" >> $GITHUB_OUTPUT
echo "Using existing changelog: $CHANGELOG_FILE"
elif [ -f "$CHANGELOG_FILE" ]; then
echo "changelog_exists=false" >> $GITHUB_OUTPUT
echo "Changelog file exists but use_existing_changelog is false"
else
echo "changelog_exists=false" >> $GITHUB_OUTPUT
echo "No changelog file found, will generate with git-cliff"
- name: Generate changelog with git-cliff
if: steps.changelog_check.outputs.changelog_exists == 'false'
uses: orhun/git-cliff-action@v2
with:
config: cliff.toml
output: CHANGELOG.md
tag: ${{ steps.version.outputs.version }}
args: --verbose
- name: Format generated changelog
if: steps.changelog_check.outputs.changelog_exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
# Add version header to generated changelog
echo "# Changelog - Version $VERSION" > CHANGELOG_temp.md
echo "" >> CHANGELOG_temp.md
echo "*This changelog was automatically generated using git-cliff*" >> CHANGELOG_temp.md
echo "" >> CHANGELOG_temp.md
# Append generated changelog
cat CHANGELOG.md >> CHANGELOG_temp.md
# Replace temp file
mv CHANGELOG_temp.md CHANGELOG.md
# Create versioned changelog
cp CHANGELOG.md "CHANGELOG_${VERSION}.md"
- name: Create release notes
id: release_notes
run: |
VERSION="${{ steps.version.outputs.version }}"
if [ "${{ steps.changelog_check.outputs.changelog_exists }}" = "true" ]; then
CHANGELOG_FILE="CHANGELOG_${VERSION}.md"
# Use existing changelog
echo "### Release $VERSION" > release_notes.md
echo "" >> release_notes.md
echo "*Using existing \`$CHANGELOG_FILE\`*" >> release_notes.md
echo "" >> release_notes.md
# Add changelog content
cat "$CHANGELOG_FILE" >> release_notes.md
else
# Use git-cliff generated changelog
echo "### Release $VERSION" > release_notes.md
echo "" >> release_notes.md
echo "*Automatically generated using git-cliff*" >> release_notes.md
echo "" >> release_notes.md
# Append generated changelog (without header we added)
tail -n +2 CHANGELOG.md >> release_notes.md
fi
echo "notes_file=release_notes.md" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.version.outputs.version }}"
NOTES_FILE="${{ steps.release_notes.outputs.notes_file }}"
# Create release using GitHub CLI
gh release create "v${VERSION}" \
--title "v${VERSION}" \
--notes-file "$NOTES_FILE" \
--repo "$GITHUB_REPOSITORY"
- name: Commit new changelog if generated
if: steps.changelog_check.outputs.changelog_exists == 'false'
uses: EndBug/add-and-commit@v9
with:
message: 'chore: Generate changelog for v${{ steps.version.outputs.version }} [skip ci]'
add: '.'
path: 'CHANGELOG_${{ steps.version.outputs.version }}.md'
- name: Upload changelog artifact
uses: actions/upload-artifact@v4
with:
name: changelog-${{ steps.version.outputs.version }}
path: |
CHANGELOG_${{ steps.version.outputs.version }}.md
CHANGELOG.md
release_notes.md