@backstage/plugin-scaffolder-backend 1.8.1-next.1 → 1.9.0-next.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 1.9.0-next.3
4
+
5
+ ### Minor Changes
6
+
7
+ - 0053d07bee: Update the `github:publish` action to allow passing wether to dismiss stale reviews on the protected default branch.
8
+
9
+ ### Patch Changes
10
+
11
+ - 935b66a646: Change step output template examples to use square bracket syntax.
12
+ - b05dcd5530: Move the `zod` dependency to a version that does not collide with other libraries
13
+ - 309f2daca4: Updated dependency `esbuild` to `^0.16.0`.
14
+ - Updated dependencies
15
+ - @backstage/plugin-catalog-backend@1.6.0-next.3
16
+ - @backstage/backend-tasks@0.4.0-next.3
17
+ - @backstage/backend-common@0.17.0-next.3
18
+ - @backstage/backend-plugin-api@0.2.0-next.3
19
+ - @backstage/catalog-client@1.2.0-next.1
20
+ - @backstage/catalog-model@1.1.4-next.1
21
+ - @backstage/config@1.0.5-next.1
22
+ - @backstage/errors@1.1.4-next.1
23
+ - @backstage/integration@1.4.1-next.1
24
+ - @backstage/types@1.0.2-next.1
25
+ - @backstage/plugin-auth-node@0.2.8-next.3
26
+ - @backstage/plugin-catalog-node@1.3.0-next.3
27
+ - @backstage/plugin-scaffolder-common@1.2.3-next.1
28
+
29
+ ## 1.9.0-next.2
30
+
31
+ ### Minor Changes
32
+
33
+ - b32005e98a: Deprecated the `taskWorkers` option in RouterOptions in favor of `concurrentTasksLimit` which sets the limit of concurrent tasks in a single TaskWorker
34
+
35
+ TaskWorker can now run multiple (defaults to 10) tasks concurrently using the `concurrentTasksLimit` option available in both `RouterOptions` and `CreateWorkerOptions`.
36
+
37
+ To use the option to create a TaskWorker:
38
+
39
+ ```diff
40
+ const worker = await TaskWorker.create({
41
+ taskBroker,
42
+ actionRegistry,
43
+ integrations,
44
+ logger,
45
+ workingDirectory,
46
+ additionalTemplateFilters,
47
+ + concurrentTasksLimit: 10 // (1 to Infinity)
48
+ });
49
+ ```
50
+
51
+ ### Patch Changes
52
+
53
+ - 884d749b14: Refactored to use `coreServices` from `@backstage/backend-plugin-api`.
54
+ - Updated dependencies
55
+ - @backstage/plugin-catalog-backend@1.6.0-next.2
56
+ - @backstage/plugin-catalog-node@1.3.0-next.2
57
+ - @backstage/backend-common@0.17.0-next.2
58
+ - @backstage/backend-plugin-api@0.2.0-next.2
59
+ - @backstage/backend-tasks@0.4.0-next.2
60
+ - @backstage/plugin-auth-node@0.2.8-next.2
61
+ - @backstage/catalog-client@1.2.0-next.1
62
+ - @backstage/catalog-model@1.1.4-next.1
63
+ - @backstage/config@1.0.5-next.1
64
+ - @backstage/errors@1.1.4-next.1
65
+ - @backstage/integration@1.4.1-next.1
66
+ - @backstage/types@1.0.2-next.1
67
+ - @backstage/plugin-scaffolder-common@1.2.3-next.1
68
+
3
69
  ## 1.8.1-next.1
4
70
 
5
71
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "1.8.1-next.1",
3
+ "version": "1.9.0-next.3",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -335,6 +335,7 @@ gitCommitMessage?: string | undefined;
335
335
  gitAuthorName?: string | undefined;
336
336
  gitAuthorEmail?: string | undefined;
337
337
  requireCodeOwnerReviews?: boolean | undefined;
338
+ dismissStaleReviews?: boolean | undefined;
338
339
  bypassPullRequestAllowances?: {
339
340
  users?: string[];
340
341
  teams?: string[];
@@ -508,6 +509,7 @@ teams?: string[];
508
509
  apps?: string[];
509
510
  } | undefined;
510
511
  requireCodeOwnerReviews?: boolean | undefined;
512
+ dismissStaleReviews?: boolean | undefined;
511
513
  requiredStatusCheckContexts?: string[] | undefined;
512
514
  requireBranchesToBeUpToDate?: boolean | undefined;
513
515
  repoVisibility?: "internal" | "private" | "public" | undefined;
@@ -611,6 +613,19 @@ export declare type CreateWorkerOptions = {
611
613
  workingDirectory: string;
612
614
  logger: Logger;
613
615
  additionalTemplateFilters?: Record<string, TemplateFilter>;
616
+ /**
617
+ * The number of tasks that can be executed at the same time by the worker
618
+ * @defaultValue 10
619
+ * @example
620
+ * ```
621
+ * {
622
+ * concurrentTasksLimit: 1,
623
+ * // OR
624
+ * concurrentTasksLimit: Infinity
625
+ * }
626
+ * ```
627
+ */
628
+ concurrentTasksLimit?: number;
614
629
  additionalTemplateGlobals?: Record<string, TemplateGlobal>;
615
630
  };
616
631
 
@@ -732,7 +747,16 @@ export declare interface RouterOptions {
732
747
  catalogClient: CatalogApi;
733
748
  scheduler?: PluginTaskScheduler;
734
749
  actions?: TemplateAction<any>[];
750
+ /**
751
+ * @deprecated taskWorkers is deprecated in favor of concurrentTasksLimit option with a single TaskWorker
752
+ * @defaultValue 1
753
+ */
735
754
  taskWorkers?: number;
755
+ /**
756
+ * Sets the number of concurrent tasks that can be run at any given time on the TaskWorker
757
+ * @defaultValue 10
758
+ */
759
+ concurrentTasksLimit?: number;
736
760
  taskBroker?: TaskBroker;
737
761
  additionalTemplateFilters?: Record<string, TemplateFilter>;
738
762
  additionalTemplateGlobals?: Record<string, TemplateGlobal>;
@@ -1015,8 +1039,10 @@ export declare type TaskStoreShutDownTaskOptions = {
1015
1039
  export declare class TaskWorker {
1016
1040
  private readonly options;
1017
1041
  private constructor();
1042
+ private taskQueue;
1018
1043
  static create(options: CreateWorkerOptions): Promise<TaskWorker>;
1019
1044
  start(): void;
1045
+ protected onReadyToClaimTask(): Promise<void>;
1020
1046
  runOneTask(task: TaskContext): Promise<void>;
1021
1047
  }
1022
1048
 
@@ -335,6 +335,7 @@ gitCommitMessage?: string | undefined;
335
335
  gitAuthorName?: string | undefined;
336
336
  gitAuthorEmail?: string | undefined;
337
337
  requireCodeOwnerReviews?: boolean | undefined;
338
+ dismissStaleReviews?: boolean | undefined;
338
339
  bypassPullRequestAllowances?: {
339
340
  users?: string[];
340
341
  teams?: string[];
@@ -508,6 +509,7 @@ teams?: string[];
508
509
  apps?: string[];
509
510
  } | undefined;
510
511
  requireCodeOwnerReviews?: boolean | undefined;
512
+ dismissStaleReviews?: boolean | undefined;
511
513
  requiredStatusCheckContexts?: string[] | undefined;
512
514
  requireBranchesToBeUpToDate?: boolean | undefined;
513
515
  repoVisibility?: "internal" | "private" | "public" | undefined;
@@ -611,6 +613,19 @@ export declare type CreateWorkerOptions = {
611
613
  workingDirectory: string;
612
614
  logger: Logger;
613
615
  additionalTemplateFilters?: Record<string, TemplateFilter>;
616
+ /**
617
+ * The number of tasks that can be executed at the same time by the worker
618
+ * @defaultValue 10
619
+ * @example
620
+ * ```
621
+ * {
622
+ * concurrentTasksLimit: 1,
623
+ * // OR
624
+ * concurrentTasksLimit: Infinity
625
+ * }
626
+ * ```
627
+ */
628
+ concurrentTasksLimit?: number;
614
629
  additionalTemplateGlobals?: Record<string, TemplateGlobal>;
615
630
  };
616
631
 
@@ -732,7 +747,16 @@ export declare interface RouterOptions {
732
747
  catalogClient: CatalogApi;
733
748
  scheduler?: PluginTaskScheduler;
734
749
  actions?: TemplateAction<any>[];
750
+ /**
751
+ * @deprecated taskWorkers is deprecated in favor of concurrentTasksLimit option with a single TaskWorker
752
+ * @defaultValue 1
753
+ */
735
754
  taskWorkers?: number;
755
+ /**
756
+ * Sets the number of concurrent tasks that can be run at any given time on the TaskWorker
757
+ * @defaultValue 10
758
+ */
759
+ concurrentTasksLimit?: number;
736
760
  taskBroker?: TaskBroker;
737
761
  additionalTemplateFilters?: Record<string, TemplateFilter>;
738
762
  additionalTemplateGlobals?: Record<string, TemplateGlobal>;
@@ -997,8 +1021,10 @@ export declare type TaskStoreShutDownTaskOptions = {
997
1021
  export declare class TaskWorker {
998
1022
  private readonly options;
999
1023
  private constructor();
1024
+ private taskQueue;
1000
1025
  static create(options: CreateWorkerOptions): Promise<TaskWorker>;
1001
1026
  start(): void;
1027
+ protected onReadyToClaimTask(): Promise<void>;
1002
1028
  runOneTask(task: TaskContext): Promise<void>;
1003
1029
  }
1004
1030
 
package/dist/index.cjs.js CHANGED
@@ -26,6 +26,7 @@ var node = require('@gitbeaker/node');
26
26
  var uuid = require('uuid');
27
27
  var luxon = require('luxon');
28
28
  var ObservableImpl = require('zen-observable');
29
+ var PQueue = require('p-queue');
29
30
  var winston = require('winston');
30
31
  var nunjucks = require('nunjucks');
31
32
  var lodash = require('lodash');
@@ -69,6 +70,7 @@ var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
69
70
  var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
70
71
  var limiterFactory__default = /*#__PURE__*/_interopDefaultLegacy(limiterFactory);
71
72
  var ObservableImpl__default = /*#__PURE__*/_interopDefaultLegacy(ObservableImpl);
73
+ var PQueue__default = /*#__PURE__*/_interopDefaultLegacy(PQueue);
72
74
  var winston__namespace = /*#__PURE__*/_interopNamespace(winston);
73
75
  var nunjucks__default = /*#__PURE__*/_interopDefaultLegacy(nunjucks);
74
76
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
@@ -997,7 +999,8 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
997
999
  requiredStatusCheckContexts = [],
998
1000
  requireBranchesToBeUpToDate = true,
999
1001
  defaultBranch = "master",
1000
- enforceAdmins = true
1002
+ enforceAdmins = true,
1003
+ dismissStaleReviews = false
1001
1004
  }) => {
1002
1005
  const tryOnce = async () => {
1003
1006
  try {
@@ -1017,7 +1020,8 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
1017
1020
  required_pull_request_reviews: {
1018
1021
  required_approving_review_count: 1,
1019
1022
  require_code_owner_reviews: requireCodeOwnerReviews,
1020
- bypass_pull_request_allowances: bypassPullRequestAllowances
1023
+ bypass_pull_request_allowances: bypassPullRequestAllowances,
1024
+ dismiss_stale_reviews: dismissStaleReviews
1021
1025
  }
1022
1026
  });
1023
1027
  } catch (e) {
@@ -1184,7 +1188,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
1184
1188
  }
1185
1189
  return newRepo;
1186
1190
  }
1187
- async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, bypassPullRequestAllowances, requiredStatusCheckContexts, requireBranchesToBeUpToDate, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail) {
1191
+ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, bypassPullRequestAllowances, requiredStatusCheckContexts, requireBranchesToBeUpToDate, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail, dismissStaleReviews) {
1188
1192
  const gitAuthorInfo = {
1189
1193
  name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
1190
1194
  email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
@@ -1214,7 +1218,8 @@ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, source
1214
1218
  requireCodeOwnerReviews,
1215
1219
  requiredStatusCheckContexts,
1216
1220
  requireBranchesToBeUpToDate,
1217
- enforceAdmins: protectEnforceAdmins
1221
+ enforceAdmins: protectEnforceAdmins,
1222
+ dismissStaleReviews
1218
1223
  });
1219
1224
  } catch (e) {
1220
1225
  errors.assertError(e);
@@ -1396,6 +1401,11 @@ const requireCodeOwnerReviews = {
1396
1401
  description: "Require an approved review in PR including files with a designated Code Owner",
1397
1402
  type: "boolean"
1398
1403
  };
1404
+ const dismissStaleReviews = {
1405
+ title: "Dismiss Stale Reviews",
1406
+ description: "New reviewable commits pushed to a matching branch will dismiss pull request review approvals.",
1407
+ type: "boolean"
1408
+ };
1399
1409
  const requiredStatusCheckContexts = {
1400
1410
  title: "Required Status Check Contexts",
1401
1411
  description: "The list of status checks to require in order to merge into this branch",
@@ -1646,6 +1656,7 @@ function createGithubRepoPushAction(options) {
1646
1656
  properties: {
1647
1657
  repoUrl: repoUrl,
1648
1658
  requireCodeOwnerReviews: requireCodeOwnerReviews,
1659
+ dismissStaleReviews: dismissStaleReviews,
1649
1660
  requiredStatusCheckContexts: requiredStatusCheckContexts,
1650
1661
  bypassPullRequestAllowances: bypassPullRequestAllowances,
1651
1662
  requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
@@ -1677,6 +1688,7 @@ function createGithubRepoPushAction(options) {
1677
1688
  gitAuthorName,
1678
1689
  gitAuthorEmail,
1679
1690
  requireCodeOwnerReviews = false,
1691
+ dismissStaleReviews = false,
1680
1692
  bypassPullRequestAllowances,
1681
1693
  requiredStatusCheckContexts = [],
1682
1694
  requireBranchesToBeUpToDate = true,
@@ -1715,7 +1727,8 @@ function createGithubRepoPushAction(options) {
1715
1727
  ctx.logger,
1716
1728
  gitCommitMessage,
1717
1729
  gitAuthorName,
1718
- gitAuthorEmail
1730
+ gitAuthorEmail,
1731
+ dismissStaleReviews
1719
1732
  );
1720
1733
  ctx.output("remoteUrl", remoteUrl);
1721
1734
  ctx.output("repoContentsUrl", repoContentsUrl);
@@ -2929,6 +2942,7 @@ function createPublishGithubAction(options) {
2929
2942
  access: access,
2930
2943
  bypassPullRequestAllowances: bypassPullRequestAllowances,
2931
2944
  requireCodeOwnerReviews: requireCodeOwnerReviews,
2945
+ dismissStaleReviews: dismissStaleReviews,
2932
2946
  requiredStatusCheckContexts: requiredStatusCheckContexts,
2933
2947
  requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
2934
2948
  repoVisibility: repoVisibility,
@@ -2964,6 +2978,7 @@ function createPublishGithubAction(options) {
2964
2978
  homepage,
2965
2979
  access,
2966
2980
  requireCodeOwnerReviews = false,
2981
+ dismissStaleReviews = false,
2967
2982
  bypassPullRequestAllowances,
2968
2983
  requiredStatusCheckContexts = [],
2969
2984
  requireBranchesToBeUpToDate = true,
@@ -3032,7 +3047,8 @@ function createPublishGithubAction(options) {
3032
3047
  ctx.logger,
3033
3048
  gitCommitMessage,
3034
3049
  gitAuthorName,
3035
- gitAuthorEmail
3050
+ gitAuthorEmail,
3051
+ dismissStaleReviews
3036
3052
  );
3037
3053
  ctx.output("remoteUrl", remoteUrl);
3038
3054
  ctx.output("repoContentsUrl", repoContentsUrl);
@@ -4585,6 +4601,9 @@ function scaffoldingTracker() {
4585
4601
  class TaskWorker {
4586
4602
  constructor(options) {
4587
4603
  this.options = options;
4604
+ this.taskQueue = new PQueue__default["default"]({
4605
+ concurrency: this.options.concurrentTasksLimit
4606
+ });
4588
4607
  }
4589
4608
  static async create(options) {
4590
4609
  const {
@@ -4594,6 +4613,7 @@ class TaskWorker {
4594
4613
  integrations,
4595
4614
  workingDirectory,
4596
4615
  additionalTemplateFilters,
4616
+ concurrentTasksLimit = 10,
4597
4617
  additionalTemplateGlobals
4598
4618
  } = options;
4599
4619
  const workflowRunner = new NunjucksWorkflowRunner({
@@ -4606,17 +4626,29 @@ class TaskWorker {
4606
4626
  });
4607
4627
  return new TaskWorker({
4608
4628
  taskBroker,
4609
- runners: { workflowRunner }
4629
+ runners: { workflowRunner },
4630
+ concurrentTasksLimit
4610
4631
  });
4611
4632
  }
4612
4633
  start() {
4613
4634
  (async () => {
4614
4635
  for (; ; ) {
4636
+ await this.onReadyToClaimTask();
4615
4637
  const task = await this.options.taskBroker.claim();
4616
- await this.runOneTask(task);
4638
+ this.taskQueue.add(() => this.runOneTask(task));
4617
4639
  }
4618
4640
  })();
4619
4641
  }
4642
+ onReadyToClaimTask() {
4643
+ if (this.taskQueue.pending < this.options.concurrentTasksLimit) {
4644
+ return Promise.resolve();
4645
+ }
4646
+ return new Promise((resolve) => {
4647
+ this.taskQueue.once("next", () => {
4648
+ resolve();
4649
+ });
4650
+ });
4651
+ }
4620
4652
  async runOneTask(task) {
4621
4653
  try {
4622
4654
  if (task.spec.apiVersion !== "scaffolder.backstage.io/v1beta3") {
@@ -4835,6 +4867,7 @@ async function createRouter(options) {
4835
4867
  catalogClient,
4836
4868
  actions,
4837
4869
  taskWorkers,
4870
+ concurrentTasksLimit,
4838
4871
  scheduler,
4839
4872
  additionalTemplateFilters,
4840
4873
  additionalTemplateGlobals
@@ -4868,7 +4901,7 @@ async function createRouter(options) {
4868
4901
  }
4869
4902
  const actionRegistry = new TemplateActionRegistry();
4870
4903
  const workers = [];
4871
- for (let i = 0; i < (taskWorkers || 3); i++) {
4904
+ for (let i = 0; i < (taskWorkers || 1); i++) {
4872
4905
  const worker = await TaskWorker.create({
4873
4906
  taskBroker,
4874
4907
  actionRegistry,
@@ -4876,7 +4909,8 @@ async function createRouter(options) {
4876
4909
  logger,
4877
4910
  workingDirectory,
4878
4911
  additionalTemplateFilters,
4879
- additionalTemplateGlobals
4912
+ additionalTemplateGlobals,
4913
+ concurrentTasksLimit
4880
4914
  });
4881
4915
  workers.push(worker);
4882
4916
  }
@@ -5273,12 +5307,12 @@ const scaffolderPlugin = backendPluginApi.createBackendPlugin({
5273
5307
  );
5274
5308
  env.registerInit({
5275
5309
  deps: {
5276
- logger: backendPluginApi.loggerServiceRef,
5277
- config: backendPluginApi.configServiceRef,
5278
- reader: backendPluginApi.urlReaderServiceRef,
5279
- permissions: backendPluginApi.permissionsServiceRef,
5280
- database: backendPluginApi.databaseServiceRef,
5281
- httpRouter: backendPluginApi.httpRouterServiceRef,
5310
+ logger: backendPluginApi.coreServices.logger,
5311
+ config: backendPluginApi.coreServices.config,
5312
+ reader: backendPluginApi.coreServices.urlReader,
5313
+ permissions: backendPluginApi.coreServices.permissions,
5314
+ database: backendPluginApi.coreServices.database,
5315
+ httpRouter: backendPluginApi.coreServices.httpRouter,
5282
5316
  catalogClient: pluginCatalogNode.catalogServiceRef
5283
5317
  },
5284
5318
  async init({