|
| 1 | +name: Publish GenUI SDK packages |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: '发布版本号(将写入 server / vue / angular 的 package.json,例如 1.0.0-beta.2)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + npm_tag: |
| 11 | + description: '发布标签(latest=正式版,beta/alpha=预发版,安装时如 npm install pkg@beta)' |
| 12 | + required: true |
| 13 | + default: latest |
| 14 | + type: choice |
| 15 | + options: |
| 16 | + - latest |
| 17 | + - beta |
| 18 | + - alpha |
| 19 | + |
| 20 | +jobs: |
| 21 | + publish: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + id-token: write |
| 26 | + steps: |
| 27 | + - name: Check allowed publishers |
| 28 | + run: | |
| 29 | + ALLOWED="${{ vars.ALLOWED_PUBLISHERS }}" |
| 30 | + if [ -z "$ALLOWED" ]; then |
| 31 | + echo "::error::请在仓库 Settings → Secrets and variables → Actions → Variables 中配置 ALLOWED_PUBLISHERS(逗号分隔的 GitHub 用户名)" |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + ACTOR="${{ github.actor }}" |
| 35 | + if echo ",${ALLOWED}," | grep -q ",${ACTOR},"; then |
| 36 | + echo "✓ 允许发布: $ACTOR" |
| 37 | + else |
| 38 | + echo "::error::无权限发布: $ACTOR 不在 ALLOWED_PUBLISHERS 列表中" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Validate version (semver) |
| 43 | + run: | |
| 44 | + VERSION="${{ github.event.inputs.version }}" |
| 45 | + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then |
| 46 | + echo "::error::版本号需符合语义化版本(如 1.0.0、1.0.0-beta.2),当前值: $VERSION" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + echo "✓ 版本号格式正确: $VERSION" |
| 50 | +
|
| 51 | + - name: Checkout (with submodules) |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + fetch-depth: 0 |
| 55 | + submodules: true |
| 56 | + |
| 57 | + - name: Setup pnpm |
| 58 | + uses: pnpm/action-setup@v4 |
| 59 | + |
| 60 | + - name: Setup Node.js |
| 61 | + uses: actions/setup-node@v4 |
| 62 | + with: |
| 63 | + node-version: '20' |
| 64 | + cache: 'pnpm' |
| 65 | + |
| 66 | + - name: Install dependencies |
| 67 | + run: pnpm install |
| 68 | + |
| 69 | + - name: Update package versions |
| 70 | + run: | |
| 71 | + VERSION="${{ github.event.inputs.version }}" |
| 72 | + node ./scripts/update-package-version.js packages/server/package.json "$VERSION" |
| 73 | + node ./scripts/update-package-version.js packages/frameworks/vue/package.json "$VERSION" |
| 74 | + node ./scripts/update-package-version.js packages/frameworks/angular/package.json "$VERSION" |
| 75 | +
|
| 76 | + - name: Build Server |
| 77 | + run: pnpm --filter @opentiny/genui-sdk-server build:lib:npm |
| 78 | + |
| 79 | + - name: Build Vue |
| 80 | + run: pnpm --filter @opentiny/genui-sdk-vue build:lib:npm |
| 81 | + |
| 82 | + - name: Build Angular |
| 83 | + run: pnpm --filter @opentiny/genui-sdk-angular build:lib:npm |
| 84 | + |
| 85 | + - name: Setup .npmrc for publish |
| 86 | + run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc |
| 87 | + |
| 88 | + - name: Publish server to npm |
| 89 | + working-directory: packages/server/output |
| 90 | + run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }} |
| 91 | + |
| 92 | + - name: Publish Vue to npm |
| 93 | + working-directory: packages/frameworks/vue/output |
| 94 | + run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }} |
| 95 | + |
| 96 | + - name: Publish Angular to npm |
| 97 | + working-directory: packages/frameworks/angular/output |
| 98 | + run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }} |
| 99 | + |
| 100 | + - name: Create and push tags |
| 101 | + run: | |
| 102 | + VERSION="${{ github.event.inputs.version }}" |
| 103 | + git config user.name "github-actions[bot]" |
| 104 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 105 | + git tag "v${VERSION}" |
| 106 | + git push origin "v${VERSION}" |
0 commit comments