|
1 | | -# This action will publish the package to npm and create a GitHub release. |
2 | 1 | name: Release |
3 | 2 |
|
4 | 3 | on: |
5 | | - # Run `npm run bump` to bump the version and create a git tag. |
6 | 4 | push: |
7 | 5 | tags: |
8 | | - - "v*" |
9 | | - |
| 6 | + - 'v*' |
10 | 7 | workflow_dispatch: |
11 | | - |
12 | | -permissions: |
13 | | - contents: write |
14 | | - id-token: write |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: '发布版本 (例如: 1.0.0)' |
| 11 | + required: true |
| 12 | + type: string |
15 | 13 |
|
16 | 14 | jobs: |
17 | | - publish: |
| 15 | + release: |
18 | 16 | runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: write |
| 19 | + packages: write |
| 20 | + id-token: write |
| 21 | + |
19 | 22 | steps: |
20 | | - - name: Checkout |
| 23 | + - name: 检出代码 |
21 | 24 | uses: actions/checkout@v5 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
22 | 27 |
|
23 | | - - name: Setup pnpm |
| 28 | + - name: 设置 Node.js |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: 22.18.0 |
| 32 | + registry-url: 'https://registry.npmjs.org' |
| 33 | + |
| 34 | + - name: 安装 pnpm |
24 | 35 | uses: pnpm/action-setup@v4 |
25 | 36 | with: |
26 | 37 | version: 10.14.0 |
27 | 38 |
|
28 | | - - name: Setup Node.js |
29 | | - uses: actions/setup-node@v4 |
| 39 | + - name: 获取 pnpm store 目录 |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 43 | +
|
| 44 | + - name: 设置 pnpm 缓存 |
| 45 | + uses: actions/cache@v4 |
30 | 46 | with: |
31 | | - node-version: 22.20.0 |
32 | | - registry-url: 'https://registry.npmjs.org' |
33 | | - scope: '@winner-fed' |
34 | | - always-auth: true |
| 47 | + path: ${{ env.STORE_PATH }} |
| 48 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 49 | + restore-keys: | |
| 50 | + ${{ runner.os }}-pnpm-store- |
35 | 51 |
|
36 | | - - name: Update npm to latest |
37 | | - run: npm install -g npm@latest |
| 52 | + - name: 安装依赖 |
| 53 | + run: | |
| 54 | + # 尝试使用 frozen lockfile,如果失败则更新 lockfile |
| 55 | + pnpm install --frozen-lockfile || { |
| 56 | + echo "⚠️ Lockfile 不匹配,正在更新..." |
| 57 | + pnpm install --no-frozen-lockfile |
| 58 | + } |
38 | 59 |
|
39 | | - - name: Install Dependencies |
40 | | - run: pnpm install --frozen-lockfile |
| 60 | + - name: 格式检查 |
| 61 | + run: pnpm run lint |
41 | 62 |
|
42 | | - - name: Build |
| 63 | + - name: 构建项目 |
43 | 64 | run: pnpm run build |
44 | 65 |
|
45 | | - - name: Verify package.json |
| 66 | + - name: 获取版本号 |
| 67 | + id: get_version |
46 | 68 | run: | |
47 | | - echo "Package name: $(node -p "require('./package.json').name")" |
48 | | - echo "Package version: $(node -p "require('./package.json').version")" |
| 69 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 70 | + echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT |
| 71 | + echo "tag_name=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT |
| 72 | + else |
| 73 | + echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 74 | + echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 75 | + fi |
49 | 76 |
|
50 | | - - name: Debug npm config |
| 77 | + - name: 更新版本号 (手动触发时) |
| 78 | + if: github.event_name == 'workflow_dispatch' |
51 | 79 | run: | |
52 | | - echo "=== npm 配置信息 ===" |
53 | | - npm config list |
54 | | - echo "" |
55 | | - echo "=== 环境变量检查 ===" |
56 | | - echo "NODE_AUTH_TOKEN exists: $([ -n "$NODE_AUTH_TOKEN" ] && echo 'yes' || echo 'no')" |
57 | | - echo "NPM_TOKEN exists: $([ -n "$NPM_TOKEN" ] && echo 'yes' || echo 'no')" |
58 | | - echo "" |
59 | | - echo "=== npm 版本信息 ===" |
60 | | - npm --version |
61 | | - echo "" |
62 | | - echo "=== 检查 .npmrc 文件 ===" |
63 | | - cat ~/.npmrc 2>/dev/null || echo "未找到 .npmrc 文件" |
64 | | - echo "" |
65 | | - echo "=== 检查 npm 认证状态 ===" |
66 | | - npm whoami || echo "未认证或认证失败" |
67 | | - echo "" |
68 | | - echo "=== 检查作用域配置 ===" |
69 | | - npm config get @winner-fed:registry || echo "未找到作用域配置" |
70 | | - echo "" |
71 | | - echo "=== 检查认证 token 格式 ===" |
72 | | - if [ -n "$NODE_AUTH_TOKEN" ]; then |
73 | | - echo "Token 长度: ${#NODE_AUTH_TOKEN}" |
74 | | - echo "Token 前缀: ${NODE_AUTH_TOKEN:0:20}..." |
75 | | - fi |
| 80 | + npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version |
| 81 | + git config --local user.email "action@github.com" |
| 82 | + git config --local user.name "GitHub Action" |
| 83 | + git add package.json |
| 84 | + git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}" |
| 85 | + git tag ${{ steps.get_version.outputs.tag_name }} |
| 86 | + git push origin HEAD:${{ github.ref_name }} |
| 87 | + git push origin ${{ steps.get_version.outputs.tag_name }} |
| 88 | +
|
| 89 | + - name: 生成变更日志 |
| 90 | + id: changelog |
| 91 | + run: npx changelogithub |
| 92 | + continue-on-error: true |
| 93 | + env: |
| 94 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
76 | 95 |
|
77 | | - - name: Publish to npm |
78 | | - run: npm publish --access public --provenance |
| 96 | + - name: 发布到 npm |
| 97 | + run: pnpm publish --no-git-checks |
| 98 | + env: |
| 99 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
79 | 100 |
|
80 | | - - name: Create GitHub Release |
81 | | - uses: ncipollo/release-action@v1 |
| 101 | + - name: 创建 GitHub Release |
| 102 | + uses: actions/create-release@v1 |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
82 | 105 | with: |
83 | | - generateReleaseNotes: "true" |
| 106 | + tag_name: ${{ steps.get_version.outputs.tag_name }} |
| 107 | + release_name: Release ${{ steps.get_version.outputs.tag_name }} |
| 108 | + body_path: ${{ steps.changelog.outputs.changelog_file }} |
| 109 | + draft: false |
| 110 | + prerelease: false |
| 111 | + |
| 112 | + - name: 通知发布成功 |
| 113 | + run: | |
| 114 | + echo "🎉 发布成功!" |
| 115 | + echo "📦 版本: ${{ steps.get_version.outputs.version }}" |
| 116 | + echo "🏷️ 标签: ${{ steps.get_version.outputs.tag_name }}" |
| 117 | + echo "📝 npm: https://www.npmjs.com/package/@winner-fed/plugin-antdv" |
0 commit comments