@backstage/plugin-scaffolder-backend 0.15.11 → 0.15.15

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/dist/index.d.ts CHANGED
@@ -11,6 +11,8 @@ import { Config } from '@backstage/config';
11
11
  import { createPullRequest } from 'octokit-plugin-create-pull-request';
12
12
  import { Octokit } from '@octokit/rest';
13
13
  export { createFetchCookiecutterAction } from '@backstage/plugin-scaffolder-backend-module-cookiecutter';
14
+ import { SpawnOptionsWithoutStdio } from 'child_process';
15
+ import { Knex } from 'knex';
14
16
  import express from 'express';
15
17
  import { TemplateEntityV1beta2, Entity, LocationSpec } from '@backstage/catalog-model';
16
18
  import { CatalogProcessor, CatalogProcessorEmit } from '@backstage/plugin-catalog-backend';
@@ -139,11 +141,217 @@ declare class OctokitProvider {
139
141
  }
140
142
 
141
143
  declare type RunCommandOptions = {
144
+ /** command to run */
142
145
  command: string;
146
+ /** arguments to pass the command */
143
147
  args: string[];
148
+ /** options to pass to spawn */
149
+ options?: SpawnOptionsWithoutStdio;
150
+ /** stream to capture stdout and stderr output */
144
151
  logStream?: Writable;
145
152
  };
146
- declare const runCommand: ({ command, args, logStream, }: RunCommandOptions) => Promise<void>;
153
+ /**
154
+ * Run a command in a sub-process, normally a shell command.
155
+ */
156
+ declare const runCommand: ({ command, args, logStream, options, }: RunCommandOptions) => Promise<void>;
157
+
158
+ /**
159
+ * Status
160
+ *
161
+ * @public
162
+ */
163
+ declare type Status = 'open' | 'processing' | 'failed' | 'cancelled' | 'completed';
164
+ /**
165
+ * CompletedTaskState
166
+ *
167
+ * @public
168
+ */
169
+ declare type CompletedTaskState = 'failed' | 'completed';
170
+ /**
171
+ * SerializedTask
172
+ *
173
+ * @public
174
+ */
175
+ declare type SerializedTask = {
176
+ id: string;
177
+ spec: TaskSpec;
178
+ status: Status;
179
+ createdAt: string;
180
+ lastHeartbeatAt?: string;
181
+ secrets?: TaskSecrets;
182
+ };
183
+ /**
184
+ * TaskEventType
185
+ *
186
+ * @public
187
+ */
188
+ declare type TaskEventType = 'completion' | 'log';
189
+ /**
190
+ * SerializedTaskEvent
191
+ *
192
+ * @public
193
+ */
194
+ declare type SerializedTaskEvent = {
195
+ id: number;
196
+ taskId: string;
197
+ body: JsonObject;
198
+ type: TaskEventType;
199
+ createdAt: string;
200
+ };
201
+ /**
202
+ * TemplateMetadata
203
+ *
204
+ * @public
205
+ */
206
+ declare type TemplateMetadata = {
207
+ name: string;
208
+ };
209
+ /**
210
+ * TaskSpecV1beta2
211
+ *
212
+ * @public
213
+ */
214
+ interface TaskSpecV1beta2 {
215
+ apiVersion: 'backstage.io/v1beta2';
216
+ baseUrl?: string;
217
+ values: JsonObject;
218
+ steps: Array<{
219
+ id: string;
220
+ name: string;
221
+ action: string;
222
+ input?: JsonObject;
223
+ if?: string | boolean;
224
+ }>;
225
+ output: {
226
+ [name: string]: string;
227
+ };
228
+ metadata?: TemplateMetadata;
229
+ }
230
+ interface TaskStep {
231
+ id: string;
232
+ name: string;
233
+ action: string;
234
+ input?: JsonObject;
235
+ if?: string | boolean;
236
+ }
237
+ /**
238
+ * TaskSpecV1beta3
239
+ *
240
+ * @public
241
+ */
242
+ interface TaskSpecV1beta3 {
243
+ apiVersion: 'scaffolder.backstage.io/v1beta3';
244
+ baseUrl?: string;
245
+ parameters: JsonObject;
246
+ steps: TaskStep[];
247
+ output: {
248
+ [name: string]: JsonValue;
249
+ };
250
+ metadata?: TemplateMetadata;
251
+ }
252
+ /**
253
+ * TaskSpec
254
+ *
255
+ * @public
256
+ */
257
+ declare type TaskSpec = TaskSpecV1beta2 | TaskSpecV1beta3;
258
+ /**
259
+ * TaskSecrets
260
+ *
261
+ * @public
262
+ */
263
+ declare type TaskSecrets = {
264
+ token: string | undefined;
265
+ };
266
+ /**
267
+ * DispatchResult
268
+ *
269
+ * @public
270
+ */
271
+ declare type DispatchResult = {
272
+ taskId: string;
273
+ };
274
+ /**
275
+ * Task
276
+ *
277
+ * @public
278
+ */
279
+ interface TaskContext {
280
+ spec: TaskSpec;
281
+ secrets?: TaskSecrets;
282
+ done: boolean;
283
+ emitLog(message: string, metadata?: JsonValue): Promise<void>;
284
+ complete(result: CompletedTaskState, metadata?: JsonValue): Promise<void>;
285
+ getWorkspaceName(): Promise<string>;
286
+ }
287
+ /**
288
+ * TaskBroker
289
+ *
290
+ * @public
291
+ */
292
+ interface TaskBroker {
293
+ claim(): Promise<TaskContext>;
294
+ dispatch(spec: TaskSpec, secrets?: TaskSecrets): Promise<DispatchResult>;
295
+ vacuumTasks(timeoutS: {
296
+ timeoutS: number;
297
+ }): Promise<void>;
298
+ observe(options: {
299
+ taskId: string;
300
+ after: number | undefined;
301
+ }, callback: (error: Error | undefined, result: {
302
+ events: SerializedTaskEvent[];
303
+ }) => void): {
304
+ unsubscribe: () => void;
305
+ };
306
+ get(taskId: string): Promise<SerializedTask>;
307
+ }
308
+ /**
309
+ * TaskStoreEmitOptions
310
+ *
311
+ * @public
312
+ */
313
+ declare type TaskStoreEmitOptions = {
314
+ taskId: string;
315
+ body: JsonObject;
316
+ };
317
+ /**
318
+ * TaskStoreListEventsOptions
319
+ *
320
+ * @public
321
+ */
322
+ declare type TaskStoreListEventsOptions = {
323
+ taskId: string;
324
+ after?: number | undefined;
325
+ };
326
+ /**
327
+ * TaskStore
328
+ *
329
+ * @public
330
+ */
331
+ interface TaskStore {
332
+ createTask(task: TaskSpec, secrets?: TaskSecrets): Promise<{
333
+ taskId: string;
334
+ }>;
335
+ getTask(taskId: string): Promise<SerializedTask>;
336
+ claimTask(): Promise<SerializedTask | undefined>;
337
+ completeTask(options: {
338
+ taskId: string;
339
+ status: Status;
340
+ eventBody: JsonObject;
341
+ }): Promise<void>;
342
+ heartbeatTask(taskId: string): Promise<void>;
343
+ listStaleTasks(options: {
344
+ timeoutS: number;
345
+ }): Promise<{
346
+ tasks: {
347
+ taskId: string;
348
+ }[];
349
+ }>;
350
+ emitLogEvent({ taskId, body }: TaskStoreEmitOptions): Promise<void>;
351
+ listEvents({ taskId, after, }: TaskStoreListEventsOptions): Promise<{
352
+ events: SerializedTaskEvent[];
353
+ }>;
354
+ }
147
355
 
148
356
  declare type PartialJsonObject = Partial<JsonObject>;
149
357
  declare type PartialJsonValue = PartialJsonObject | JsonValue | undefined;
@@ -168,6 +376,7 @@ declare type ActionContext<Input extends InputBase> = {
168
376
  * Creates a temporary directory for use by the action, which is then cleaned up automatically.
169
377
  */
170
378
  createTemporaryDirectory(): Promise<string>;
379
+ metadata?: TemplateMetadata;
171
380
  };
172
381
  declare type TemplateAction<Input extends InputBase> = {
173
382
  id: string;
@@ -190,6 +399,109 @@ declare const createTemplateAction: <Input extends Partial<{
190
399
  [name: string]: _backstage_types.JsonValue | Partial<_backstage_types.JsonObject> | undefined;
191
400
  }>>(templateAction: TemplateAction<Input>) => TemplateAction<any>;
192
401
 
402
+ /**
403
+ * DatabaseTaskStore
404
+ *
405
+ * @public
406
+ */
407
+ declare type DatabaseTaskStoreOptions = {
408
+ database: Knex;
409
+ };
410
+ /**
411
+ * DatabaseTaskStore
412
+ *
413
+ * @public
414
+ */
415
+ declare class DatabaseTaskStore implements TaskStore {
416
+ private readonly db;
417
+ static create(options: DatabaseTaskStoreOptions): Promise<DatabaseTaskStore>;
418
+ constructor(options: DatabaseTaskStoreOptions);
419
+ getTask(taskId: string): Promise<SerializedTask>;
420
+ createTask(spec: TaskSpec, secrets?: TaskSecrets): Promise<{
421
+ taskId: string;
422
+ }>;
423
+ claimTask(): Promise<SerializedTask | undefined>;
424
+ heartbeatTask(taskId: string): Promise<void>;
425
+ listStaleTasks({ timeoutS }: {
426
+ timeoutS: number;
427
+ }): Promise<{
428
+ tasks: {
429
+ taskId: string;
430
+ }[];
431
+ }>;
432
+ completeTask({ taskId, status, eventBody, }: {
433
+ taskId: string;
434
+ status: Status;
435
+ eventBody: JsonObject;
436
+ }): Promise<void>;
437
+ emitLogEvent({ taskId, body }: TaskStoreEmitOptions): Promise<void>;
438
+ listEvents({ taskId, after, }: TaskStoreListEventsOptions): Promise<{
439
+ events: SerializedTaskEvent[];
440
+ }>;
441
+ }
442
+
443
+ /**
444
+ * TaskManager
445
+ *
446
+ * @public
447
+ */
448
+ declare class TaskManager implements TaskContext {
449
+ private readonly state;
450
+ private readonly storage;
451
+ private readonly logger;
452
+ private isDone;
453
+ private heartbeatTimeoutId?;
454
+ static create(state: TaskState, storage: TaskStore, logger: Logger): TaskManager;
455
+ private constructor();
456
+ get spec(): TaskSpec;
457
+ get secrets(): TaskSecrets | undefined;
458
+ getWorkspaceName(): Promise<string>;
459
+ get done(): boolean;
460
+ emitLog(message: string, metadata?: JsonObject): Promise<void>;
461
+ complete(result: CompletedTaskState, metadata?: JsonObject): Promise<void>;
462
+ private startTimeout;
463
+ }
464
+ /**
465
+ * TaskState
466
+ *
467
+ * @public
468
+ */
469
+ interface TaskState {
470
+ spec: TaskSpec;
471
+ taskId: string;
472
+ secrets?: TaskSecrets;
473
+ }
474
+
475
+ /**
476
+ * CreateWorkerOptions
477
+ *
478
+ * @public
479
+ */
480
+ declare type CreateWorkerOptions = {
481
+ taskBroker: TaskBroker;
482
+ actionRegistry: TemplateActionRegistry;
483
+ integrations: ScmIntegrations;
484
+ workingDirectory: string;
485
+ logger: Logger;
486
+ };
487
+ /**
488
+ * TaskWorker
489
+ *
490
+ * @public
491
+ */
492
+ declare class TaskWorker {
493
+ private readonly options;
494
+ private constructor();
495
+ static create(options: CreateWorkerOptions): Promise<TaskWorker>;
496
+ start(): void;
497
+ runOneTask(task: TaskContext): Promise<void>;
498
+ }
499
+
500
+ /**
501
+ * RouterOptions
502
+ *
503
+ * @public
504
+ */
193
505
  interface RouterOptions {
194
506
  logger: Logger;
195
507
  config: Config;
@@ -199,6 +511,7 @@ interface RouterOptions {
199
511
  actions?: TemplateAction<any>[];
200
512
  taskWorkers?: number;
201
513
  containerRunner: ContainerRunner;
514
+ taskBroker?: TaskBroker;
202
515
  }
203
516
  declare function createRouter(options: RouterOptions): Promise<express.Router>;
204
517
 
@@ -225,4 +538,4 @@ declare class ScaffolderEntitiesProcessor implements CatalogProcessor {
225
538
  postProcessEntity(entity: Entity, _location: LocationSpec, emit: CatalogProcessorEmit): Promise<Entity>;
226
539
  }
227
540
 
228
- export { ActionContext, CatalogEntityClient, OctokitProvider, RouterOptions, ScaffolderEntitiesProcessor, TemplateAction, TemplateActionRegistry, createBuiltinActions, createCatalogRegisterAction, createCatalogWriteAction, createDebugLogAction, createFetchPlainAction, createFetchTemplateAction, createFilesystemDeleteAction, createFilesystemRenameAction, createGithubActionsDispatchAction, createGithubWebhookAction, createPublishAzureAction, createPublishBitbucketAction, createPublishFileAction, createPublishGithubAction, createPublishGithubPullRequestAction, createPublishGitlabAction, createRouter, createTemplateAction, fetchContents, runCommand };
541
+ export { ActionContext, CatalogEntityClient, CompletedTaskState, CreateWorkerOptions, DatabaseTaskStore, DispatchResult, OctokitProvider, RouterOptions, ScaffolderEntitiesProcessor, SerializedTask, SerializedTaskEvent, Status, TaskBroker, TaskContext, TaskEventType, TaskManager, TaskSecrets, TaskSpec, TaskSpecV1beta2, TaskSpecV1beta3, TaskState, TaskStore, TaskStoreEmitOptions, TaskStoreListEventsOptions, TaskWorker, TemplateAction, TemplateActionRegistry, TemplateMetadata, createBuiltinActions, createCatalogRegisterAction, createCatalogWriteAction, createDebugLogAction, createFetchPlainAction, createFetchTemplateAction, createFilesystemDeleteAction, createFilesystemRenameAction, createGithubActionsDispatchAction, createGithubWebhookAction, createPublishAzureAction, createPublishBitbucketAction, createPublishFileAction, createPublishGithubAction, createPublishGithubPullRequestAction, createPublishGitlabAction, createRouter, createTemplateAction, fetchContents, runCommand };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
3
  "description": "The Backstage backend plugin that helps you create new things",
4
- "version": "0.15.11",
4
+ "version": "0.15.15",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -27,21 +27,22 @@
27
27
  "test": "backstage-cli test",
28
28
  "prepack": "backstage-cli prepack",
29
29
  "postpack": "backstage-cli postpack",
30
- "clean": "backstage-cli clean"
30
+ "clean": "backstage-cli clean",
31
+ "build:assets": "node scripts/build-nunjucks.js"
31
32
  },
32
33
  "dependencies": {
33
- "@backstage/backend-common": "^0.9.8",
34
- "@backstage/catalog-client": "^0.5.0",
35
- "@backstage/catalog-model": "^0.9.6",
34
+ "@backstage/backend-common": "^0.9.12",
35
+ "@backstage/catalog-client": "^0.5.2",
36
+ "@backstage/catalog-model": "^0.9.7",
36
37
  "@backstage/config": "^0.1.11",
37
- "@backstage/errors": "^0.1.4",
38
- "@backstage/integration": "^0.6.9",
39
- "@backstage/plugin-catalog-backend": "^0.17.2",
40
- "@backstage/plugin-scaffolder-backend-module-cookiecutter": "^0.1.3",
38
+ "@backstage/errors": "^0.1.5",
39
+ "@backstage/integration": "^0.6.10",
40
+ "@backstage/plugin-catalog-backend": "^0.19.0",
41
+ "@backstage/plugin-scaffolder-backend-module-cookiecutter": "^0.1.5",
41
42
  "@backstage/plugin-scaffolder-common": "^0.1.1",
42
43
  "@backstage/types": "^0.1.1",
43
- "@gitbeaker/core": "^30.2.0",
44
- "@gitbeaker/node": "^30.2.0",
44
+ "@gitbeaker/core": "^34.6.0",
45
+ "@gitbeaker/node": "^34.6.0",
45
46
  "@octokit/rest": "^18.5.3",
46
47
  "@octokit/webhooks": "^9.14.1",
47
48
  "@types/express": "^4.17.6",
@@ -49,7 +50,6 @@
49
50
  "command-exists": "^1.2.9",
50
51
  "compression": "^1.7.4",
51
52
  "cors": "^2.8.5",
52
- "cross-fetch": "^3.0.6",
53
53
  "express": "^4.17.1",
54
54
  "express-promise-router": "^4.1.0",
55
55
  "fs-extra": "10.0.0",
@@ -64,21 +64,24 @@
64
64
  "lodash": "^4.17.21",
65
65
  "luxon": "^2.0.2",
66
66
  "morgan": "^1.10.0",
67
+ "node-fetch": "^2.6.1",
67
68
  "nunjucks": "^3.2.3",
68
69
  "octokit-plugin-create-pull-request": "^3.10.0",
69
70
  "uuid": "^8.2.0",
71
+ "vm2": "^3.9.5",
70
72
  "winston": "^3.2.1",
71
73
  "yaml": "^1.10.0"
72
74
  },
73
75
  "devDependencies": {
74
- "@backstage/cli": "^0.8.1",
75
- "@backstage/test-utils": "^0.1.20",
76
+ "@backstage/cli": "^0.10.0",
77
+ "@backstage/test-utils": "^0.1.23",
76
78
  "@types/command-exists": "^1.2.0",
77
79
  "@types/fs-extra": "^9.0.1",
78
80
  "@types/git-url-parse": "^9.0.0",
79
81
  "@types/mock-fs": "^4.13.0",
80
82
  "@types/nunjucks": "^3.1.4",
81
83
  "@types/supertest": "^2.0.8",
84
+ "esbuild": "^0.13.14",
82
85
  "jest-when": "^3.1.0",
83
86
  "mock-fs": "^5.1.0",
84
87
  "msw": "^0.35.0",
@@ -88,8 +91,9 @@
88
91
  "files": [
89
92
  "dist",
90
93
  "migrations",
91
- "config.d.ts"
94
+ "config.d.ts",
95
+ "assets"
92
96
  ],
93
97
  "configSchema": "config.d.ts",
94
- "gitHead": "3db0cb3683d3000666802af90a465ba4fb0d1e8d"
98
+ "gitHead": "a05e7081b805006e3f0b2960a08a7753357f532f"
95
99
  }