-
Notifications
You must be signed in to change notification settings - Fork 23
98 lines (84 loc) · 3.15 KB
/
Copy pathrelease.yml
File metadata and controls
98 lines (84 loc) · 3.15 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
name: Auto Release
on:
push:
branches: [main]
paths: [package.json]
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- name: Get version from package.json
id: version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=v${VERSION}" >> "$GITHUB_OUTPUT"
- name: Check if tag already exists
id: check
run: |
if git rev-parse "refs/tags/${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Generate release notes
if: steps.check.outputs.exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
REPO="${{ github.repository }}"
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
RANGE="HEAD"
COMPARE_BASE=$(git rev-list --max-parents=0 HEAD | head -1)
else
RANGE="${LAST_TAG}..HEAD"
COMPARE_BASE="$LAST_TAG"
fi
# Collect commits
COMMITS=$(git log "$RANGE" --pretty=format:"%s (%h)" --no-merges)
# Categorize by conventional commit type
node -e "
const commits = process.argv[1].split('\n').filter(Boolean);
const cats = {
feat: { title: 'New Features', items: [] },
fix: { title: 'Bug Fixes', items: [] },
docs: { title: 'Documentation', items: [] },
refactor: { title: 'Refactoring', items: [] },
test: { title: 'Tests', items: [] },
chore: { title: 'Chores', items: [] },
other: { title: 'Other Changes', items: [] },
};
for (const c of commits) {
const m = c.match(/^(\w+)(?:\(.+?\))?:\s*(.+)$/);
if (m) {
const type = m[1].toLowerCase();
(cats[type] || cats.other).items.push('- ' + c);
} else {
cats.other.items.push('- ' + c);
}
}
let body = \"## What's Changed in ${VERSION}\\n\\n\";
for (const cat of Object.values(cats)) {
if (cat.items.length === 0) continue;
body += '### ' + cat.title + '\n\n';
body += cat.items.join('\n') + '\n\n';
}
body += '**Full Changelog**: https://github.com/${REPO}/compare/${COMPARE_BASE}...${VERSION}\n';
process.stdout.write(body);
" "$COMMITS" > release-notes.md
- name: Create tag and release
if: steps.check.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
body_path: release-notes.md