@backstage/plugin-scaffolder-backend 1.5.0 → 1.6.0-next.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,58 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 1.6.0-next.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 7db9613671: Added `projectId` for gitlab projects to be displayed in the `gitlab:publish` output
8
+
9
+ ### Patch Changes
10
+
11
+ - 0d8d650e32: Applied the fix from version 1.5.1 of this package, which is part of the v1.5.1 release of Backstage.
12
+ - Updated dependencies
13
+ - @backstage/backend-common@0.15.1-next.1
14
+ - @backstage/plugin-catalog-backend@1.4.0-next.1
15
+
16
+ ## 1.6.0-next.0
17
+
18
+ ### Minor Changes
19
+
20
+ - ea2eee9e6a: Add the option for a homepage when using the `github:publish` action
21
+ - 8872cc735d: Fixed a bug in plugin-scaffolder-backend where it ignores the skip migration database options.
22
+
23
+ To use this new implementation you need to create the instance of `DatabaseTaskStore` using the `PluginDatabaseManager` instead of `Knex`;
24
+
25
+ ```
26
+ import { DatabaseManager, getRootLogger, loadBackendConfig } from '@backstage/backend-common';
27
+ import { DatabaseTaskStore } from '@backstage/plugin-scaffolder-backend';
28
+
29
+ const config = await loadBackendConfig({ argv: process.argv, logger: getRootLogger() });
30
+ const databaseManager = DatabaseManager.fromConfig(config, { migrations: { skip: true } });
31
+ const databaseTaskStore = await DatabaseTaskStore.create(databaseManager);
32
+ ```
33
+
34
+ - 1ff817b3f0: add entity metadata to the template info type
35
+
36
+ ### Patch Changes
37
+
38
+ - bf5e9030eb: Updated dependency `msw` to `^0.45.0`.
39
+ - 2df9955f4a: Removed the depreacated `publish:file` action, use the template editor to test templates instead.
40
+ - ef9ab322de: Minor API signatures cleanup
41
+ - Updated dependencies
42
+ - @backstage/backend-common@0.15.1-next.0
43
+ - @backstage/plugin-catalog-backend@1.3.2-next.0
44
+ - @backstage/backend-plugin-api@0.1.2-next.0
45
+ - @backstage/catalog-client@1.0.5-next.0
46
+ - @backstage/integration@1.3.1-next.0
47
+ - @backstage/plugin-scaffolder-common@1.2.0-next.0
48
+ - @backstage/plugin-catalog-node@1.0.2-next.0
49
+
50
+ ## 1.5.1
51
+
52
+ ### Patch Changes
53
+
54
+ - Fix minimum required version for `vm2`
55
+
3
56
  ## 1.5.0
4
57
 
5
58
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "1.5.0",
3
+ "version": "1.6.0-next.1",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -264,6 +264,7 @@ export declare function createGithubRepoCreateAction(options: {
264
264
  }): TemplateAction< {
265
265
  repoUrl: string;
266
266
  description?: string | undefined;
267
+ homepage?: string | undefined;
267
268
  access?: string | undefined;
268
269
  deleteBranchOnMerge?: boolean | undefined;
269
270
  gitAuthorName?: string | undefined;
@@ -409,22 +410,6 @@ enableLFS?: boolean | undefined;
409
410
  token?: string | undefined;
410
411
  }>;
411
412
 
412
- /**
413
- * This task is useful for local development and testing of both the scaffolder
414
- * and scaffolder templates.
415
- *
416
- * @remarks
417
- *
418
- * This action is not installed by default and should not be installed in
419
- * production, as it writes the files to the local filesystem of the scaffolder.
420
- *
421
- * @public
422
- * @deprecated This action will be removed, prefer testing templates using the template editor instead.
423
- */
424
- export declare function createPublishFileAction(): TemplateAction< {
425
- path: string;
426
- }>;
427
-
428
413
  /**
429
414
  * Creates a new action that initializes a git repository of the content in the workspace
430
415
  * and publishes it to a Gerrit instance.
@@ -472,6 +457,7 @@ export declare function createPublishGithubAction(options: {
472
457
  }): TemplateAction< {
473
458
  repoUrl: string;
474
459
  description?: string | undefined;
460
+ homepage?: string | undefined;
475
461
  access?: string | undefined;
476
462
  defaultBranch?: string | undefined;
477
463
  protectDefaultBranch?: boolean | undefined;
@@ -619,6 +605,8 @@ export declare interface CurrentClaimedTask {
619
605
  export declare class DatabaseTaskStore implements TaskStore {
620
606
  private readonly db;
621
607
  static create(options: DatabaseTaskStoreOptions): Promise<DatabaseTaskStore>;
608
+ private static getClient;
609
+ private static runMigrations;
622
610
  private constructor();
623
611
  list(options: {
624
612
  createdBy?: string;
@@ -629,14 +617,14 @@ export declare class DatabaseTaskStore implements TaskStore {
629
617
  createTask(options: TaskStoreCreateTaskOptions): Promise<TaskStoreCreateTaskResult>;
630
618
  claimTask(): Promise<SerializedTask | undefined>;
631
619
  heartbeatTask(taskId: string): Promise<void>;
632
- listStaleTasks({ timeoutS }: {
620
+ listStaleTasks(options: {
633
621
  timeoutS: number;
634
622
  }): Promise<{
635
623
  tasks: {
636
624
  taskId: string;
637
625
  }[];
638
626
  }>;
639
- completeTask({ taskId, status, eventBody, }: {
627
+ completeTask(options: {
640
628
  taskId: string;
641
629
  status: TaskStatus;
642
630
  eventBody: JsonObject;
@@ -644,7 +632,7 @@ export declare class DatabaseTaskStore implements TaskStore {
644
632
  emitLogEvent(options: TaskStoreEmitOptions<{
645
633
  message: string;
646
634
  } & JsonObject>): Promise<void>;
647
- listEvents({ taskId, after, }: TaskStoreListEventsOptions): Promise<{
635
+ listEvents(options: TaskStoreListEventsOptions): Promise<{
648
636
  events: SerializedTaskEvent[];
649
637
  }>;
650
638
  }
@@ -655,7 +643,7 @@ export declare class DatabaseTaskStore implements TaskStore {
655
643
  * @public
656
644
  */
657
645
  export declare type DatabaseTaskStoreOptions = {
658
- database: Knex;
646
+ database: PluginDatabaseManager | Knex;
659
647
  };
660
648
 
661
649
  /**
@@ -671,7 +659,7 @@ export declare const executeShellCommand: (options: RunCommandOptions) => Promis
671
659
  *
672
660
  * @public
673
661
  */
674
- export declare function fetchContents({ reader, integrations, baseUrl, fetchUrl, outputPath, }: {
662
+ export declare function fetchContents(options: {
675
663
  reader: UrlReader;
676
664
  integrations: ScmIntegrations;
677
665
  baseUrl?: string;
@@ -264,6 +264,7 @@ export declare function createGithubRepoCreateAction(options: {
264
264
  }): TemplateAction< {
265
265
  repoUrl: string;
266
266
  description?: string | undefined;
267
+ homepage?: string | undefined;
267
268
  access?: string | undefined;
268
269
  deleteBranchOnMerge?: boolean | undefined;
269
270
  gitAuthorName?: string | undefined;
@@ -409,22 +410,6 @@ enableLFS?: boolean | undefined;
409
410
  token?: string | undefined;
410
411
  }>;
411
412
 
412
- /**
413
- * This task is useful for local development and testing of both the scaffolder
414
- * and scaffolder templates.
415
- *
416
- * @remarks
417
- *
418
- * This action is not installed by default and should not be installed in
419
- * production, as it writes the files to the local filesystem of the scaffolder.
420
- *
421
- * @public
422
- * @deprecated This action will be removed, prefer testing templates using the template editor instead.
423
- */
424
- export declare function createPublishFileAction(): TemplateAction< {
425
- path: string;
426
- }>;
427
-
428
413
  /**
429
414
  * Creates a new action that initializes a git repository of the content in the workspace
430
415
  * and publishes it to a Gerrit instance.
@@ -472,6 +457,7 @@ export declare function createPublishGithubAction(options: {
472
457
  }): TemplateAction< {
473
458
  repoUrl: string;
474
459
  description?: string | undefined;
460
+ homepage?: string | undefined;
475
461
  access?: string | undefined;
476
462
  defaultBranch?: string | undefined;
477
463
  protectDefaultBranch?: boolean | undefined;
@@ -619,6 +605,8 @@ export declare interface CurrentClaimedTask {
619
605
  export declare class DatabaseTaskStore implements TaskStore {
620
606
  private readonly db;
621
607
  static create(options: DatabaseTaskStoreOptions): Promise<DatabaseTaskStore>;
608
+ private static getClient;
609
+ private static runMigrations;
622
610
  private constructor();
623
611
  list(options: {
624
612
  createdBy?: string;
@@ -629,14 +617,14 @@ export declare class DatabaseTaskStore implements TaskStore {
629
617
  createTask(options: TaskStoreCreateTaskOptions): Promise<TaskStoreCreateTaskResult>;
630
618
  claimTask(): Promise<SerializedTask | undefined>;
631
619
  heartbeatTask(taskId: string): Promise<void>;
632
- listStaleTasks({ timeoutS }: {
620
+ listStaleTasks(options: {
633
621
  timeoutS: number;
634
622
  }): Promise<{
635
623
  tasks: {
636
624
  taskId: string;
637
625
  }[];
638
626
  }>;
639
- completeTask({ taskId, status, eventBody, }: {
627
+ completeTask(options: {
640
628
  taskId: string;
641
629
  status: TaskStatus;
642
630
  eventBody: JsonObject;
@@ -644,7 +632,7 @@ export declare class DatabaseTaskStore implements TaskStore {
644
632
  emitLogEvent(options: TaskStoreEmitOptions<{
645
633
  message: string;
646
634
  } & JsonObject>): Promise<void>;
647
- listEvents({ taskId, after, }: TaskStoreListEventsOptions): Promise<{
635
+ listEvents(options: TaskStoreListEventsOptions): Promise<{
648
636
  events: SerializedTaskEvent[];
649
637
  }>;
650
638
  }
@@ -655,7 +643,7 @@ export declare class DatabaseTaskStore implements TaskStore {
655
643
  * @public
656
644
  */
657
645
  export declare type DatabaseTaskStoreOptions = {
658
- database: Knex;
646
+ database: PluginDatabaseManager | Knex;
659
647
  };
660
648
 
661
649
  /**
@@ -671,7 +659,7 @@ export declare const executeShellCommand: (options: RunCommandOptions) => Promis
671
659
  *
672
660
  * @public
673
661
  */
674
- export declare function fetchContents({ reader, integrations, baseUrl, fetchUrl, outputPath, }: {
662
+ export declare function fetchContents(options: {
675
663
  reader: UrlReader;
676
664
  integrations: ScmIntegrations;
677
665
  baseUrl?: string;
package/dist/index.cjs.js CHANGED
@@ -283,13 +283,8 @@ async function recursiveReadDir(dir) {
283
283
  return files.reduce((a, f) => a.concat(f), []);
284
284
  }
285
285
 
286
- async function fetchContents({
287
- reader,
288
- integrations,
289
- baseUrl,
290
- fetchUrl = ".",
291
- outputPath
292
- }) {
286
+ async function fetchContents(options) {
287
+ const { reader, integrations, baseUrl, fetchUrl = ".", outputPath } = options;
293
288
  let fetchUrlIsAbsolute = false;
294
289
  try {
295
290
  new URL(fetchUrl);
@@ -1043,7 +1038,7 @@ async function getOctokitOptions(options) {
1043
1038
  previews: ["nebula-preview"]
1044
1039
  };
1045
1040
  }
1046
- async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, repoVisibility, description, deleteBranchOnMerge, allowMergeCommit, allowSquashMerge, allowRebaseMerge, access, collaborators, topics, logger) {
1041
+ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, repoVisibility, description, homepage, deleteBranchOnMerge, allowMergeCommit, allowSquashMerge, allowRebaseMerge, access, collaborators, topics, logger) {
1047
1042
  const user = await client.rest.users.getByUsername({
1048
1043
  username: owner
1049
1044
  });
@@ -1056,7 +1051,8 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
1056
1051
  delete_branch_on_merge: deleteBranchOnMerge,
1057
1052
  allow_merge_commit: allowMergeCommit,
1058
1053
  allow_squash_merge: allowSquashMerge,
1059
- allow_rebase_merge: allowRebaseMerge
1054
+ allow_rebase_merge: allowRebaseMerge,
1055
+ homepage
1060
1056
  }) : client.rest.repos.createForAuthenticatedUser({
1061
1057
  name: repo,
1062
1058
  private: repoVisibility === "private",
@@ -1064,7 +1060,8 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
1064
1060
  delete_branch_on_merge: deleteBranchOnMerge,
1065
1061
  allow_merge_commit: allowMergeCommit,
1066
1062
  allow_squash_merge: allowSquashMerge,
1067
- allow_rebase_merge: allowRebaseMerge
1063
+ allow_rebase_merge: allowRebaseMerge,
1064
+ homepage
1068
1065
  });
1069
1066
  let newRepo;
1070
1067
  try {
@@ -1335,6 +1332,10 @@ const description = {
1335
1332
  title: "Repository Description",
1336
1333
  type: "string"
1337
1334
  };
1335
+ const homepage = {
1336
+ title: "Repository Homepage",
1337
+ type: "string"
1338
+ };
1338
1339
  const access = {
1339
1340
  title: "Repository Access",
1340
1341
  description: `Sets an admin collaborator on the repository. Can either be a user reference different from 'owner' in 'repoUrl' or team reference, eg. 'org/team-name'`,
@@ -1473,6 +1474,7 @@ function createGithubRepoCreateAction(options) {
1473
1474
  properties: {
1474
1475
  repoUrl: repoUrl,
1475
1476
  description: description,
1477
+ homepage: homepage,
1476
1478
  access: access,
1477
1479
  requireCodeOwnerReviews: requireCodeOwnerReviews,
1478
1480
  requiredStatusCheckContexts: requiredStatusCheckContexts,
@@ -1498,6 +1500,7 @@ function createGithubRepoCreateAction(options) {
1498
1500
  const {
1499
1501
  repoUrl,
1500
1502
  description,
1503
+ homepage,
1501
1504
  access,
1502
1505
  repoVisibility = "private",
1503
1506
  deleteBranchOnMerge = false,
@@ -1525,6 +1528,7 @@ function createGithubRepoCreateAction(options) {
1525
1528
  owner,
1526
1529
  repoVisibility,
1527
1530
  description,
1531
+ homepage,
1528
1532
  deleteBranchOnMerge,
1529
1533
  allowMergeCommit,
1530
1534
  allowSquashMerge,
@@ -2544,37 +2548,6 @@ function createPublishBitbucketServerAction(options) {
2544
2548
  });
2545
2549
  }
2546
2550
 
2547
- function createPublishFileAction() {
2548
- return createTemplateAction({
2549
- id: "publish:file",
2550
- description: "Writes contents of the workspace to a local directory",
2551
- schema: {
2552
- input: {
2553
- type: "object",
2554
- required: ["path"],
2555
- properties: {
2556
- path: {
2557
- title: "Path to a directory where the output will be written",
2558
- type: "string"
2559
- }
2560
- }
2561
- }
2562
- },
2563
- async handler(ctx) {
2564
- ctx.logger.warn(
2565
- "[DEPRECATED] This action will be removed, prefer testing templates using the template editor instead."
2566
- );
2567
- const { path: path$1 } = ctx.input;
2568
- const exists = await fs__default["default"].pathExists(path$1);
2569
- if (exists) {
2570
- throw new errors.InputError("Output path already exists");
2571
- }
2572
- await fs__default["default"].ensureDir(path.dirname(path$1));
2573
- await fs__default["default"].copy(ctx.workspacePath, path$1);
2574
- }
2575
- });
2576
- }
2577
-
2578
2551
  const createGerritProject = async (config, options) => {
2579
2552
  const { projectName, parent, owner, description } = options;
2580
2553
  const fetchOptions = {
@@ -2843,6 +2816,7 @@ function createPublishGithubAction(options) {
2843
2816
  properties: {
2844
2817
  repoUrl: repoUrl,
2845
2818
  description: description,
2819
+ homepage: homepage,
2846
2820
  access: access,
2847
2821
  requireCodeOwnerReviews: requireCodeOwnerReviews,
2848
2822
  requiredStatusCheckContexts: requiredStatusCheckContexts,
@@ -2875,6 +2849,7 @@ function createPublishGithubAction(options) {
2875
2849
  const {
2876
2850
  repoUrl,
2877
2851
  description,
2852
+ homepage,
2878
2853
  access,
2879
2854
  requireCodeOwnerReviews = false,
2880
2855
  requiredStatusCheckContexts = [],
@@ -2910,6 +2885,7 @@ function createPublishGithubAction(options) {
2910
2885
  owner,
2911
2886
  repoVisibility,
2912
2887
  description,
2888
+ homepage,
2913
2889
  deleteBranchOnMerge,
2914
2890
  allowMergeCommit,
2915
2891
  allowSquashMerge,
@@ -3261,6 +3237,10 @@ function createPublishGitlabAction(options) {
3261
3237
  repoContentsUrl: {
3262
3238
  title: "A URL to the root of the repository",
3263
3239
  type: "string"
3240
+ },
3241
+ projectId: {
3242
+ title: "The ID of the project",
3243
+ type: "string"
3264
3244
  }
3265
3245
  }
3266
3246
  }
@@ -3333,6 +3313,7 @@ function createPublishGitlabAction(options) {
3333
3313
  });
3334
3314
  ctx.output("remoteUrl", remoteUrl);
3335
3315
  ctx.output("repoContentsUrl", repoContentsUrl);
3316
+ ctx.output("projectId", projectId);
3336
3317
  }
3337
3318
  });
3338
3319
  }
@@ -3639,6 +3620,9 @@ const migrationsDir = backendCommon.resolvePackagePath(
3639
3620
  "@backstage/plugin-scaffolder-backend",
3640
3621
  "migrations"
3641
3622
  );
3623
+ function isPluginDatabaseManager(opt) {
3624
+ return opt.getClient !== void 0;
3625
+ }
3642
3626
  const parseSqlDateToIsoString = (input) => {
3643
3627
  if (typeof input === "string") {
3644
3628
  return luxon.DateTime.fromSQL(input, { zone: "UTC" }).toISO();
@@ -3647,13 +3631,33 @@ const parseSqlDateToIsoString = (input) => {
3647
3631
  };
3648
3632
  class DatabaseTaskStore {
3649
3633
  static async create(options) {
3650
- await options.database.migrate.latest({
3651
- directory: migrationsDir
3652
- });
3653
- return new DatabaseTaskStore(options);
3634
+ const { database } = options;
3635
+ const client = await this.getClient(database);
3636
+ await this.runMigrations(database, client);
3637
+ return new DatabaseTaskStore(client);
3654
3638
  }
3655
- constructor(options) {
3656
- this.db = options.database;
3639
+ static async getClient(database) {
3640
+ if (isPluginDatabaseManager(database)) {
3641
+ return database.getClient();
3642
+ }
3643
+ return database;
3644
+ }
3645
+ static async runMigrations(database, client) {
3646
+ var _a;
3647
+ if (!isPluginDatabaseManager(database)) {
3648
+ await client.migrate.latest({
3649
+ directory: migrationsDir
3650
+ });
3651
+ return;
3652
+ }
3653
+ if (!((_a = database.migrations) == null ? void 0 : _a.skip)) {
3654
+ await client.migrate.latest({
3655
+ directory: migrationsDir
3656
+ });
3657
+ }
3658
+ }
3659
+ constructor(client) {
3660
+ this.db = client;
3657
3661
  }
3658
3662
  async list(options) {
3659
3663
  const queryBuilder = this.db("tasks");
@@ -3752,7 +3756,8 @@ class DatabaseTaskStore {
3752
3756
  throw new errors.ConflictError(`No running task with taskId ${taskId} found`);
3753
3757
  }
3754
3758
  }
3755
- async listStaleTasks({ timeoutS }) {
3759
+ async listStaleTasks(options) {
3760
+ const { timeoutS } = options;
3756
3761
  const rawRows = await this.db("tasks").where("status", "processing").andWhere(
3757
3762
  "last_heartbeat_at",
3758
3763
  "<=",
@@ -3766,11 +3771,8 @@ class DatabaseTaskStore {
3766
3771
  }));
3767
3772
  return { tasks };
3768
3773
  }
3769
- async completeTask({
3770
- taskId,
3771
- status,
3772
- eventBody
3773
- }) {
3774
+ async completeTask(options) {
3775
+ const { taskId, status, eventBody } = options;
3774
3776
  let oldStatus;
3775
3777
  if (status === "failed" || status === "completed") {
3776
3778
  oldStatus = "processing";
@@ -3818,10 +3820,8 @@ class DatabaseTaskStore {
3818
3820
  body: serializedBody
3819
3821
  });
3820
3822
  }
3821
- async listEvents({
3822
- taskId,
3823
- after
3824
- }) {
3823
+ async listEvents(options) {
3824
+ const { taskId, after } = options;
3825
3825
  const rawEvents = await this.db("task_events").where({
3826
3826
  task_id: taskId
3827
3827
  }).andWhere((builder) => {
@@ -4468,9 +4468,7 @@ async function createRouter(options) {
4468
4468
  const integrations = integration.ScmIntegrations.fromConfig(config);
4469
4469
  let taskBroker;
4470
4470
  if (!options.taskBroker) {
4471
- const databaseTaskStore = await DatabaseTaskStore.create({
4472
- database: await database.getClient()
4473
- });
4471
+ const databaseTaskStore = await DatabaseTaskStore.create({ database });
4474
4472
  taskBroker = new StorageTaskBroker(databaseTaskStore, logger);
4475
4473
  } else {
4476
4474
  taskBroker = options.taskBroker;
@@ -4604,7 +4602,10 @@ async function createRouter(options) {
4604
4602
  namespace,
4605
4603
  name: (_c = template.metadata) == null ? void 0 : _c.name
4606
4604
  }),
4607
- baseUrl
4605
+ baseUrl,
4606
+ entity: {
4607
+ metadata: template.metadata
4608
+ }
4608
4609
  }
4609
4610
  };
4610
4611
  const result = await taskBroker.dispatch({
@@ -4890,7 +4891,6 @@ exports.createPublishAzureAction = createPublishAzureAction;
4890
4891
  exports.createPublishBitbucketAction = createPublishBitbucketAction;
4891
4892
  exports.createPublishBitbucketCloudAction = createPublishBitbucketCloudAction;
4892
4893
  exports.createPublishBitbucketServerAction = createPublishBitbucketServerAction;
4893
- exports.createPublishFileAction = createPublishFileAction;
4894
4894
  exports.createPublishGerritAction = createPublishGerritAction;
4895
4895
  exports.createPublishGerritReviewAction = createPublishGerritReviewAction;
4896
4896
  exports.createPublishGithubAction = createPublishGithubAction;