Skip to content

Commit 23896ae

Browse files
committed
fix(github): update versioning script and release workflow to handle package paths correctly
1 parent 4633d64 commit 23896ae

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

.github/version-script-beta.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
// .github/version-script-beta.js
22
import { execSync } from 'node:child_process';
33
import fs from 'node:fs';
4+
import path from 'node:path';
45

5-
const pkgName = process.argv[2];
6-
if (!pkgName) {
7-
console.error('❌ Missing package argument. Usage: node .github/version-script-beta.js <package-name>');
6+
const pkgPath = process.argv[2];
7+
if (!pkgPath) {
8+
console.error('❌ Missing package path. Usage: node .github/version-script-beta.js <package-path>');
89
process.exit(1);
910
}
1011

11-
const pkgPath = `packages/${pkgName}/package.json`;
12+
const absPath = path.resolve(pkgPath, 'package.json');
1213

1314
try {
14-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
15+
const pkg = JSON.parse(fs.readFileSync(absPath, 'utf-8'));
1516
const shortHash = execSync('git rev-parse --short HEAD').toString().trim();
1617
pkg.version = `0.0.0-beta.${shortHash}`;
17-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
18-
console.log(`✅ Updated ${pkgName} version → ${pkg.version}`);
18+
fs.writeFileSync(absPath, JSON.stringify(pkg, null, 2));
19+
console.log(`✅ Updated ${pkg.name} version → ${pkg.version}`);
1920
} catch (err) {
20-
console.error('Error modifying version:', err);
21+
console.error('Error modifying version:', err);
2122
process.exit(1);
2223
}

.github/workflows/release-beta.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# .github/workflows/release-beta.yml
21
name: Release - Beta
32

43
on:
@@ -30,45 +29,48 @@ jobs:
3029
uses: actions/setup-node@v4
3130
with:
3231
node-version: 20
33-
cache: "pnpm"
32+
cache: 'pnpm'
3433

3534
- name: Install deps
3635
run: pnpm install --frozen-lockfile
3736

38-
# 👇 自动检测当前 PR 修改的子包路径
37+
# 👇 自动检测当前 PR 修改的子包完整路径(适配多层目录)
3938
- name: Detect changed package
4039
id: detect
4140
run: |
4241
echo "Detecting changed package..."
43-
CHANGED=$(git diff --name-only origin/main | grep "packages/" | cut -d/ -f2 | sort | uniq | head -n 1)
44-
echo "package=$CHANGED" >> $GITHUB_OUTPUT
45-
echo "Detected package: $CHANGED"
42+
CHANGED=$(git diff --name-only origin/main | grep "packages/" | grep "package.json" | head -n 1 | xargs dirname)
43+
echo "package_path=$CHANGED" >> $GITHUB_OUTPUT
44+
echo "Detected package path: $CHANGED"
4645
47-
# 👇 生成 beta 版本号
46+
# 👇 生成 beta 版本号(自动注入路径)
4847
- name: Modify package.json version
49-
run: node .github/version-script-beta.js ${{ steps.detect.outputs.package }}
48+
run: node .github/version-script-beta.js ${{ steps.detect.outputs.package_path }}
5049

5150
# 👇 登录 npm
5251
- name: Authenticate to npm
53-
run: echo "//registry.npmjs.org/:_authToken=$NPM_ACCESS_TOKEN" >> packages/${{ steps.detect.outputs.package }}/.npmrc
52+
run: echo "//registry.npmjs.org/:_authToken=$NPM_ACCESS_TOKEN" >> ${{ steps.detect.outputs.package_path }}/.npmrc
5453
env:
5554
NPM_ACCESS_TOKEN: ${{ secrets.NPM_TOKEN }}
5655

5756
# 👇 发布 beta 包
5857
- name: Publish Beta to npm
59-
run: pnpm --filter "./packages/${{ steps.detect.outputs.package }}" publish --tag beta --access public
58+
run: pnpm --filter "./${{ steps.detect.outputs.package_path }}" publish --tag beta --access public
6059

6160
# 👇 获取新版本号
6261
- name: Get new package version
6362
id: pkg-version
6463
run: |
65-
PKG_JSON="packages/${{ steps.detect.outputs.package }}/package.json"
64+
PKG_JSON="${{ steps.detect.outputs.package_path }}/package.json"
6665
VERSION=$(jq -r .version "$PKG_JSON")
66+
PKG_NAME=$(jq -r .name "$PKG_JSON")
6767
echo "version=$VERSION" >> $GITHUB_OUTPUT
68+
echo "pkg_name=$PKG_NAME" >> $GITHUB_OUTPUT
69+
echo "Detected package: $PKG_NAME@$VERSION"
6870
69-
# 👇 上传 artifact,用于后续 comment workflow
71+
# 👇 上传 artifact, comment workflow 使用
7072
- name: Upload packaged artifact
7173
uses: actions/upload-artifact@v4
7274
with:
73-
name: npm-package-${{ steps.detect.outputs.package }}@${{ steps.pkg-version.outputs.version }}-pr-${{ github.event.number }}
74-
path: packages/${{ steps.detect.outputs.package }}/dist
75+
name: npm-package-${{ steps.pkg-version.outputs.pkg_name }}@${{ steps.pkg-version.outputs.version }}-pr-${{ github.event.number }}
76+
path: ${{ steps.detect.outputs.package_path }}/dist

0 commit comments

Comments
 (0)