@coze-arch/rush-publish-plugin 0.0.5-alpha.5049d2 → 0.0.5-alpha.e4e8c6

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 CHANGED
@@ -159,6 +159,14 @@
159
159
  "shortName": "-r",
160
160
  "description": "NPM registry URL (default: https://registry.npmjs.org)",
161
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
162
170
  }
163
171
  ]
164
172
  }
@@ -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({ sessionId, files, cwd, publishManifests, branchName, createTags, }: CommitChangesOptions): Promise<{
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;
@@ -4,6 +4,7 @@ export interface ReleaseOptions {
4
4
  dryRun?: boolean;
5
5
  registry: string;
6
6
  packages?: PackageToPublish[];
7
+ allowBranches?: string[];
7
8
  }
8
9
  export interface PackageToPublish {
9
10
  packageName: string;
@@ -6,3 +6,7 @@ export declare const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
6
6
  * 默认的 Git 分支名前缀
7
7
  */
8
8
  export declare const DEFAULT_BRANCH_PREFIX = "bump";
9
+ /**
10
+ * 默认允许发布正式版本的分支列表
11
+ */
12
+ export declare const DEFAULT_ALLOW_BRANCHES: string[];
package/lib/index.js CHANGED
@@ -158,6 +158,11 @@ const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
158
158
  */
159
159
  const DEFAULT_BRANCH_PREFIX = 'bump';
160
160
 
161
+ /**
162
+ * 默认允许发布正式版本的分支列表
163
+ */
164
+ const DEFAULT_ALLOW_BRANCHES = ['main', 'feat/auto-publish'];
165
+
161
166
  // Copyright (c) 2025 coze-dev
162
167
  // SPDX-License-Identifier: MIT
163
168
 
@@ -471,13 +476,16 @@ const calReleasePlan = (releaseManifests) => {
471
476
  const checkReleasePlan = (
472
477
  releaseManifests,
473
478
  branchName,
479
+ allowBranches = ['main', 'feat/auto-publish'],
474
480
  ) => {
475
481
  const releasePlan = calReleasePlan(releaseManifests);
476
482
  if (
477
483
  releasePlan === ReleaseType.LATEST &&
478
- !['main', 'feat/auto-publish'].includes(branchName)
484
+ !allowBranches.includes(branchName)
479
485
  ) {
480
- throw new Error('For LATEST release, should be on main branch only.');
486
+ throw new Error(
487
+ `For LATEST release, should be on one of these branches: ${allowBranches.join(', ')}. Current Branch: ${branchName}`,
488
+ );
481
489
  }
482
490
  return true;
483
491
  };
@@ -546,7 +554,12 @@ const getPackagesToPublish = async (
546
554
 
547
555
 
548
556
  async function release(options) {
549
- const { dryRun = false, registry, packages } = options;
557
+ const {
558
+ dryRun = false,
559
+ registry,
560
+ packages,
561
+ allowBranches = DEFAULT_ALLOW_BRANCHES,
562
+ } = options;
550
563
  let { commit } = options;
551
564
  const hasPassedCommit = !!options.commit;
552
565
 
@@ -582,7 +595,7 @@ async function release(options) {
582
595
  false,
583
596
  );
584
597
  const branchName = await getCurrentBranchName();
585
- checkReleasePlan(releaseManifests, branchName);
598
+ checkReleasePlan(releaseManifests, branchName, allowBranches);
586
599
 
587
600
  // 只有在指定了 commit 且与当前 HEAD 不同时才切换
588
601
  if (hasPassedCommit) {
@@ -614,6 +627,10 @@ const installAction$2 = (program) => {
614
627
  `发布到的 registry (默认: ${DEFAULT_NPM_REGISTRY})`,
615
628
  DEFAULT_NPM_REGISTRY,
616
629
  )
630
+ .option(
631
+ '--allow-branches <branches...>',
632
+ `允许发布正式版本的分支列表 (默认: ${DEFAULT_ALLOW_BRANCHES.join(', ')})`,
633
+ )
617
634
  .action(async (options) => {
618
635
  try {
619
636
  if (!process.env.NPM_AUTH_TOKEN) {
@@ -854,31 +871,15 @@ const generatePublishManifest = async (
854
871
 
855
872
 
856
873
 
857
-
858
-
859
-
860
874
  async function commitChanges({
861
- sessionId,
862
875
  files,
863
876
  cwd,
864
- publishManifests,
865
877
  branchName,
866
- createTags,
867
878
  }) {
868
879
  await exec(`git add ${files.join(' ')}`, { cwd });
869
880
  await exec(`git commit -m "chore: Publish ${branchName}" -n`, { cwd });
870
881
 
871
- let tags = [];
872
- if (createTags) {
873
- tags = publishManifests.map(
874
- m => `v/${m.project.packageName}@${m.newVersion}`,
875
- );
876
- await exec(
877
- tags.map(tag => `git tag -a ${tag} -m "Bump type ${tag}"`).join(' && '),
878
- { cwd },
879
- );
880
- }
881
- return { effects: [...tags, branchName], branchName };
882
+ return { effects: [branchName], branchName };
882
883
  }
883
884
 
884
885
 
@@ -914,7 +915,6 @@ const pushToRemote = async (options) => {
914
915
  sessionId,
915
916
  changedFiles,
916
917
  cwd,
917
- publishManifests,
918
918
  bumpPolicy,
919
919
  skipCommit,
920
920
  skipPush,
@@ -942,13 +942,9 @@ const pushToRemote = async (options) => {
942
942
 
943
943
  // 4. 创建并推送发布分支
944
944
  const { effects } = await commitChanges({
945
- sessionId,
946
945
  files: changedFiles,
947
946
  cwd,
948
- publishManifests,
949
947
  branchName,
950
- // 只有 alpha、beta 需要创建 tag,正式发布会在 .github/workflows/common-pr-checks.yml 创建并发布tag
951
- createTags: isTestPublish,
952
948
  });
953
949
  if (skipPush) {
954
950
  return;
@@ -1595,7 +1591,11 @@ const publish = async (options) => {
1595
1591
  const isBetaPublish = [BumpType.BETA, BumpType.ALPHA].includes(
1596
1592
  bumpPolicy ,
1597
1593
  );
1598
- if (isBetaPublish === false && (await isMainBranch()) === false) {
1594
+ if (
1595
+ process.env.SKIP_BRANCH_CHECK !== 'true' &&
1596
+ isBetaPublish === false &&
1597
+ (await isMainBranch()) === false
1598
+ ) {
1599
1599
  // 只允许在主分支发布
1600
1600
  logger.error(
1601
1601
  'You are not in main branch, please switch to main branch and try again.',
@@ -1654,7 +1654,6 @@ const publish = async (options) => {
1654
1654
  } else {
1655
1655
  // 普通模式:创建并推送发布分支
1656
1656
  await pushToRemote({
1657
- publishManifests,
1658
1657
  bumpPolicy: bumpPolicy ,
1659
1658
  sessionId,
1660
1659
  changedFiles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/rush-publish-plugin",
3
- "version": "0.0.5-alpha.5049d2",
3
+ "version": "0.0.5-alpha.e4e8c6",
4
4
  "description": "rush plugin to generate change log and publish packages",
5
5
  "keywords": [
6
6
  "rush",