chore: version (#341) #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release & Publish | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| registry-url: https://registry.npmjs.org | |
| - name: Install latest npm | |
| run: npm install -g npm@latest | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| - name: Install Dependencies | |
| run: pnpm install | |
| - name: Build | |
| run: pnpm run build | |
| - 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: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| generate_release_notes: true # 自动根据 commit 生成简单的更新日志 | |
| draft: false | |
| prerelease: ${{ contains(github.ref_name, '-') }} # 如果带横杠,自动标记为 Pre-release | |
| - name: Publish to npm | |
| run: | | |
| npm --version && pnpm --version && node --version | |
| npm version ${{ steps.meta.outputs.clean_version }} --no-git-tag-version | |
| pnpm publish --provenance --no-git-checks --tag ${{ steps.meta.outputs.npm_tag }} |