-
Notifications
You must be signed in to change notification settings - Fork 17
174 lines (149 loc) · 7.09 KB
/
Copy pathpublish-packages.yml
File metadata and controls
174 lines (149 loc) · 7.09 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Publish GenUI SDK packages
on:
workflow_dispatch:
inputs:
version:
description: '发布版本号,如 1.0.0-beta.2'
required: true
type: string
npm_tag:
description: '发布标签(latest=正式版,beta/alpha=预发版,安装时如 npm install pkg@beta)'
required: true
default: latest
type: choice
options:
- latest
- beta
- alpha
fetch_npm_tag:
description: '发包前从 npm 拉取版本替换 workspace 依赖所使用的 tag(通常为 latest)'
required: true
default: latest
type: choice
options:
- latest
- beta
- alpha
publish_optional_packages:
description: '同时发布 core 与物料包(vue-opentiny / vue-element-plus / angular)'
required: false
default: false
type: boolean
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Check allowed publishers
run: |
ALLOWED="${{ vars.ALLOWED_PUBLISHERS }}"
if [ -z "$ALLOWED" ]; then
echo "::error::请在仓库 Settings → Secrets and variables → Actions → Variables 中配置 ALLOWED_PUBLISHERS(逗号分隔的 GitHub 用户名)"
exit 1
fi
ACTOR="${{ github.actor }}"
if echo ",${ALLOWED}," | grep -q ",${ACTOR},"; then
echo "✓ 允许发布: $ACTOR"
else
echo "::error::无权限发布: $ACTOR 不在 ALLOWED_PUBLISHERS 列表中"
exit 1
fi
- name: Validate version (semver)
run: |
VERSION="${{ github.event.inputs.version }}"
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
echo "::error::版本号需符合语义化版本(如 1.0.0、1.0.0-beta.2),当前值: $VERSION"
exit 1
fi
echo "✓ 版本号格式正确: $VERSION"
- name: Checkout (with submodules)
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Update package versions
run: |
VERSION="${{ github.event.inputs.version }}"
node ./scripts/update-package-version.js packages/server/package.json "$VERSION"
node ./scripts/update-package-version.js packages/frameworks/vue/package.json "$VERSION"
node ./scripts/update-package-version.js packages/frameworks/angular/package.json "$VERSION"
if [ "${{ github.event.inputs.publish_optional_packages }}" = "true" ]; then
node ./scripts/update-package-version.js packages/core/package.json "$VERSION"
node ./scripts/update-package-version.js packages/materials/vue-opentiny-vue/package.json "$VERSION"
node ./scripts/update-package-version.js packages/materials/vue-element-plus/package.json "$VERSION"
node ./scripts/update-package-version.js packages/materials/angular-opentiny-ng/package.json "$VERSION"
fi
- name: Build Core
if: github.event.inputs.publish_optional_packages == 'true'
run: pnpm --filter @opentiny/genui-sdk-core build
- name: Build Vue materials
if: github.event.inputs.publish_optional_packages == 'true'
run: pnpm --filter @opentiny/genui-sdk-materials-vue-opentiny-vue build
- name: Build Element Plus materials
if: github.event.inputs.publish_optional_packages == 'true'
run: pnpm --filter @opentiny/genui-sdk-materials-vue-element-plus build
- name: Build Angular materials
if: github.event.inputs.publish_optional_packages == 'true'
run: pnpm --filter @opentiny/genui-sdk-materials-angular-opentiny-ng build
- name: Build Server
run: pnpm --filter @opentiny/genui-sdk-server build:lib:npm
- name: Build Vue
run: pnpm --filter @opentiny/genui-sdk-vue build:lib:npm
- name: Build Angular
run: pnpm --filter @opentiny/genui-sdk-angular build:lib:npm
- name: Sync workspace deps for publish
env:
FETCH_NPM_TAG: ${{ github.event.inputs.fetch_npm_tag }}
PUBLISH_VERSION: ${{ github.event.inputs.version }}
run: |
PUBLISH_PKG_JSONS="packages/server/output/package.json,packages/frameworks/vue/package.json,packages/frameworks/angular/output/package.json"
if [ "${{ github.event.inputs.publish_optional_packages }}" = "true" ]; then
PUBLISH_PKG_JSONS="${PUBLISH_PKG_JSONS},packages/core/package.json,packages/materials/vue-opentiny-vue/package.json,packages/materials/vue-element-plus/package.json,packages/materials/angular-opentiny-ng/package.json"
fi
export PUBLISH_PKG_JSONS
node ./scripts/ci-replace-workspace-deps.js
- name: Setup .npmrc for publish
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
- name: Publish Core to npm
if: github.event.inputs.publish_optional_packages == 'true'
working-directory: packages/core
run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }}
- name: Publish Vue materials to npm
if: github.event.inputs.publish_optional_packages == 'true'
working-directory: packages/materials/vue-opentiny-vue
run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }}
- name: Publish Element Plus materials to npm
if: github.event.inputs.publish_optional_packages == 'true'
working-directory: packages/materials/vue-element-plus
run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }}
- name: Publish Angular materials to npm
if: github.event.inputs.publish_optional_packages == 'true'
working-directory: packages/materials/angular-opentiny-ng
run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }}
- name: Publish server to npm
working-directory: packages/server/output
run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }}
- name: Publish Vue to npm
working-directory: packages/frameworks/vue
run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }}
- name: Publish Angular to npm
working-directory: packages/frameworks/angular/output
run: pnpm publish --no-git-checks --access public --tag ${{ github.event.inputs.npm_tag }}
- name: Create and push tags
run: |
VERSION="${{ github.event.inputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v${VERSION}"
git push origin "v${VERSION}"