-
Notifications
You must be signed in to change notification settings - Fork 5
89 lines (76 loc) · 2.66 KB
/
Copy pathauto-release.yml
File metadata and controls
89 lines (76 loc) · 2.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
name: 🚀 Auto Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: macos-latest
permissions:
id-token: write
contents: write
env:
NODE_OPTIONS: '--max-old-space-size=8192'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: npm install
- name: lint
run: npm run lint
- name: build
run: npm run build
env:
CI: false
- name: test
run: npm run test
- name: Parse Version and Tag
id: meta
run: |
# 获取当前的 ref 名称,例如 v0.8.1-alpha.0
REF_NAME=${{ github.ref_name }}
echo "Current Ref: $REF_NAME"
# 去掉 'v' 前缀,得到 0.8.1-alpha.0
VERSION=${REF_NAME#v}
echo "clean_version=$VERSION" >> $GITHUB_OUTPUT
# 判断 tag 策略
if [[ "$VERSION" == *"-"* ]]; then
# 如果版本号带横杠 (如 -alpha.0),提取横杠后的第一个单词作为 tag (如 alpha)
# 逻辑:取第一个 - 后面的内容,再取第一个 . 前面的内容
NPM_TAG=$(echo "$VERSION" | cut -d'-' -f2 | cut -d'.' -f1)
echo "Detected pre-release version. Setting npm tag to: $NPM_TAG"
echo "npm_tag=$NPM_TAG" >> $GITHUB_OUTPUT
else
# 否则就是正式版
echo "Detected stable version. Setting npm tag to: latest"
echo "npm_tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
run: |
TAG_VERSION="${{ steps.meta.outputs.clean_version }}"
PKG_VERSION=$(node -p "require('./package.json').version")
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
echo "Version mismatch: Tag ($TAG_VERSION) != Package ($PKG_VERSION). Syncing..."
npm version $TAG_VERSION --no-git-tag-version --allow-same-version
else
echo "Versions match ($TAG_VERSION). Proceeding..."
fi
npm publish --provenance --access public --tag ${{ steps.meta.outputs.npm_tag }}
env:
CI: true
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}