-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (88 loc) · 2.99 KB
/
Copy pathrelease.yml
File metadata and controls
103 lines (88 loc) · 2.99 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
name: Release Bun Package
on:
push:
branches:
- main
paths:
- package.json
- CHANGELOG.md
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
release:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Step 2: Setup Bun
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
version: latest
# Step 3: Install Dependencies && Build Package
- name: Install Dependencies
run: bun install --frozen-lockfile
- name: Build Package
run: bun run build
# Step 4: Read version from package.json
- name: Read package version
id: version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$VERSION" >> $GITHUB_OUTPUT
if [[ "$VERSION" == *"-"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
echo "npm_tag=beta" >> $GITHUB_OUTPUT
echo "Detected Pre-release version: $VERSION (tag: beta)"
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
echo "npm_tag=latest" >> $GITHUB_OUTPUT
echo "Detected Release version: $VERSION (tag: latest)"
fi
# Step 5: Ensure tag doesn't already exist
- name: Check if tag exist
run: |
if git rev-parse "${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then
echo "❌ Tag already exists"
exit 1
fi
# Step 6: Extract release notes from CHANGELOG.md
- name: Generate release notes from CHANGELOG
id: notes
run: |
VERSION="v${{ steps.version.outputs.version }}"
if ! grep -q "## $VERSION" CHANGELOG.md; then
echo "❌ No changelog entry found for $VERSION"
exit 1
fi
awk -v ver="$VERSION" '
$0 == "## " ver {flag=1; next}
/^## v/ && flag {exit}
flag
' CHANGELOG.md > release.md
echo "📄 Release notes:"
cat release.md
# Step 7: Publish package
- name: Publish Bun package
run: bun publish --access public --tag ${{ steps.version.outputs.npm_tag }}
env:
NPM_AUTH_TOKEN: ${{ secrets.TUANNC2_SECRET_KEY }}
# Step 8: Create git tag
- name: Create git tag
run: |
git tag ${{ steps.version.outputs.tag }}
git push origin ${{ steps.version.outputs.tag }}
# Step 9: Create GitHub Release (from CHANGELOG)
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.tag }}
body_path: release.md
prerelease: ${{ steps.version.outputs.is_prerelease }}