-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (123 loc) · 4.66 KB
/
Copy pathrelease-automation.yml
File metadata and controls
142 lines (123 loc) · 4.66 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
name: Release Automation
on:
push:
branches: [ main, master ]
paths-ignore:
- '**.md'
- '.github/workflows/**'
workflow_dispatch:
inputs:
release_type:
description: 'Release type (patch, minor, major)'
required: true
default: 'patch'
type: choice
options: [patch, minor, major]
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
# Only run if commit message signals a release
if: |
contains(github.event.head_commit.message, 'feat:') ||
contains(github.event.head_commit.message, 'fix:') ||
contains(github.event.head_commit.message, 'release:') ||
github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for changelog generation
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install dependencies
run: npm ci
- name: Run tests before release
run: npm test -- --passWithNoTests --watchAll=false
- name: Build
run: npm run build
- name: Determine release type
id: release-type
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "type=${{ github.event.inputs.release_type }}" >> $GITHUB_OUTPUT
else
# Auto-detect from commit message
MSG="${{ github.event.head_commit.message }}"
if echo "$MSG" | grep -q "BREAKING CHANGE\|major:"; then
echo "type=major" >> $GITHUB_OUTPUT
elif echo "$MSG" | grep -q "feat:"; then
echo "type=minor" >> $GITHUB_OUTPUT
else
echo "type=patch" >> $GITHUB_OUTPUT
fi
fi
- name: Bump version
id: version
run: |
npm version ${{ steps.release-type.outputs.type }} --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Generate changelog
id: changelog
run: |
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s (%h)" -20)
else
COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s (%h)")
fi
# Categorize commits
FEATURES=$(echo "$COMMITS" | grep "^- feat:" || echo "")
FIXES=$(echo "$COMMITS" | grep "^- fix:" || echo "")
OTHER=$(echo "$COMMITS" | grep -v "^- feat:\|^- fix:" || echo "")
CHANGELOG="## What's Changed in v${{ steps.version.outputs.version }}"
if [ -n "$FEATURES" ]; then
CHANGELOG="$CHANGELOG\n\n### ✨ New Features\n$FEATURES"
fi
if [ -n "$FIXES" ]; then
CHANGELOG="$CHANGELOG\n\n### 🐛 Bug Fixes\n$FIXES"
fi
if [ -n "$OTHER" ]; then
CHANGELOG="$CHANGELOG\n\n### 🔧 Other Changes\n$OTHER"
fi
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo -e "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Commit version bump
run: |
git add package.json package-lock.json
git commit -m "chore: release v${{ steps.version.outputs.version }} [skip ci]"
git tag "v${{ steps.version.outputs.version }}"
git push origin HEAD --tags
- name: Create GitHub Release
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${{ steps.version.outputs.version }}`,
name: `v${{ steps.version.outputs.version }}`,
body: `${{ steps.changelog.outputs.changelog }}`,
draft: false,
prerelease: false
});
- name: Summary
run: |
echo "## 🚀 Released v${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "Type: ${{ steps.release-type.outputs.type }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.changelog.outputs.changelog }}" >> $GITHUB_STEP_SUMMARY