|
1 | | -# 自动发布 npm 包 @opensec/secbot(以 2.0.3 / 标签 v2.0.3 为例) |
| 1 | +# 自动构建发布包并上传到 GitHub Release(以 2.0.3 / 标签 v2.0.3 为例) |
2 | 2 | # 1. 确认根目录 package.json 的 version 与即将打的标签一致(如 2.0.3 对应标签 v2.0.3)。 |
3 | | -# 2. npmjs 发布采用 Trusted Publishing(GitHub Actions OIDC),无需 NPM_TOKEN: |
4 | | -# · 需在 npm 包页面 Settings -> Publishing access / Trusted publishers 中绑定 GitHub 仓库 iammm0/secbot。 |
5 | | -# · workflow 文件名需与本文件一致(release.yml)。 |
6 | | -# · package.json 的 repository.url 需与 GitHub 仓库匹配。 |
7 | | -# · workflow permissions 需包含 id-token: write。 |
8 | | -# 3. git tag v2.0.3 && git push origin v2.0.3 |
9 | | -# 将触发:构建 → 校验版本 → 打 GitHub Release 并上传 tgz → npm trusted publish(npmjs)+ |
10 | | -# GitHub Packages(仓库 Settings -> Packages 可见;包名为 @<仓库所有者>/secbot,与 @opensec/secbot 并存)。 |
11 | | -# GitHub Packages 继续使用 GITHUB_TOKEN 认证 npm.pkg.github.com。 |
| 3 | +# 2. git tag v2.0.3 && git push origin v2.0.3 |
| 4 | +# 将触发:构建 → 校验版本 → 打 GitHub Release 并上传 tgz。 |
| 5 | +# 3. 本 workflow 不再发布到 npmjs 或 GitHub Packages。 |
12 | 6 |
|
13 | 7 | name: Release |
14 | 8 |
|
|
20 | 14 |
|
21 | 15 | permissions: |
22 | 16 | contents: write |
23 | | - packages: write |
24 | | - id-token: write |
25 | 17 |
|
26 | 18 | jobs: |
27 | 19 | build: |
|
83 | 75 | prerelease: ${{ contains(github.ref_name, '-') }} |
84 | 76 | env: |
85 | 77 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
86 | | - |
87 | | - publish-npm: |
88 | | - name: Publish to npm registry |
89 | | - needs: build |
90 | | - runs-on: ubuntu-latest |
91 | | - if: startsWith(github.ref, 'refs/tags/v') |
92 | | - steps: |
93 | | - - uses: actions/checkout@v4 |
94 | | - |
95 | | - - name: Set up Node.js for npm |
96 | | - uses: actions/setup-node@v4 |
97 | | - with: |
98 | | - node-version: '24' |
99 | | - registry-url: 'https://registry.npmjs.org' |
100 | | - cache: 'npm' |
101 | | - |
102 | | - - name: Install dependencies |
103 | | - run: npm ci |
104 | | - |
105 | | - - name: Publish to npm |
106 | | - run: | |
107 | | - PKG_VER="$(node -p "require('./package.json').version")" |
108 | | - if [[ "$PKG_VER" == *-* ]]; then |
109 | | - npm publish --access public --tag next |
110 | | - else |
111 | | - npm publish --access public |
112 | | - fi |
113 | | -
|
114 | | - publish-github-packages: |
115 | | - name: Publish to GitHub Packages |
116 | | - needs: build |
117 | | - runs-on: ubuntu-latest |
118 | | - if: startsWith(github.ref, 'refs/tags/v') |
119 | | - steps: |
120 | | - - uses: actions/checkout@v4 |
121 | | - |
122 | | - # GitHub Packages 要求作用域小写,与 apply-github-packages-name.js 中 pkg.name 一致 |
123 | | - - name: Normalize npm scope owner (lowercase) |
124 | | - run: echo "NPM_SCOPE_OWNER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
125 | | - |
126 | | - - name: Set up Node.js for GitHub Packages |
127 | | - uses: actions/setup-node@v4 |
128 | | - with: |
129 | | - node-version: '24' |
130 | | - registry-url: 'https://npm.pkg.github.com' |
131 | | - scope: '${{ env.NPM_SCOPE_OWNER }}' |
132 | | - cache: 'npm' |
133 | | - |
134 | | - - name: Install dependencies |
135 | | - run: npm ci |
136 | | - |
137 | | - - name: Apply scoped name for GitHub Packages registry |
138 | | - run: node scripts/apply-github-packages-name.js |
139 | | - env: |
140 | | - GITHUB_REPOSITORY_OWNER: ${{ env.NPM_SCOPE_OWNER }} |
141 | | - |
142 | | - - name: Publish to GitHub Packages |
143 | | - run: | |
144 | | - PKG_VER="$(node -p "require('./package.json').version")" |
145 | | - if [[ "$PKG_VER" == *-* ]]; then |
146 | | - npm publish --tag next |
147 | | - else |
148 | | - npm publish |
149 | | - fi |
150 | | - env: |
151 | | - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments