@backstage/plugin-scaffolder-backend 1.15.2-next.2 → 1.16.1

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.
@@ -81,7 +81,7 @@ var winston__namespace = /*#__PURE__*/_interopNamespace(winston);
81
81
  var nunjucks__default = /*#__PURE__*/_interopDefaultLegacy(nunjucks);
82
82
  var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
83
83
 
84
- const examples$9 = [
84
+ const examples$b = [
85
85
  {
86
86
  description: "Register with the catalog",
87
87
  example: yaml__default["default"].stringify({
@@ -105,7 +105,7 @@ function createCatalogRegisterAction(options) {
105
105
  return pluginScaffolderNode.createTemplateAction({
106
106
  id: id$4,
107
107
  description: "Registers entities from a catalog descriptor file in the workspace into the software catalog.",
108
- examples: examples$9,
108
+ examples: examples$b,
109
109
  schema: {
110
110
  input: {
111
111
  oneOf: [
@@ -229,7 +229,7 @@ function createCatalogRegisterAction(options) {
229
229
  });
230
230
  }
231
231
 
232
- const examples$8 = [
232
+ const examples$a = [
233
233
  {
234
234
  description: "Write a catalog yaml file",
235
235
  example: yaml__namespace.stringify({
@@ -273,7 +273,7 @@ function createCatalogWriteAction() {
273
273
  )
274
274
  })
275
275
  },
276
- examples: examples$8,
276
+ examples: examples$a,
277
277
  supportsDryRun: true,
278
278
  async handler(ctx) {
279
279
  ctx.logStream.write(`Writing catalog-info.yaml`);
@@ -287,7 +287,7 @@ function createCatalogWriteAction() {
287
287
  });
288
288
  }
289
289
 
290
- const examples$7 = [
290
+ const examples$9 = [
291
291
  {
292
292
  description: "Fetch entity by reference",
293
293
  example: yaml__default["default"].stringify({
@@ -326,7 +326,7 @@ function createFetchCatalogEntityAction(options) {
326
326
  return pluginScaffolderNode.createTemplateAction({
327
327
  id: id$2,
328
328
  description: "Returns entity or entities from the catalog by entity reference(s)",
329
- examples: examples$7,
329
+ examples: examples$9,
330
330
  supportsDryRun: true,
331
331
  schema: {
332
332
  input: zod.z.object({
@@ -401,7 +401,7 @@ function createFetchCatalogEntityAction(options) {
401
401
  });
402
402
  }
403
403
 
404
- const examples$6 = [
404
+ const examples$8 = [
405
405
  {
406
406
  description: "Write a debug message",
407
407
  example: yaml__default["default"].stringify({
@@ -439,7 +439,7 @@ function createDebugLogAction() {
439
439
  return pluginScaffolderNode.createTemplateAction({
440
440
  id: id$1,
441
441
  description: "Writes a message into the log or lists all files in the workspace.",
442
- examples: examples$6,
442
+ examples: examples$8,
443
443
  schema: {
444
444
  input: {
445
445
  type: "object",
@@ -486,7 +486,7 @@ async function recursiveReadDir(dir) {
486
486
  return files.reduce((a, f) => a.concat(f), []);
487
487
  }
488
488
 
489
- const examples$5 = [
489
+ const examples$7 = [
490
490
  {
491
491
  description: "Waiting for 50 milliseconds",
492
492
  example: yaml__default["default"].stringify({
@@ -549,7 +549,7 @@ function createWaitAction(options) {
549
549
  return pluginScaffolderNode.createTemplateAction({
550
550
  id,
551
551
  description: "Waits for a certain period of time.",
552
- examples: examples$5,
552
+ examples: examples$7,
553
553
  schema: {
554
554
  input: {
555
555
  type: "object",
@@ -594,7 +594,7 @@ function createWaitAction(options) {
594
594
  });
595
595
  }
596
596
 
597
- const examples$4 = [
597
+ const examples$6 = [
598
598
  {
599
599
  description: "Downloads content and places it in the workspace.",
600
600
  example: yaml__default["default"].stringify({
@@ -633,7 +633,7 @@ function createFetchPlainAction(options) {
633
633
  const { reader, integrations } = options;
634
634
  return pluginScaffolderNode.createTemplateAction({
635
635
  id: ACTION_ID,
636
- examples: examples$4,
636
+ examples: examples$6,
637
637
  description: "Downloads content and places it in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.",
638
638
  schema: {
639
639
  input: {
@@ -670,7 +670,7 @@ function createFetchPlainAction(options) {
670
670
  });
671
671
  }
672
672
 
673
- const examples$3 = [
673
+ const examples$5 = [
674
674
  {
675
675
  description: "Downloads a file and places it in the workspace.",
676
676
  example: yaml__default["default"].stringify({
@@ -694,7 +694,7 @@ function createFetchPlainFileAction(options) {
694
694
  return pluginScaffolderNode.createTemplateAction({
695
695
  id: "fetch:plain:file",
696
696
  description: "Downloads single file and places it in the workspace.",
697
- examples: examples$3,
697
+ examples: examples$5,
698
698
  schema: {
699
699
  input: {
700
700
  type: "object",
@@ -962,7 +962,7 @@ const createDefaultFilters = ({
962
962
  };
963
963
  };
964
964
 
965
- const examples$2 = [
965
+ const examples$4 = [
966
966
  {
967
967
  description: "Downloads a skelaton directory that lives alongside the template file and fill it out with values.",
968
968
  example: yaml__default["default"].stringify({
@@ -998,7 +998,7 @@ function createFetchTemplateAction(options) {
998
998
  return pluginScaffolderNode.createTemplateAction({
999
999
  id: "fetch:template",
1000
1000
  description: "Downloads a skeleton, templates variables into file and directory names and content, and places the result in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.",
1001
- examples: examples$2,
1001
+ examples: examples$4,
1002
1002
  schema: {
1003
1003
  input: {
1004
1004
  type: "object",
@@ -1203,7 +1203,7 @@ function containsSkippedContent(localOutputPath) {
1203
1203
  return localOutputPath === "" || localOutputPath.startsWith("/") || localOutputPath.includes("//");
1204
1204
  }
1205
1205
 
1206
- const examples$1 = [
1206
+ const examples$3 = [
1207
1207
  {
1208
1208
  description: "Delete specified files",
1209
1209
  example: yaml__namespace.stringify({
@@ -1225,7 +1225,7 @@ const createFilesystemDeleteAction = () => {
1225
1225
  return pluginScaffolderNode.createTemplateAction({
1226
1226
  id: "fs:delete",
1227
1227
  description: "Deletes files and directories from the workspace",
1228
- examples: examples$1,
1228
+ examples: examples$3,
1229
1229
  schema: {
1230
1230
  input: {
1231
1231
  required: ["files"],
@@ -1262,7 +1262,7 @@ const createFilesystemDeleteAction = () => {
1262
1262
  });
1263
1263
  };
1264
1264
 
1265
- const examples = [
1265
+ const examples$2 = [
1266
1266
  {
1267
1267
  description: "Rename specified files ",
1268
1268
  example: yaml__namespace.stringify({
@@ -1288,7 +1288,7 @@ const createFilesystemRenameAction = () => {
1288
1288
  return pluginScaffolderNode.createTemplateAction({
1289
1289
  id: "fs:rename",
1290
1290
  description: "Renames files and directories within the workspace",
1291
- examples,
1291
+ examples: examples$2,
1292
1292
  schema: {
1293
1293
  input: {
1294
1294
  required: ["files"],
@@ -2170,11 +2170,60 @@ const commitHash = {
2170
2170
  type: "string"
2171
2171
  };
2172
2172
 
2173
+ const examples$1 = [
2174
+ {
2175
+ description: "Creates a GitHub repository with default configuration.",
2176
+ example: yaml__default["default"].stringify({
2177
+ steps: [
2178
+ {
2179
+ action: "github:repo:create",
2180
+ name: "Create a new GitHub repository",
2181
+ input: {
2182
+ repoUrl: "github.com?repo=repo&owner=owner"
2183
+ }
2184
+ }
2185
+ ]
2186
+ })
2187
+ },
2188
+ {
2189
+ description: "Add a description.",
2190
+ example: yaml__default["default"].stringify({
2191
+ steps: [
2192
+ {
2193
+ action: "github:repo:create",
2194
+ name: "Create a new GitHub repository with a description",
2195
+ input: {
2196
+ repoUrl: "github.com?repo=repo&owner=owner",
2197
+ description: "My new repository"
2198
+ }
2199
+ }
2200
+ ]
2201
+ })
2202
+ },
2203
+ {
2204
+ description: "Disable wiki and issues.",
2205
+ example: yaml__default["default"].stringify({
2206
+ steps: [
2207
+ {
2208
+ action: "github:repo:create",
2209
+ name: "Create a new GitHub repository without wiki and issues",
2210
+ input: {
2211
+ repoUrl: "github.com?repo=repo&owner=owner",
2212
+ hasIssues: false,
2213
+ hasWiki: false
2214
+ }
2215
+ }
2216
+ ]
2217
+ })
2218
+ }
2219
+ ];
2220
+
2173
2221
  function createGithubRepoCreateAction(options) {
2174
2222
  const { integrations, githubCredentialsProvider } = options;
2175
2223
  return pluginScaffolderNode.createTemplateAction({
2176
2224
  id: "github:repo:create",
2177
2225
  description: "Creates a GitHub repository.",
2226
+ examples: examples$1,
2178
2227
  schema: {
2179
2228
  input: {
2180
2229
  type: "object",
@@ -2281,11 +2330,59 @@ function createGithubRepoCreateAction(options) {
2281
2330
  });
2282
2331
  }
2283
2332
 
2333
+ const examples = [
2334
+ {
2335
+ description: "Setup repo with no modifications to branch protection rules",
2336
+ example: yaml__default["default"].stringify({
2337
+ steps: [
2338
+ {
2339
+ action: "github:repo:push",
2340
+ name: "Create test repo with testuser as owner.",
2341
+ input: {
2342
+ repoUrl: "github.com?repo=test&owner=testuser"
2343
+ }
2344
+ }
2345
+ ]
2346
+ })
2347
+ },
2348
+ {
2349
+ description: "Setup repo with required codeowners check",
2350
+ example: yaml__default["default"].stringify({
2351
+ steps: [
2352
+ {
2353
+ action: "github:repo:push",
2354
+ name: "Require codeowner branch protection rule",
2355
+ input: {
2356
+ repoUrl: "github.com?repo=reponame&owner=owner",
2357
+ requireCodeOwnerReviews: true
2358
+ }
2359
+ }
2360
+ ]
2361
+ })
2362
+ },
2363
+ {
2364
+ description: "Change the default required number of approvals",
2365
+ example: yaml__default["default"].stringify({
2366
+ steps: [
2367
+ {
2368
+ action: "github:repo:push",
2369
+ name: "Require two approvals before merging",
2370
+ input: {
2371
+ repoUrl: "github.com?repo=reponame&owner=owner",
2372
+ requiredApprovingReviewCount: 2
2373
+ }
2374
+ }
2375
+ ]
2376
+ })
2377
+ }
2378
+ ];
2379
+
2284
2380
  function createGithubRepoPushAction(options) {
2285
2381
  const { integrations, config, githubCredentialsProvider } = options;
2286
2382
  return pluginScaffolderNode.createTemplateAction({
2287
2383
  id: "github:repo:push",
2288
2384
  description: "Initializes a git repository of contents in workspace and publishes it to GitHub.",
2385
+ examples,
2289
2386
  schema: {
2290
2387
  input: {
2291
2388
  type: "object",
@@ -5797,7 +5894,7 @@ class NunjucksWorkflowRunner {
5797
5894
  });
5798
5895
  }
5799
5896
  async executeStep(task, step, context, renderTemplate, taskTrack, workspacePath, decision) {
5800
- var _a, _b, _c, _d, _e, _f, _g;
5897
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
5801
5898
  const stepTrack = await this.tracker.stepStart(task, step);
5802
5899
  if (task.cancelSignal.aborted) {
5803
5900
  throw new Error(`Step ${step.name} has been cancelled.`);
@@ -5872,25 +5969,58 @@ class NunjucksWorkflowRunner {
5872
5969
  }
5873
5970
  const tmpDirs = new Array();
5874
5971
  const stepOutput = {};
5875
- await action.handler({
5876
- input,
5877
- secrets: (_g = task.secrets) != null ? _g : {},
5878
- logger: taskLogger,
5879
- logStream: streamLogger,
5880
- workspacePath,
5881
- createTemporaryDirectory: async () => {
5882
- const tmpDir = await fs__default["default"].mkdtemp(`${workspacePath}_step-${step.id}-`);
5883
- tmpDirs.push(tmpDir);
5884
- return tmpDir;
5885
- },
5886
- output(name, value) {
5887
- stepOutput[name] = value;
5888
- },
5889
- templateInfo: task.spec.templateInfo,
5890
- user: task.spec.user,
5891
- isDryRun: task.isDryRun,
5892
- signal: task.cancelSignal
5893
- });
5972
+ const iterations = new Array();
5973
+ if (step.each) {
5974
+ const each = await this.render(step.each, context, renderTemplate);
5975
+ iterations.push(
5976
+ ...Object.keys(each).map((key) => {
5977
+ return { key, value: each[key] };
5978
+ })
5979
+ );
5980
+ } else {
5981
+ iterations.push({});
5982
+ }
5983
+ let actionInput = input;
5984
+ for (const iteration of iterations) {
5985
+ if (step.each) {
5986
+ taskLogger.info(`Running step each: ${iteration}`);
5987
+ const iterationContext = {
5988
+ ...context,
5989
+ each: iteration
5990
+ };
5991
+ actionInput = (_h = step.input && this.render(
5992
+ step.input,
5993
+ { ...iterationContext, secrets: (_g = task.secrets) != null ? _g : {} },
5994
+ renderTemplate
5995
+ )) != null ? _h : {};
5996
+ }
5997
+ await action.handler({
5998
+ input: actionInput,
5999
+ secrets: (_i = task.secrets) != null ? _i : {},
6000
+ logger: taskLogger,
6001
+ logStream: streamLogger,
6002
+ workspacePath,
6003
+ createTemporaryDirectory: async () => {
6004
+ const tmpDir = await fs__default["default"].mkdtemp(
6005
+ `${workspacePath}_step-${step.id}-`
6006
+ );
6007
+ tmpDirs.push(tmpDir);
6008
+ return tmpDir;
6009
+ },
6010
+ output(name, value) {
6011
+ if (step.each) {
6012
+ stepOutput[name] = stepOutput[name] || [];
6013
+ stepOutput[name].push(value);
6014
+ } else {
6015
+ stepOutput[name] = value;
6016
+ }
6017
+ },
6018
+ templateInfo: task.spec.templateInfo,
6019
+ user: task.spec.user,
6020
+ isDryRun: task.isDryRun,
6021
+ signal: task.cancelSignal
6022
+ });
6023
+ }
5894
6024
  for (const tmpDir of tmpDirs) {
5895
6025
  await fs__default["default"].remove(tmpDir);
5896
6026
  }
@@ -6371,6 +6501,7 @@ function buildDefaultIdentityClient(options) {
6371
6501
  };
6372
6502
  }
6373
6503
  async function createRouter(options) {
6504
+ var _a;
6374
6505
  const router = Router__default["default"]();
6375
6506
  router.use(express__default["default"].json({ limit: "10MB" }));
6376
6507
  const {
@@ -6381,13 +6512,13 @@ async function createRouter(options) {
6381
6512
  catalogClient,
6382
6513
  actions,
6383
6514
  taskWorkers,
6384
- concurrentTasksLimit,
6385
6515
  scheduler,
6386
6516
  additionalTemplateFilters,
6387
6517
  additionalTemplateGlobals,
6388
6518
  permissions,
6389
6519
  permissionRules
6390
6520
  } = options;
6521
+ const concurrentTasksLimit = (_a = options.concurrentTasksLimit) != null ? _a : options.config.getOptionalNumber("scaffolder.concurrentTasksLimit");
6391
6522
  const logger = parentLogger.child({ plugin: "scaffolder" });
6392
6523
  const identity = options.identity || buildDefaultIdentityClient(options);
6393
6524
  const workingDirectory = await getWorkingDirectory(config, logger);
@@ -6418,19 +6549,21 @@ async function createRouter(options) {
6418
6549
  }
6419
6550
  const actionRegistry = new TemplateActionRegistry();
6420
6551
  const workers = [];
6421
- for (let i = 0; i < (taskWorkers || 1); i++) {
6422
- const worker = await TaskWorker.create({
6423
- taskBroker,
6424
- actionRegistry,
6425
- integrations,
6426
- logger,
6427
- workingDirectory,
6428
- additionalTemplateFilters,
6429
- additionalTemplateGlobals,
6430
- concurrentTasksLimit,
6431
- permissions
6432
- });
6433
- workers.push(worker);
6552
+ if (concurrentTasksLimit !== 0) {
6553
+ for (let i = 0; i < (taskWorkers || 1); i++) {
6554
+ const worker = await TaskWorker.create({
6555
+ taskBroker,
6556
+ actionRegistry,
6557
+ integrations,
6558
+ logger,
6559
+ workingDirectory,
6560
+ additionalTemplateFilters,
6561
+ additionalTemplateGlobals,
6562
+ concurrentTasksLimit,
6563
+ permissions
6564
+ });
6565
+ workers.push(worker);
6566
+ }
6434
6567
  }
6435
6568
  const actionsToRegister = Array.isArray(actions) ? actions : createBuiltinActions({
6436
6569
  integrations,
@@ -6482,21 +6615,21 @@ async function createRouter(options) {
6482
6615
  router.get(
6483
6616
  "/v2/templates/:namespace/:kind/:name/parameter-schema",
6484
6617
  async (req, res) => {
6485
- var _a, _b;
6618
+ var _a2, _b;
6486
6619
  const userIdentity = await identity.getIdentity({
6487
6620
  request: req
6488
6621
  });
6489
6622
  const token = userIdentity == null ? void 0 : userIdentity.token;
6490
6623
  const template = await authorizeTemplate(req.params, token);
6491
- const parameters = [(_a = template.spec.parameters) != null ? _a : []].flat();
6624
+ const parameters = [(_a2 = template.spec.parameters) != null ? _a2 : []].flat();
6492
6625
  res.json({
6493
6626
  title: (_b = template.metadata.title) != null ? _b : template.metadata.name,
6494
6627
  description: template.metadata.description,
6495
6628
  "ui:options": template.metadata["ui:options"],
6496
6629
  steps: parameters.map((schema) => {
6497
- var _a2;
6630
+ var _a3;
6498
6631
  return {
6499
- title: (_a2 = schema.title) != null ? _a2 : "Please enter the following information",
6632
+ title: (_a3 = schema.title) != null ? _a3 : "Please enter the following information",
6500
6633
  description: schema.description,
6501
6634
  schema
6502
6635
  };
@@ -6514,7 +6647,7 @@ async function createRouter(options) {
6514
6647
  });
6515
6648
  res.json(actionsList);
6516
6649
  }).post("/v2/tasks", async (req, res) => {
6517
- var _a, _b;
6650
+ var _a2, _b;
6518
6651
  const templateRef = req.body.templateRef;
6519
6652
  const { kind, namespace, name } = catalogModel.parseEntityRef(templateRef, {
6520
6653
  defaultKind: "template"
@@ -6535,7 +6668,7 @@ async function createRouter(options) {
6535
6668
  { kind, namespace, name },
6536
6669
  token
6537
6670
  );
6538
- for (const parameters of [(_a = template.spec.parameters) != null ? _a : []].flat()) {
6671
+ for (const parameters of [(_a2 = template.spec.parameters) != null ? _a2 : []].flat()) {
6539
6672
  const result2 = jsonschema.validate(values, parameters);
6540
6673
  if (!result2.valid) {
6541
6674
  res.status(400).json({ errors: result2.errors });
@@ -6546,10 +6679,10 @@ async function createRouter(options) {
6546
6679
  const taskSpec = {
6547
6680
  apiVersion: template.apiVersion,
6548
6681
  steps: template.spec.steps.map((step, index) => {
6549
- var _a2, _b2;
6682
+ var _a3, _b2;
6550
6683
  return {
6551
6684
  ...step,
6552
- id: (_a2 = step.id) != null ? _a2 : `step-${index + 1}`,
6685
+ id: (_a3 = step.id) != null ? _a3 : `step-${index + 1}`,
6553
6686
  name: (_b2 = step.name) != null ? _b2 : step.action
6554
6687
  };
6555
6688
  }),
@@ -6599,9 +6732,9 @@ async function createRouter(options) {
6599
6732
  delete task.secrets;
6600
6733
  res.status(200).json(task);
6601
6734
  }).post("/v2/tasks/:taskId/cancel", async (req, res) => {
6602
- var _a;
6735
+ var _a2;
6603
6736
  const { taskId } = req.params;
6604
- await ((_a = taskBroker.cancel) == null ? void 0 : _a.call(taskBroker, taskId));
6737
+ await ((_a2 = taskBroker.cancel) == null ? void 0 : _a2.call(taskBroker, taskId));
6605
6738
  res.status(200).json({ status: "cancelled" });
6606
6739
  }).get("/v2/tasks/:taskId/eventstream", async (req, res) => {
6607
6740
  const { taskId } = req.params;
@@ -6620,7 +6753,7 @@ async function createRouter(options) {
6620
6753
  res.end();
6621
6754
  },
6622
6755
  next: ({ events }) => {
6623
- var _a;
6756
+ var _a2;
6624
6757
  let shouldUnsubscribe = false;
6625
6758
  for (const event of events) {
6626
6759
  res.write(
@@ -6633,7 +6766,7 @@ data: ${JSON.stringify(event)}
6633
6766
  shouldUnsubscribe = true;
6634
6767
  }
6635
6768
  }
6636
- (_a = res.flush) == null ? void 0 : _a.call(res);
6769
+ (_a2 = res.flush) == null ? void 0 : _a2.call(res);
6637
6770
  if (shouldUnsubscribe) {
6638
6771
  subscription.unsubscribe();
6639
6772
  res.end();
@@ -6667,7 +6800,7 @@ data: ${JSON.stringify(event)}
6667
6800
  clearTimeout(timeout);
6668
6801
  });
6669
6802
  }).post("/v2/dry-run", async (req, res) => {
6670
- var _a, _b, _c, _d;
6803
+ var _a2, _b, _c, _d;
6671
6804
  const bodySchema = zod.z.object({
6672
6805
  template: zod.z.unknown(),
6673
6806
  values: zod.z.record(zod.z.unknown()),
@@ -6683,9 +6816,9 @@ data: ${JSON.stringify(event)}
6683
6816
  if (!await pluginScaffolderCommon.templateEntityV1beta3Validator.check(template)) {
6684
6817
  throw new errors.InputError("Input template is not a template");
6685
6818
  }
6686
- const token = (_a = await identity.getIdentity({
6819
+ const token = (_a2 = await identity.getIdentity({
6687
6820
  request: req
6688
- })) == null ? void 0 : _a.token;
6821
+ })) == null ? void 0 : _a2.token;
6689
6822
  for (const parameters of [(_b = template.spec.parameters) != null ? _b : []].flat()) {
6690
6823
  const result2 = jsonschema.validate(body.values, parameters);
6691
6824
  if (!result2.valid) {
@@ -6694,10 +6827,10 @@ data: ${JSON.stringify(event)}
6694
6827
  }
6695
6828
  }
6696
6829
  const steps = template.spec.steps.map((step, index) => {
6697
- var _a2, _b2;
6830
+ var _a3, _b2;
6698
6831
  return {
6699
6832
  ...step,
6700
- id: (_a2 = step.id) != null ? _a2 : `step-${index + 1}`,
6833
+ id: (_a3 = step.id) != null ? _a3 : `step-${index + 1}`,
6701
6834
  name: (_b2 = step.name) != null ? _b2 : step.action
6702
6835
  };
6703
6836
  });
@@ -6862,4 +6995,4 @@ exports.createRouter = createRouter;
6862
6995
  exports.createWaitAction = createWaitAction;
6863
6996
  exports.scaffolderActionRules = scaffolderActionRules;
6864
6997
  exports.scaffolderTemplateRules = scaffolderTemplateRules;
6865
- //# sourceMappingURL=ScaffolderEntitiesProcessor-82f18a18.cjs.js.map
6998
+ //# sourceMappingURL=ScaffolderEntitiesProcessor-4b7489dd.cjs.js.map