ci: 🎡 publish分离版本号更新

This commit is contained in:
CodiceFabbrica 2026-03-18 16:32:27 +08:00
parent a8af544e79
commit da7d53e791
10 changed files with 100 additions and 142 deletions

View File

@ -1,27 +1,33 @@
{
"permissions": {
"defaultMode": "acceptEdits",
"allow": [
"Bash(pnpm --filter @r-utils/vue3 add vue)",
"Bash(grep -A 5 '\"\"dependencies\"\"' /d/Projects/r-util-js/packages/*/package.json)",
"Bash(grep -r \"console.log\" /d/Projects/r-util-js/packages/*/webpack.config.js)",
"Bash(grep -c \"__dirname\" /d/Projects/r-util-js/packages/*/webpack.config.js)",
"Bash(grep -r \"private.*true\" /d/Projects/r-util-js/packages/*/package.json)",
"Bash(grep \"name\" /d/Projects/r-util-js/packages/*/package.json)",
"Bash(git -C /d/Projects/r-util-js status --short)",
"Read(./)",
"Edit(./)",
"Write(./)",
"Bash(npm run *)",
"Bash(npm test *)",
"Bash(npm run build *)",
"Bash(npm view *)",
"Bash(npm list *)",
"Bash(pnpm install)",
"Bash(pnpm build)",
"Bash(pnpm test)",
"Bash(pnpm run *)",
"Bash(pnpm test *)",
"Bash(pnpm run build *)",
"Bash(pnpm view *)",
"Bash(pnpm list *)",
"Bash(git diff *)",
"Bash(git status *)",
"Bash(git log *)",
"Bash(grep *)",
"Bash(pnpm --filter @r-utils/vue3 add vue)",
"Bash(printf 'npm run lint-staged\\\\nnpm test\\\\n')",
"Bash(printf 'npx commitlint --edit \"\"$1\"\"\\\\n')",
"Bash(npm view typescript version)",
"Bash(pnpm update typescript)",
"Bash(npm view @typescript-eslint/parser versions --json)",
"Bash(npm view @typescript-eslint/parser@latest peerDependencies)",
"Bash(npm view @typescript-eslint/parser@latest version)",
"Bash(pnpm list typescript)",
"Bash(pnpm list @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript-eslint)",
"Bash(npm view @commitlint/cz-commitlint@latest peerDependencies)",
"Bash(npm view inquirer@9 version)"
]
"Bash(pnpm update typescript)"
],
"ask": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)", "Bash(git push *)", "Bash(rm -rf *)"]
}
}

9
.versionrc.json Normal file
View File

@ -0,0 +1,9 @@
{
"bumpFiles": [
{ "filename": "package.json", "type": "json" },
{ "filename": "packages/common/package.json", "type": "json" },
{ "filename": "packages/vue3/package.json", "type": "json" },
{ "filename": "packages/uni-app/package.json", "type": "json" },
{ "filename": "packages/vue2/package.json", "type": "json" }
]
}

View File

@ -60,6 +60,22 @@ pnpm commit
**注意**:提交时 husky pre-commit 钩子会自动运行 lint-staged 和 jest 测试commit-msg 钩子会用 commitlint 校验提交信息格式。
### 发布
发布分两步:先用 `standard-version` 管理版本,再用脚本构建和发布。
```bash
# 1. 版本管理(更新版本号 + 生成 CHANGELOG + git commit/tag
pnpm release # 默认 patch
npx standard-version --release-as minor # 指定版本类型
# 2. 构建并发布到 npm
bash scripts/publish.sh # Linux/macOS
powershell scripts/publish.ps1 # Windows
```
版本配置见 `.versionrc.json`,会同步更新根包和所有子包的版本号。
## 架构说明
### Monorepo 结构

View File

@ -139,44 +139,42 @@ pnpm commit
## 发布
### 发布到私有 npm 仓库
### 1. 版本管理standard-version
使用 `standard-version` 更新版本号、生成 CHANGELOG、创建 Git commit 和 tag。版本配置见 `.versionrc.json`,会同步更新根包和所有子包的版本号。
```bash
# 默认 patch 版本
pnpm release
# 指定版本类型
npx standard-version --release-as minor # 1.0.0 -> 1.1.0
npx standard-version --release-as major # 1.0.0 -> 2.0.0
```
### 2. 构建并发布到私有 npm 仓库
项目已配置发布到私有 npm 仓库 `http://npm.nps.yunvip123.cn`
#### Windows (PowerShell)
```powershell
# 发布所有子包(默认 patch 版本)
powershell scripts/publish.ps1
# 指定版本类型
powershell scripts/publish.ps1 patch # 1.0.0 -> 1.0.1
powershell scripts/publish.ps1 minor # 1.0.0 -> 1.1.0
powershell scripts/publish.ps1 major # 1.0.0 -> 2.0.0
```
#### Linux/macOS (Bash)
```bash
# 发布所有子包(默认 patch 版本)
bash scripts/publish.sh
# 指定版本类型
bash scripts/publish.sh patch # 1.0.0 -> 1.0.1
bash scripts/publish.sh minor # 1.0.0 -> 1.1.0
bash scripts/publish.sh major # 1.0.0 -> 2.0.0
```
发布脚本会自动执行以下步骤:
1. 检查 Git 工作区状态
2. 运行测试(确保代码质量)
3. 更新所有子包的版本号
4. 构建所有子包
5. 提交版本更新到 Git
6. 依次发布 `@r-utils/common`、`@r-utils/vue3`、`@r-utils/uni-app`、`@r-utils/vue2`
7. 创建 Git 标签(如 `v1.0.1`
8. 询问是否推送到远程仓库
3. 构建所有子包
4. 依次发布 `@r-utils/common`、`@r-utils/vue3`、`@r-utils/uni-app`、`@r-utils/vue2`
5. 询问是否推送到远程仓库
### 安装已发布的包

View File

@ -1,12 +1,12 @@
{
"name": "@r-utils/common",
"version": "1.0.2",
"version": "1.0.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@r-utils/common",
"version": "1.0.2",
"version": "1.0.3",
"dependencies": {
"@r-utils/common": "file:",
"dayjs": "^1.11.13",

View File

@ -1,12 +1,12 @@
{
"name": "@r-utils/uni-app",
"version": "1.0.1",
"version": "1.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@r-utils/uni-app",
"version": "1.0.1",
"version": "1.0.2",
"dependencies": {
"@r-utils/root": "file:",
"@r-utils/uni-app": "file:",

View File

@ -1,12 +1,12 @@
{
"name": "@r-utils/vue2",
"version": "1.0.1",
"version": "1.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@r-utils/vue2",
"version": "1.0.1",
"version": "1.0.2",
"dependencies": {
"@r-utils/vue2": "file:",
"lodash": "^4.17.21"

View File

@ -1,12 +1,12 @@
{
"name": "@r-utils/vue3",
"version": "1.0.2",
"version": "1.0.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@r-utils/vue3",
"version": "1.0.2",
"version": "1.0.3",
"license": "ISC",
"dependencies": {
"@r-utils/vue3": "file:",

View File

@ -1,21 +1,11 @@
# 发布所有子包到私有 npm 仓库
# 使用方法: powershell scripts/publish.ps1 [版本类型]
# 版本类型: major | minor | patch (默认 patch)
# 发布所有子包到私有 npm 仓库
# 使用方法: powershell scripts/publish.ps1
# 注意: 发布仓库地址使用各子包 package.json 中的 publishConfig.registry 配置
# 版本管理请先通过 pnpm release (standard-version) 完成,本脚本仅负责构建和发布
$ErrorActionPreference = "Stop"
# 获取版本类型参数,默认为 patch
$VERSION_TYPE = if ($args.Count -gt 0) { $args[0] } else { "patch" }
# 验证版本类型
if ($VERSION_TYPE -notin @("major", "minor", "patch")) {
Write-Host "❌ 无效的版本类型: $VERSION_TYPE" -ForegroundColor Red
Write-Host "使用方法: powershell scripts/publish.ps1 [major|minor|patch]" -ForegroundColor Yellow
exit 1
}
Write-Host "🚀 开始发布流程 (版本类型: $VERSION_TYPE)" -ForegroundColor Green
Write-Host "🚀 开始发布流程" -ForegroundColor Green
Write-Host ""
# 子包列表
@ -48,19 +38,7 @@ if ($LASTEXITCODE -ne 0) {
}
Write-Host ""
# 3. 更新版本号
Write-Host "📝 更新版本号 ($VERSION_TYPE)..." -ForegroundColor Cyan
foreach ($package in $PACKAGES) {
if (Test-Path $package) {
Write-Host " 更新 $package 版本号..." -ForegroundColor Gray
Push-Location $package
npm version $VERSION_TYPE --no-git-tag-version
Pop-Location
}
}
Write-Host ""
# 4. 构建所有包
# 3. 构建所有包
Write-Host "📦 构建所有包..." -ForegroundColor Cyan
pnpm build
if ($LASTEXITCODE -ne 0) {
@ -69,22 +47,12 @@ if ($LASTEXITCODE -ne 0) {
}
Write-Host ""
# 5. 更新 README 中的版本信息
Write-Host "📄 更新 README..." -ForegroundColor Cyan
$COMMON_VERSION = node -p "require('./packages/common/package.json').version"
Write-Host " 当前版本: $COMMON_VERSION" -ForegroundColor Gray
# 获取当前版本号
$CURRENT_VERSION = node -p "require('./package.json').version"
Write-Host " 当前版本: v$CURRENT_VERSION" -ForegroundColor Gray
Write-Host ""
# 6. 提交版本更新
Write-Host "💾 提交版本更新..." -ForegroundColor Cyan
git add packages/*/package.json
git commit -m "chore(release): publish v$COMMON_VERSION"
if ($LASTEXITCODE -ne 0) {
Write-Host " 没有需要提交的更改" -ForegroundColor Gray
}
Write-Host ""
# 7. 发布每个包
# 4. 发布每个包
Write-Host "📤 开始发布包到 npm..." -ForegroundColor Cyan
foreach ($package in $PACKAGES) {
if (Test-Path $package) {
@ -106,23 +74,18 @@ foreach ($package in $PACKAGES) {
}
}
# 8. 创建 Git 标签
Write-Host "🏷️ 创建 Git 标签..." -ForegroundColor Cyan
git tag "v$COMMON_VERSION"
Write-Host ""
# 9. 推送到远程仓库
# 5. 推送到远程仓库
Write-Host "🔼 推送到远程仓库..." -ForegroundColor Cyan
$push = Read-Host "是否推送到远程仓库? (y/N)"
if ($push -eq "y" -or $push -eq "Y") {
git push origin master
git push origin "v$COMMON_VERSION"
git push origin --tags
Write-Host "✅ 已推送到远程仓库" -ForegroundColor Green
} else {
Write-Host "⚠️ 跳过推送,请手动执行:" -ForegroundColor Yellow
Write-Host " git push origin master" -ForegroundColor Gray
Write-Host " git push origin v$COMMON_VERSION" -ForegroundColor Gray
Write-Host " git push origin --tags" -ForegroundColor Gray
}
Write-Host ""
Write-Host "🎉 所有包发布完成!版本: v$COMMON_VERSION" -ForegroundColor Green
Write-Host "🎉 所有包发布完成!版本: v$CURRENT_VERSION" -ForegroundColor Green

View File

@ -1,23 +1,13 @@
#!/bin/bash
# 发布所有子包到私有 npm 仓库
# 使用方法: bash scripts/publish.sh [版本类型]
# 版本类型: major | minor | patch (默认 patch)
# 使用方法: bash scripts/publish.sh
# 注意: 发布仓库地址使用各子包 package.json 中的 publishConfig.registry 配置
# 版本管理请先通过 pnpm release (standard-version) 完成,本脚本仅负责构建和发布
set -e
# 获取版本类型参数,默认为 patch
VERSION_TYPE=${1:-patch}
# 验证版本类型
if [[ ! "$VERSION_TYPE" =~ ^(major|minor|patch)$ ]]; then
echo "❌ 无效的版本类型: $VERSION_TYPE"
echo "使用方法: bash scripts/publish.sh [major|minor|patch]"
exit 1
fi
echo "🚀 开始发布流程 (版本类型: $VERSION_TYPE)"
echo "🚀 开始发布流程"
echo ""
# 子包列表
@ -49,39 +39,20 @@ if ! pnpm test; then
fi
echo ""
# 3. 更新版本号
echo "📝 更新版本号 ($VERSION_TYPE)..."
for package in "${PACKAGES[@]}"; do
if [ -d "$package" ]; then
echo " 更新 $package 版本号..."
cd "$package"
npm version $VERSION_TYPE --no-git-tag-version
cd - > /dev/null
fi
done
echo ""
# 4. 构建所有包
# 3. 构建所有包
echo "📦 构建所有包..."
if ! pnpm build; then
echo "❌构建失败,停止发布"
echo "❌ 构建失败,停止发布"
exit 1
fi
echo ""
# 5. 更新 README 中的版本信息
echo "📄 更新 README..."
COMMON_VERSION=$(node -p "require('./packages/common/package.json').version")
echo " 当前版本: $COMMON_VERSION"
# 获取当前版本号
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo " 当前版本: v$CURRENT_VERSION"
echo ""
# 6. 提交版本更新
echo "💾 提交版本更新..."
git add packages/*/package.json
git commit -m "chore(release): publish v$COMMON_VERSION" || echo " 没有需要提交的更改"
echo ""
# 7. 发布每个包
# 4. 发布每个包
echo "📤 开始发布包到 npm..."
for package in "${PACKAGES[@]}"; do
if [ -d "$package" ]; then
@ -101,24 +72,19 @@ for package in "${PACKAGES[@]}"; do
fi
done
# 8. 创建 Git 标签
echo "🏷️ 创建 Git 标签..."
git tag "v$COMMON_VERSION"
echo ""
# 9. 推送到远程仓库
# 5. 推送到远程仓库
echo "🔼 推送到远程仓库..."
read -p "是否推送到远程仓库? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git push origin master
git push origin "v$COMMON_VERSION"
git push origin --tags
echo "✅ 已推送到远程仓库"
else
echo "⚠️ 跳过推送,请手动执行:"
echo " git push origin master"
echo " git push origin v$COMMON_VERSION"
echo " git push origin --tags"
fi
echo ""
echo "🎉 所有包发布完成!版本: v$COMMON_VERSION"
echo "🎉 所有包发布完成!版本: v$CURRENT_VERSION"