diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/TemplateActionRegistry.ts b/plugins/scaffolder-backend/src/scaffolder/actions/TemplateActionRegistry.ts similarity index 100% rename from plugins/scaffolder-backend/src/scaffolder/tasks/TemplateActionRegistry.ts rename to plugins/scaffolder-backend/src/scaffolder/actions/TemplateActionRegistry.ts diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/builtin.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin.ts similarity index 100% rename from plugins/scaffolder-backend/src/scaffolder/tasks/builtin.ts rename to plugins/scaffolder-backend/src/scaffolder/actions/builtin.ts diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/index.ts b/plugins/scaffolder-backend/src/scaffolder/actions/index.ts new file mode 100644 index 0000000000..3da406d45a --- /dev/null +++ b/plugins/scaffolder-backend/src/scaffolder/actions/index.ts @@ -0,0 +1,24 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { + createCatalogRegisterAction, + createFetchCookiecutterAction, + createFetchPlainAction, + createPublishGithubAction, +} from './builtin'; +export { TemplateActionRegistry } from './TemplateActionRegistry'; +export type { ActionContext, TemplateAction } from './types'; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/types.ts b/plugins/scaffolder-backend/src/scaffolder/actions/types.ts new file mode 100644 index 0000000000..aed91e35f8 --- /dev/null +++ b/plugins/scaffolder-backend/src/scaffolder/actions/types.ts @@ -0,0 +1,43 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Logger } from 'winston'; +import { Writable } from 'stream'; +import { JsonValue } from '@backstage/config'; + +export type ActionContext = { + /** + * Base URL for the location of the task spec, typically the url of the source entity file. + */ + baseUrl?: string; + + logger: Logger; + logStream: Writable; + + workspacePath: string; + parameters: { [name: string]: JsonValue }; + output(name: string, value: JsonValue): void; + + /** + * Creates a temporary directory for use by the action, which is then cleaned up automatically. + */ + createTemporaryDirectory(): Promise; +}; + +export type TemplateAction = { + id: string; + handler: (ctx: ActionContext) => Promise; +}; diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/legacy.ts b/plugins/scaffolder-backend/src/scaffolder/stages/legacy.ts index 4b3a0d8610..5f2d6a47a8 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/legacy.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/legacy.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TemplateActionRegistry } from '../tasks/TemplateActionRegistry'; +import { TemplateActionRegistry } from '../actions/TemplateActionRegistry'; import { FilePreparer, PreparerBuilder } from './prepare'; import Docker from 'dockerode'; import { TemplaterBuilder, TemplaterValues } from './templater'; diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts index 1e038ba65e..357e5e815c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts @@ -21,7 +21,7 @@ import { JsonValue, JsonObject } from '@backstage/config'; import { TaskBroker, Task } from './types'; import fs from 'fs-extra'; import path from 'path'; -import { TemplateActionRegistry } from './TemplateActionRegistry'; +import { TemplateActionRegistry } from '../actions/TemplateActionRegistry'; import * as handlebars from 'handlebars'; type Options = { diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/types.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/types.ts index 42d8179a3e..3a1d207a04 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/types.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/types.ts @@ -15,8 +15,6 @@ */ import { JsonValue, JsonObject } from '@backstage/config'; -import { Logger } from 'winston'; -import { Writable } from 'stream'; export type Status = | 'open' @@ -93,6 +91,7 @@ export type TaskStoreGetEventsOptions = { taskId: string; after?: number | undefined; }; + export interface TaskStore { createTask(task: TaskSpec): Promise<{ taskId: string }>; getTask(taskId: string): Promise; @@ -115,27 +114,3 @@ export interface TaskStore { after, }: TaskStoreGetEventsOptions): Promise<{ events: DbTaskEventRow[] }>; } - -export type ActionContext = { - /** - * Base URL for the location of the task spec, typically the url of the source entity file. - */ - baseUrl?: string; - - logger: Logger; - logStream: Writable; - - workspacePath: string; - parameters: { [name: string]: JsonValue }; - output(name: string, value: JsonValue): void; - - /** - * Creates a temporary directory for use by the action, which is then cleaned up automatically. - */ - createTemporaryDirectory(): Promise; -}; - -export type TemplateAction = { - id: string; - handler: (ctx: ActionContext) => Promise; -}; diff --git a/plugins/scaffolder-backend/src/service/router.ts b/plugins/scaffolder-backend/src/service/router.ts index 3cc8d01238..f30cb9ce3a 100644 --- a/plugins/scaffolder-backend/src/service/router.ts +++ b/plugins/scaffolder-backend/src/service/router.ts @@ -39,7 +39,7 @@ import { TaskWorker, } from '../scaffolder/tasks'; import { templateEntityToSpec } from '../scaffolder/tasks/TemplateConverter'; -import { TemplateActionRegistry } from '../scaffolder/tasks/TemplateActionRegistry'; +import { TemplateActionRegistry } from '../scaffolder/actions/TemplateActionRegistry'; import { registerLegacyActions } from '../scaffolder/stages/legacy'; import { getEntityBaseUrl, getWorkingDirectory } from './helpers'; import { @@ -59,7 +59,7 @@ import { createFetchCookiecutterAction, createPublishGithubAction, createCatalogRegisterAction, -} from '../scaffolder/tasks/builtin'; +} from '../scaffolder/actions/builtin'; import { ScmIntegrations } from '@backstage/integration'; export interface RouterOptions {