-
Notifications
You must be signed in to change notification settings - Fork 1
222 lines (186 loc) · 6.81 KB
/
auto-release.yml
File metadata and controls
222 lines (186 loc) · 6.81 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: Auto Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
id-token: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
NODE_VERSION: '20'
jobs:
detect-release:
name: Detect Release
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check.outputs.should_release }}
release_type: ${{ steps.check.outputs.release_type }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect release from commits
id: check
run: |
# Manual dispatch — always release
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "should_release=true" >> $GITHUB_OUTPUT
echo "release_type=${{ github.event.inputs.release_type }}" >> $GITHUB_OUTPUT
echo "Manual release: ${{ github.event.inputs.release_type }}"
exit 0
fi
# Get all commits since last tag (handles PR merges with multiple commits)
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
COMMITS=$(git log --pretty=format:"%s" ${LAST_TAG}..HEAD)
else
COMMITS=$(git log --pretty=format:"%s")
fi
echo "Commits since last tag:"
echo "$COMMITS"
# Skip if only maintenance commits
NON_MAINTENANCE=$(echo "$COMMITS" | grep -v -E '^\[skip ci\]|^chore: bump version|^chore\(deps|^Merge pull request.*dependabot' || true)
if [ -z "$NON_MAINTENANCE" ]; then
echo "should_release=false" >> $GITHUB_OUTPUT
echo "Skipping: only maintenance commits"
exit 0
fi
# Scan ALL commits for highest priority: major > minor > patch
# This correctly handles PR merges with multiple conventional commits
RELEASE_TYPE=""
if echo "$COMMITS" | grep -qE '^feat!|^fix!|^refactor!|BREAKING CHANGE'; then
RELEASE_TYPE="major"
elif echo "$COMMITS" | grep -qE '^feat(\(|:)'; then
RELEASE_TYPE="minor"
elif echo "$COMMITS" | grep -qE '^fix(\(|:)|^perf(\(|:)|^refactor(\(|:)'; then
RELEASE_TYPE="patch"
fi
if [ -n "$RELEASE_TYPE" ]; then
echo "should_release=true" >> $GITHUB_OUTPUT
echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
echo "Detected: $RELEASE_TYPE release"
else
echo "should_release=false" >> $GITHUB_OUTPUT
echo "No releasable commits found"
fi
release:
name: Release
runs-on: ubuntu-latest
needs: detect-release
if: needs.detect-release.outputs.should_release == 'true'
environment: npm-publish
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
registry-url: https://registry.npmjs.org
- name: Upgrade npm for OIDC
run: npm install -g npm@latest
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Typecheck
run: pnpm typecheck
- name: Test
run: pnpm test
- name: Build
run: pnpm build
- name: Bump version
id: bump
run: |
RELEASE_TYPE="${{ needs.detect-release.outputs.release_type }}"
NEW_VERSION=$(npm version "$RELEASE_TYPE" --no-git-tag-version | sed 's/^v//')
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumped to: $NEW_VERSION"
- name: Publish to npm (OIDC provenance)
run: |
VERSION=${{ steps.bump.outputs.new_version }}
if npm view featuredrop@$VERSION version 2>/dev/null; then
echo "Version $VERSION already exists, skipping"
else
npm publish --provenance --access public
fi
- name: Commit version bump
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add package.json
if ! git diff --staged --quiet; then
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
git push
fi
- name: Create git tag
run: |
TAG_NAME="v${{ steps.bump.outputs.new_version }}"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists"
else
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
fi
- name: Generate release notes
run: |
VERSION="${{ steps.bump.outputs.new_version }}"
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
FEAT=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD | grep -E "^- feat" | head -10 || true)
FIXES=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD | grep -E "^- fix" | head -10 || true)
PERF=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD | grep -E "^- (perf|refactor)" | head -5 || true)
else
FEAT="- Initial release"
FIXES=""
PERF=""
fi
cat > release_notes.md << 'NOTES_EOF'
## What's Changed
NOTES_EOF
if [ -n "$FEAT" ]; then
echo "" >> release_notes.md
echo "### Features" >> release_notes.md
echo "$FEAT" >> release_notes.md
fi
if [ -n "$FIXES" ]; then
echo "" >> release_notes.md
echo "### Bug Fixes" >> release_notes.md
echo "$FIXES" >> release_notes.md
fi
if [ -n "$PERF" ]; then
echo "" >> release_notes.md
echo "### Improvements" >> release_notes.md
echo "$PERF" >> release_notes.md
fi
cat >> release_notes.md << INSTALL_EOF
### Install
\`\`\`bash
npm install featuredrop@${VERSION}
\`\`\`
**Full Changelog**: https://github.com/GLINCKER/featuredrop/compare/${PREV_TAG:-v1.0.0}...v${VERSION}
INSTALL_EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.bump.outputs.new_version }}
name: v${{ steps.bump.outputs.new_version }}
body_path: release_notes.md
draft: false