-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (160 loc) · 6.7 KB
/
release.yml
File metadata and controls
204 lines (160 loc) · 6.7 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: Release Workflow
on:
push:
branches: [main]
paths:
- 'package.json'
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
default: patch
jobs:
release:
runs-on: ubuntu-latest
# Skip if commit is from github-actions bot or contains [skip ci]
if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'github-actions[bot]'"
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GA_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest
- name: Install dependencies
run: pnpm install
- name: Get current version
id: current-version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Check if tag exists
id: check-tag
run: |
VERSION="${{ steps.current-version.outputs.version }}"
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag v$VERSION already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag v$VERSION does not exist"
fi
- name: Get previous version
id: previous-version
if: steps.check-tag.outputs.exists == 'false'
run: |
# Get the latest tag
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
PREV_VERSION=${PREV_TAG#v}
echo "previous=$PREV_VERSION" >> $GITHUB_OUTPUT
echo "Previous version: $PREV_VERSION"
else
echo "previous=" >> $GITHUB_OUTPUT
echo "No previous version found"
fi
- name: Install auto-changelog globally
if: steps.check-tag.outputs.exists == 'false'
run: |
npm install -g auto-changelog
- name: Update changelog for current version
if: steps.check-tag.outputs.exists == 'false'
run: |
VERSION="${{ steps.current-version.outputs.version }}"
PREV_VERSION="${{ steps.previous-version.outputs.previous }}"
echo "Updating changelog for version v$VERSION"
# Create backup of current changelog
cp CHANGELOG.md CHANGELOG.md.backup
# Generate new changelog
auto-changelog --template keepachangelog --commit-limit false --unreleased
# If the changelog wasn't properly updated, manually update it
if ! grep -q "## \[v$VERSION\]" CHANGELOG.md; then
echo "Manually updating changelog for v$VERSION"
# Get current date
CURRENT_DATE=$(date '+%Y-%m-%d')
# Create temporary changelog content
cat > temp_changelog.md << EOF
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Generated by [\`auto-changelog\`](https://github.com/CookPete/auto-changelog).
## [Unreleased](https://github.com/chess-labs/core/compare/v$VERSION...HEAD)
## [v$VERSION](https://github.com/chess-labs/core/compare/v$PREV_VERSION...v$VERSION) - $CURRENT_DATE
### Commits
EOF
# Get commits since last version
if [ -n "$PREV_VERSION" ]; then
git log --oneline --no-merges "v$PREV_VERSION..HEAD" --pretty=format:"- %s [\`%h\`](https://github.com/chess-labs/core/commit/%H)" >> temp_changelog.md
else
git log --oneline --no-merges --pretty=format:"- %s [\`%h\`](https://github.com/chess-labs/core/commit/%H)" >> temp_changelog.md
fi
echo "" >> temp_changelog.md
echo "" >> temp_changelog.md
# Append existing changelog content (excluding header)
if [ -f CHANGELOG.md.backup ]; then
tail -n +9 CHANGELOG.md.backup >> temp_changelog.md
fi
# Replace changelog
mv temp_changelog.md CHANGELOG.md
fi
echo "✅ Changelog updated for v$VERSION"
- name: Commit and push changelog
if: steps.check-tag.outputs.exists == 'false'
run: |
VERSION="${{ steps.current-version.outputs.version }}"
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Add changelog
git add CHANGELOG.md
# Check if there are changes to commit
if ! git diff --staged --quiet; then
git commit -m "docs: auto-update changelog for v$VERSION [skip ci]"
git push origin main
echo "✅ Committed and pushed changelog updates"
else
echo "ℹ️ No changelog changes to commit"
fi
- name: Create and push tag
if: steps.check-tag.outputs.exists == 'false'
run: |
VERSION="${{ steps.current-version.outputs.version }}"
# Create annotated tag
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
echo "✅ Created and pushed tag v$VERSION"
- name: Create GitHub Release
if: steps.check-tag.outputs.exists == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GA_TOKEN }}
with:
tag_name: v${{ steps.current-version.outputs.version }}
release_name: Release v${{ steps.current-version.outputs.version }}
body: >
🚀 **Release v${{ steps.current-version.outputs.version }}**
## What's Changed
Check the [CHANGELOG.md](https://github.com/chess-labs/core/blob/main/CHANGELOG.md) for detailed changes.
**Full Changelog**: https://github.com/chess-labs/core/compare/v${{ steps.current-version.outputs.version }}...HEAD
draft: false
prerelease: false
- name: Skip message
if: steps.check-tag.outputs.exists == 'true'
run: |
echo "⏭️ Tag v${{ steps.current-version.outputs.version }} already exists, skipping release"