@coze-arch/rush-publish-plugin 0.0.5-alpha.0f1107 → 0.0.5-alpha.8b5f6f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/command-line.json +26 -2
- package/lib/action/publish/confirm.d.ts +5 -1
- package/lib/action/publish/git.d.ts +1 -5
- package/lib/action/publish/push-to-remote.d.ts +1 -0
- package/lib/action/publish/types.d.ts +3 -0
- package/lib/action/release/plan.d.ts +1 -1
- package/lib/action/release/types.d.ts +3 -1
- package/lib/const/index.d.ts +12 -0
- package/lib/index.js +173 -58
- package/lib/utils/get-plugin-config.d.ts +8 -0
- package/lib/utils/git.d.ts +5 -0
- package/package.json +1 -1
package/command-line.json
CHANGED
|
@@ -106,6 +106,22 @@
|
|
|
106
106
|
"associatedCommands": ["pub"],
|
|
107
107
|
"required": false
|
|
108
108
|
},
|
|
109
|
+
{
|
|
110
|
+
"parameterKind": "string",
|
|
111
|
+
"longName": "--branch-prefix",
|
|
112
|
+
"description": "Git branch name prefix (default: 'release')",
|
|
113
|
+
"argumentName": "BRANCH_PREFIX",
|
|
114
|
+
"associatedCommands": ["pub"],
|
|
115
|
+
"required": false
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"parameterKind": "flag",
|
|
119
|
+
"longName": "--release",
|
|
120
|
+
"shortName": "-l",
|
|
121
|
+
"description": "Directly publish packages (only for alpha/beta versions)",
|
|
122
|
+
"associatedCommands": ["pub"],
|
|
123
|
+
"required": false
|
|
124
|
+
},
|
|
109
125
|
{
|
|
110
126
|
"parameterKind": "flag",
|
|
111
127
|
"longName": "--amend-commit",
|
|
@@ -141,8 +157,16 @@
|
|
|
141
157
|
"argumentName": "REGISTRY",
|
|
142
158
|
"longName": "--registry",
|
|
143
159
|
"shortName": "-r",
|
|
144
|
-
"description": "
|
|
145
|
-
"associatedCommands": ["release"]
|
|
160
|
+
"description": "NPM registry URL (default: https://registry.npmjs.org)",
|
|
161
|
+
"associatedCommands": ["release", "pub"]
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"parameterKind": "stringList",
|
|
165
|
+
"argumentName": "ALLOW_BRANCHES",
|
|
166
|
+
"longName": "--allow-branches",
|
|
167
|
+
"description": "Branches allowed for LATEST release (default: main, feat/auto-publish)",
|
|
168
|
+
"associatedCommands": ["release"],
|
|
169
|
+
"required": false
|
|
146
170
|
}
|
|
147
171
|
]
|
|
148
172
|
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { type PublishManifest } from './types';
|
|
2
|
-
export
|
|
2
|
+
export interface ConfirmForPublishOptions {
|
|
3
|
+
isReleaseMode?: boolean;
|
|
4
|
+
registry?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const confirmForPublish: (publishManifest: PublishManifest[], dryRun: boolean, options?: ConfirmForPublishOptions) => Promise<boolean>;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { type PublishManifest } from './types';
|
|
2
1
|
export declare function createAndPushBranch(branchName: string, cwd: string): Promise<void>;
|
|
3
2
|
interface CommitChangesOptions {
|
|
4
|
-
sessionId: string;
|
|
5
3
|
files: string[];
|
|
6
4
|
cwd: string;
|
|
7
|
-
publishManifests: PublishManifest[];
|
|
8
5
|
branchName: string;
|
|
9
|
-
createTags: boolean;
|
|
10
6
|
}
|
|
11
|
-
export declare function commitChanges({
|
|
7
|
+
export declare function commitChanges({ files, cwd, branchName, }: CommitChangesOptions): Promise<{
|
|
12
8
|
effects: string[];
|
|
13
9
|
branchName: string;
|
|
14
10
|
}>;
|
|
@@ -5,4 +5,4 @@ export declare enum ReleaseType {
|
|
|
5
5
|
LATEST = "latest"
|
|
6
6
|
}
|
|
7
7
|
export declare const calReleaseType: (version: string) => ReleaseType;
|
|
8
|
-
export declare const checkReleasePlan: (releaseManifests: ReleaseManifest[], branchName: string) => boolean;
|
|
8
|
+
export declare const checkReleasePlan: (releaseManifests: ReleaseManifest[], branchName: string, allowBranches?: string[]) => boolean;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type RushConfigurationProject } from '@rushstack/rush-sdk';
|
|
2
2
|
export interface ReleaseOptions {
|
|
3
|
-
commit
|
|
3
|
+
commit?: string;
|
|
4
4
|
dryRun?: boolean;
|
|
5
5
|
registry: string;
|
|
6
|
+
packages?: PackageToPublish[];
|
|
7
|
+
allowBranches?: string[];
|
|
6
8
|
}
|
|
7
9
|
export interface PackageToPublish {
|
|
8
10
|
packageName: string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 默认的 NPM registry 地址
|
|
3
|
+
*/
|
|
4
|
+
export declare const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
|
|
5
|
+
/**
|
|
6
|
+
* 默认的 Git 分支名前缀
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_BRANCH_PREFIX = "bump";
|
|
9
|
+
/**
|
|
10
|
+
* 默认允许发布正式版本的分支列表
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_ALLOW_BRANCHES: string[];
|
package/lib/index.js
CHANGED
|
@@ -148,6 +148,24 @@ const logger = {
|
|
|
148
148
|
// Copyright (c) 2025 coze-dev
|
|
149
149
|
// SPDX-License-Identifier: MIT
|
|
150
150
|
|
|
151
|
+
/**
|
|
152
|
+
* 默认的 NPM registry 地址
|
|
153
|
+
*/
|
|
154
|
+
const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 默认的 Git 分支名前缀
|
|
158
|
+
*/
|
|
159
|
+
const DEFAULT_BRANCH_PREFIX = 'bump';
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 默认允许发布正式版本的分支列表
|
|
163
|
+
*/
|
|
164
|
+
const DEFAULT_ALLOW_BRANCHES = ['main', 'feat/auto-publish'];
|
|
165
|
+
|
|
166
|
+
// Copyright (c) 2025 coze-dev
|
|
167
|
+
// SPDX-License-Identifier: MIT
|
|
168
|
+
|
|
151
169
|
|
|
152
170
|
|
|
153
171
|
|
|
@@ -214,6 +232,15 @@ const getCurrentBranchName = async () => {
|
|
|
214
232
|
return stdout.trim();
|
|
215
233
|
};
|
|
216
234
|
|
|
235
|
+
/**
|
|
236
|
+
* 获取当前 commit hash
|
|
237
|
+
* @returns commit hash
|
|
238
|
+
*/
|
|
239
|
+
const getCurrentCommitHash = async () => {
|
|
240
|
+
const { stdout } = await exec('git rev-parse HEAD');
|
|
241
|
+
return stdout.trim();
|
|
242
|
+
};
|
|
243
|
+
|
|
217
244
|
const isMainBranch = async () => {
|
|
218
245
|
const currentBranchName = await getCurrentBranchName();
|
|
219
246
|
return currentBranchName === 'main';
|
|
@@ -369,7 +396,12 @@ const publishPackage = async (
|
|
|
369
396
|
: version.includes('beta')
|
|
370
397
|
? 'beta'
|
|
371
398
|
: 'latest';
|
|
372
|
-
const
|
|
399
|
+
const setToken = `npm config set //bnpm.byted.org/:_authToken ${token}`;
|
|
400
|
+
await exec(setToken, {
|
|
401
|
+
cwd: project.projectFolder,
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
const args = [`NODE_AUTH_TOKEN=${token}`, 'npm', 'publish', `--tag ${tag}`];
|
|
373
405
|
if (dryRun) {
|
|
374
406
|
args.push('--dry-run');
|
|
375
407
|
}
|
|
@@ -444,13 +476,16 @@ const calReleasePlan = (releaseManifests) => {
|
|
|
444
476
|
const checkReleasePlan = (
|
|
445
477
|
releaseManifests,
|
|
446
478
|
branchName,
|
|
479
|
+
allowBranches = ['main', 'feat/auto-publish'],
|
|
447
480
|
) => {
|
|
448
481
|
const releasePlan = calReleasePlan(releaseManifests);
|
|
449
482
|
if (
|
|
450
483
|
releasePlan === ReleaseType.LATEST &&
|
|
451
|
-
!
|
|
484
|
+
!allowBranches.includes(branchName)
|
|
452
485
|
) {
|
|
453
|
-
throw new Error(
|
|
486
|
+
throw new Error(
|
|
487
|
+
`For LATEST release, should be on one of these branches: ${allowBranches.join(', ')}.`,
|
|
488
|
+
);
|
|
454
489
|
}
|
|
455
490
|
return true;
|
|
456
491
|
};
|
|
@@ -519,10 +554,32 @@ const getPackagesToPublish = async (
|
|
|
519
554
|
|
|
520
555
|
|
|
521
556
|
async function release(options) {
|
|
522
|
-
const {
|
|
557
|
+
const {
|
|
558
|
+
dryRun = false,
|
|
559
|
+
registry,
|
|
560
|
+
packages,
|
|
561
|
+
allowBranches = DEFAULT_ALLOW_BRANCHES,
|
|
562
|
+
} = options;
|
|
563
|
+
let { commit } = options;
|
|
564
|
+
const hasPassedCommit = !!options.commit;
|
|
523
565
|
|
|
524
566
|
// 1. 获取需要发布的包列表
|
|
525
|
-
|
|
567
|
+
let packagesToPublish;
|
|
568
|
+
if (packages) {
|
|
569
|
+
// 直接使用传入的包列表
|
|
570
|
+
packagesToPublish = packages;
|
|
571
|
+
logger.info('Using provided package list');
|
|
572
|
+
} else {
|
|
573
|
+
// 从 git tags 获取包列表
|
|
574
|
+
if (!hasPassedCommit) {
|
|
575
|
+
commit = await getCurrentCommitHash();
|
|
576
|
+
logger.info('Using current commit');
|
|
577
|
+
}
|
|
578
|
+
// 此时 commit 必定有值(要么传入了,要么刚获取了)
|
|
579
|
+
const commitHash = commit ;
|
|
580
|
+
packagesToPublish = await getPackagesToPublish(commitHash);
|
|
581
|
+
}
|
|
582
|
+
|
|
526
583
|
if (packagesToPublish.length === 0) {
|
|
527
584
|
logger.warn('No packages to publish');
|
|
528
585
|
return;
|
|
@@ -538,8 +595,16 @@ async function release(options) {
|
|
|
538
595
|
false,
|
|
539
596
|
);
|
|
540
597
|
const branchName = await getCurrentBranchName();
|
|
541
|
-
checkReleasePlan(releaseManifests, branchName);
|
|
542
|
-
|
|
598
|
+
checkReleasePlan(releaseManifests, branchName, allowBranches);
|
|
599
|
+
|
|
600
|
+
// 只有在指定了 commit 且与当前 HEAD 不同时才切换
|
|
601
|
+
if (hasPassedCommit) {
|
|
602
|
+
const currentHead = await getCurrentCommitHash();
|
|
603
|
+
if (currentHead !== commit) {
|
|
604
|
+
logger.info(`Checking out commit: ${commit}`);
|
|
605
|
+
await exec(`git checkout ${commit}`);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
543
608
|
|
|
544
609
|
await releasePackages(releaseManifests, { dryRun, registry });
|
|
545
610
|
logger.success('All packages published successfully!');
|
|
@@ -555,18 +620,19 @@ const installAction$2 = (program) => {
|
|
|
555
620
|
program
|
|
556
621
|
.command('release')
|
|
557
622
|
.description('Release packages based on git tags.')
|
|
558
|
-
.
|
|
623
|
+
.option('--commit <string>', '需要执行发布的 commit id (默认使用当前 HEAD)')
|
|
559
624
|
.option('--dry-run', '是否只执行不真实发布', false)
|
|
560
625
|
.option(
|
|
561
626
|
'-r, --registry <string>',
|
|
562
|
-
|
|
563
|
-
|
|
627
|
+
`发布到的 registry (默认: ${DEFAULT_NPM_REGISTRY})`,
|
|
628
|
+
DEFAULT_NPM_REGISTRY,
|
|
629
|
+
)
|
|
630
|
+
.option(
|
|
631
|
+
'--allow-branches <branches...>',
|
|
632
|
+
`允许发布正式版本的分支列表 (默认: ${DEFAULT_ALLOW_BRANCHES.join(', ')})`,
|
|
564
633
|
)
|
|
565
634
|
.action(async (options) => {
|
|
566
635
|
try {
|
|
567
|
-
if (!options.commit) {
|
|
568
|
-
throw new Error('请提供需要发布的 commit id');
|
|
569
|
-
}
|
|
570
636
|
if (!process.env.NPM_AUTH_TOKEN) {
|
|
571
637
|
throw new Error('请设置 NPM_AUTH_TOKEN 环境变量');
|
|
572
638
|
}
|
|
@@ -805,31 +871,15 @@ const generatePublishManifest = async (
|
|
|
805
871
|
|
|
806
872
|
|
|
807
873
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
874
|
async function commitChanges({
|
|
812
|
-
sessionId,
|
|
813
875
|
files,
|
|
814
876
|
cwd,
|
|
815
|
-
publishManifests,
|
|
816
877
|
branchName,
|
|
817
|
-
createTags,
|
|
818
878
|
}) {
|
|
819
879
|
await exec(`git add ${files.join(' ')}`, { cwd });
|
|
820
880
|
await exec(`git commit -m "chore: Publish ${branchName}" -n`, { cwd });
|
|
821
881
|
|
|
822
|
-
|
|
823
|
-
if (createTags) {
|
|
824
|
-
tags = publishManifests.map(
|
|
825
|
-
m => `v/${m.project.packageName}@${m.newVersion}`,
|
|
826
|
-
);
|
|
827
|
-
await exec(
|
|
828
|
-
tags.map(tag => `git tag -a ${tag} -m "Bump type ${tag}"`).join(' && '),
|
|
829
|
-
{ cwd },
|
|
830
|
-
);
|
|
831
|
-
}
|
|
832
|
-
return { effects: [...tags, branchName], branchName };
|
|
882
|
+
return { effects: [branchName], branchName };
|
|
833
883
|
}
|
|
834
884
|
|
|
835
885
|
|
|
@@ -859,16 +909,17 @@ async function push({ refs, cwd, repoUrl }) {
|
|
|
859
909
|
|
|
860
910
|
|
|
861
911
|
|
|
912
|
+
|
|
862
913
|
const pushToRemote = async (options) => {
|
|
863
914
|
const {
|
|
864
915
|
sessionId,
|
|
865
916
|
changedFiles,
|
|
866
917
|
cwd,
|
|
867
|
-
publishManifests,
|
|
868
918
|
bumpPolicy,
|
|
869
919
|
skipCommit,
|
|
870
920
|
skipPush,
|
|
871
921
|
repoUrl,
|
|
922
|
+
branchPrefix = 'release',
|
|
872
923
|
} = options;
|
|
873
924
|
if (skipCommit) {
|
|
874
925
|
return;
|
|
@@ -882,7 +933,7 @@ const pushToRemote = async (options) => {
|
|
|
882
933
|
branchName = await getCurrentBranchName();
|
|
883
934
|
} else {
|
|
884
935
|
const date = dayjs().format('YYYYMMDD');
|
|
885
|
-
branchName =
|
|
936
|
+
branchName = `${branchPrefix}/${date}-${sessionId}`;
|
|
886
937
|
await exec(`git checkout -b ${branchName}`, { cwd });
|
|
887
938
|
}
|
|
888
939
|
const isTestPublish = [BumpType.ALPHA, BumpType.BETA].includes(
|
|
@@ -891,13 +942,9 @@ const pushToRemote = async (options) => {
|
|
|
891
942
|
|
|
892
943
|
// 4. 创建并推送发布分支
|
|
893
944
|
const { effects } = await commitChanges({
|
|
894
|
-
sessionId,
|
|
895
945
|
files: changedFiles,
|
|
896
946
|
cwd,
|
|
897
|
-
publishManifests,
|
|
898
947
|
branchName,
|
|
899
|
-
// 只有 alpha、beta 需要创建 tag,正式发布会在 .github/workflows/common-pr-checks.yml 创建并发布tag
|
|
900
|
-
createTags: isTestPublish,
|
|
901
948
|
});
|
|
902
949
|
if (skipPush) {
|
|
903
950
|
return;
|
|
@@ -1034,7 +1081,7 @@ const lookupOnly = (packageName) => {
|
|
|
1034
1081
|
return projects[0];
|
|
1035
1082
|
};
|
|
1036
1083
|
|
|
1037
|
-
function _optionalChain$
|
|
1084
|
+
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1038
1085
|
|
|
1039
1086
|
|
|
1040
1087
|
|
|
@@ -1088,7 +1135,7 @@ const retrievePackages = (
|
|
|
1088
1135
|
|
|
1089
1136
|
const validateAndGetPackages = (options) => {
|
|
1090
1137
|
const retrievePatterns = Object.values(RetrievePattern);
|
|
1091
|
-
if (retrievePatterns.every(pattern => (_optionalChain$
|
|
1138
|
+
if (retrievePatterns.every(pattern => (_optionalChain$2([options, 'access', _ => _[pattern], 'optionalAccess', _2 => _2.length]) || 0) <= 0)) {
|
|
1092
1139
|
throw new Error('No packages to publish');
|
|
1093
1140
|
}
|
|
1094
1141
|
const res = retrievePatterns.reduce((acc, pattern) => {
|
|
@@ -1114,8 +1161,11 @@ const validateAndGetPackages = (options) => {
|
|
|
1114
1161
|
return result;
|
|
1115
1162
|
};
|
|
1116
1163
|
|
|
1117
|
-
// Copyright (c) 2025 coze-dev
|
|
1118
|
-
|
|
1164
|
+
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// Copyright (c) 2025 coze-dev
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
|
|
1119
1169
|
|
|
1120
1170
|
|
|
1121
1171
|
|
|
@@ -1123,20 +1173,33 @@ const validateAndGetPackages = (options) => {
|
|
|
1123
1173
|
const confirmForPublish = async (
|
|
1124
1174
|
publishManifest,
|
|
1125
1175
|
dryRun,
|
|
1176
|
+
options,
|
|
1126
1177
|
) => {
|
|
1127
|
-
|
|
1178
|
+
logger.info(chalk.gray('Will publish the following packages:'), false);
|
|
1128
1179
|
publishManifest.forEach(manifest => {
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1180
|
+
const versionChange = `${manifest.currentVersion} -> ${chalk.bold(manifest.newVersion)}`;
|
|
1181
|
+
const msg = `${manifest.project.packageName}: ${chalk.bgGreen(versionChange)}`;
|
|
1182
|
+
logger.info(`- ${msg}`, false);
|
|
1131
1183
|
});
|
|
1184
|
+
|
|
1185
|
+
// Release 模式的额外提示
|
|
1186
|
+
if (_optionalChain$1([options, 'optionalAccess', _ => _.isReleaseMode])) {
|
|
1187
|
+
logger.info('', false);
|
|
1188
|
+
logger.warn(chalk.yellow.bold('⚠️ Release Mode Enabled:'), false);
|
|
1189
|
+
const registryMsg = ` Packages will be published directly to: ${chalk.bold(options.registry || 'default registry')}`;
|
|
1190
|
+
logger.warn(chalk.yellow(registryMsg), false);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1132
1193
|
if (dryRun) {
|
|
1133
1194
|
return false;
|
|
1134
1195
|
}
|
|
1135
1196
|
|
|
1136
|
-
|
|
1197
|
+
logger.info('', false);
|
|
1137
1198
|
try {
|
|
1138
1199
|
const result = await prompts.confirm({
|
|
1139
|
-
message: '
|
|
1200
|
+
message: _optionalChain$1([options, 'optionalAccess', _2 => _2.isReleaseMode])
|
|
1201
|
+
? 'Are you sure to publish directly?'
|
|
1202
|
+
: 'Are you sure to publish?',
|
|
1140
1203
|
default: true,
|
|
1141
1204
|
});
|
|
1142
1205
|
return result;
|
|
@@ -1500,7 +1563,10 @@ const publish = async (options) => {
|
|
|
1500
1563
|
const sessionId = randomHash(6);
|
|
1501
1564
|
const rushConfiguration = getRushConfiguration$1();
|
|
1502
1565
|
const rushFolder = rushConfiguration.rushJsonFolder;
|
|
1503
|
-
if (
|
|
1566
|
+
if (
|
|
1567
|
+
process.env.SKIP_UNCOMMITTED_CHECK !== 'true' &&
|
|
1568
|
+
options.release !== true
|
|
1569
|
+
) {
|
|
1504
1570
|
await ensureNotUncommittedChanges();
|
|
1505
1571
|
}
|
|
1506
1572
|
|
|
@@ -1536,6 +1602,10 @@ const publish = async (options) => {
|
|
|
1536
1602
|
const continuePublish = await confirmForPublish(
|
|
1537
1603
|
publishManifests,
|
|
1538
1604
|
!!options.dryRun,
|
|
1605
|
+
{
|
|
1606
|
+
isReleaseMode: !!options.release,
|
|
1607
|
+
registry: options.registry || DEFAULT_NPM_REGISTRY,
|
|
1608
|
+
},
|
|
1539
1609
|
);
|
|
1540
1610
|
|
|
1541
1611
|
if (!continuePublish) {
|
|
@@ -1551,17 +1621,46 @@ const publish = async (options) => {
|
|
|
1551
1621
|
await Promise.all(postHandles.map(handle => handle(publishManifests)))
|
|
1552
1622
|
).flat();
|
|
1553
1623
|
|
|
1554
|
-
// 4. 创建并推送发布分支
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1624
|
+
// 4. 创建并推送发布分支 或 直接发布
|
|
1625
|
+
let shouldRelease = false;
|
|
1626
|
+
if (options.release) {
|
|
1627
|
+
// 验证 release 模式的前置条件
|
|
1628
|
+
if (isBetaPublish === false) {
|
|
1629
|
+
logger.error(
|
|
1630
|
+
'Direct release (--release) is only allowed for alpha or beta versions.',
|
|
1631
|
+
);
|
|
1632
|
+
logger.error(`Current bump type is: ${bumpPolicy}`);
|
|
1633
|
+
logger.warn('Falling back to normal publish mode...');
|
|
1634
|
+
} else {
|
|
1635
|
+
shouldRelease = true;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
if (shouldRelease) {
|
|
1640
|
+
// Release 模式:直接发布
|
|
1641
|
+
logger.info('Running in direct release mode...');
|
|
1642
|
+
logger.info('Starting package release...');
|
|
1643
|
+
const registry = options.registry || DEFAULT_NPM_REGISTRY;
|
|
1644
|
+
// 将 PublishManifest[] 转换为 PackageToPublish[]
|
|
1645
|
+
const packages = publishManifests.map(manifest => ({
|
|
1646
|
+
packageName: manifest.project.packageName,
|
|
1647
|
+
version: manifest.newVersion,
|
|
1648
|
+
}));
|
|
1649
|
+
await release({ dryRun: !!options.dryRun, registry, packages });
|
|
1650
|
+
} else {
|
|
1651
|
+
// 普通模式:创建并推送发布分支
|
|
1652
|
+
await pushToRemote({
|
|
1653
|
+
bumpPolicy: bumpPolicy ,
|
|
1654
|
+
sessionId,
|
|
1655
|
+
changedFiles,
|
|
1656
|
+
cwd: rushFolder,
|
|
1657
|
+
skipCommit: !!options.skipCommit,
|
|
1658
|
+
skipPush: !!options.skipPush,
|
|
1659
|
+
repoUrl: options.repoUrl,
|
|
1660
|
+
branchPrefix: options.branchPrefix,
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1565
1664
|
logger.success('Publish success.');
|
|
1566
1665
|
};
|
|
1567
1666
|
|
|
@@ -1592,6 +1691,21 @@ const installAction$1 = (program) => {
|
|
|
1592
1691
|
'Git repository URL (e.g. git@github.com:coze-dev/coze-js.git)',
|
|
1593
1692
|
undefined,
|
|
1594
1693
|
)
|
|
1694
|
+
.option(
|
|
1695
|
+
'--branch-prefix <prefix>',
|
|
1696
|
+
`Git branch name prefix (default: ${DEFAULT_BRANCH_PREFIX})`,
|
|
1697
|
+
DEFAULT_BRANCH_PREFIX,
|
|
1698
|
+
)
|
|
1699
|
+
.option(
|
|
1700
|
+
'-l, --release',
|
|
1701
|
+
'Directly publish packages (only for alpha/beta versions)',
|
|
1702
|
+
false,
|
|
1703
|
+
)
|
|
1704
|
+
.option(
|
|
1705
|
+
'--registry <url>',
|
|
1706
|
+
`NPM registry URL (default: ${DEFAULT_NPM_REGISTRY})`,
|
|
1707
|
+
DEFAULT_NPM_REGISTRY,
|
|
1708
|
+
)
|
|
1595
1709
|
.action(async (options) => {
|
|
1596
1710
|
try {
|
|
1597
1711
|
const repoUrl = options.repoUrl || (await getCurrentOrigin());
|
|
@@ -1599,8 +1713,9 @@ const installAction$1 = (program) => {
|
|
|
1599
1713
|
throw new Error('Git repository URL is required');
|
|
1600
1714
|
}
|
|
1601
1715
|
if (!GIT_REPO_URL_REGEX.test(repoUrl)) {
|
|
1716
|
+
const expectedFormat = 'git@github.com:${org}/${repo}.git';
|
|
1602
1717
|
throw new Error(
|
|
1603
|
-
`Invalid git repository URL: ${repoUrl}, it should
|
|
1718
|
+
`Invalid git repository URL: ${repoUrl}, it should follow the format: ${expectedFormat}`,
|
|
1604
1719
|
);
|
|
1605
1720
|
}
|
|
1606
1721
|
const normalizeOptions = {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface IPublishPluginConfig {
|
|
2
|
+
branchPrefix?: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Read plugin configuration from common/config/rush-plugins/@coze-arch/rush-publish-plugin.json
|
|
6
|
+
* @returns Plugin configuration object
|
|
7
|
+
*/
|
|
8
|
+
export declare function getPluginConfig(): IPublishPluginConfig;
|
package/lib/utils/git.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ export declare const getChangedFilesFromCached: () => Promise<string[]>;
|
|
|
4
4
|
* @returns string
|
|
5
5
|
*/
|
|
6
6
|
export declare const getCurrentBranchName: () => Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* 获取当前 commit hash
|
|
9
|
+
* @returns commit hash
|
|
10
|
+
*/
|
|
11
|
+
export declare const getCurrentCommitHash: () => Promise<string>;
|
|
7
12
|
export declare const isMainBranch: () => Promise<boolean>;
|
|
8
13
|
export declare const getChangedFiles: () => Promise<string[]>;
|
|
9
14
|
/**
|