Merge pull request #15854 from backstage/freben/scaffolder-node

create new package scaffolder-node
This commit is contained in:
Fredrik Adelöw
2023-01-23 10:56:28 +01:00
committed by GitHub
83 changed files with 504 additions and 178 deletions
@@ -8,7 +8,7 @@
import { ContainerRunner } from '@backstage/backend-common';
import { JsonObject } from '@backstage/types';
import { ScmIntegrations } from '@backstage/integration';
import { TemplateAction } from '@backstage/plugin-scaffolder-backend';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { UrlReader } from '@backstage/backend-common';
// @public
@@ -28,6 +28,7 @@
"@backstage/errors": "workspace:^",
"@backstage/integration": "workspace:^",
"@backstage/plugin-scaffolder-backend": "workspace:^",
"@backstage/plugin-scaffolder-node": "workspace:^",
"@backstage/types": "workspace:^",
"command-exists": "^1.2.9",
"fs-extra": "10.1.0",
@@ -27,7 +27,7 @@ import os from 'os';
import { PassThrough } from 'stream';
import { createFetchCookiecutterAction } from './cookiecutter';
import { join } from 'path';
import type { ActionContext } from '@backstage/plugin-scaffolder-backend';
import type { ActionContext } from '@backstage/plugin-scaffolder-node';
const executeShellCommand = jest.fn();
const commandExists = jest.fn();
@@ -27,10 +27,10 @@ import fs from 'fs-extra';
import path, { resolve as resolvePath } from 'path';
import { Writable } from 'stream';
import {
createTemplateAction,
fetchContents,
executeShellCommand,
} from '@backstage/plugin-scaffolder-backend';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
export class CookiecutterRunner {
private readonly containerRunner: ContainerRunner;
@@ -6,7 +6,7 @@
import { ContainerRunner } from '@backstage/backend-common';
import { JsonObject } from '@backstage/types';
import { ScmIntegrations } from '@backstage/integration';
import { TemplateAction } from '@backstage/plugin-scaffolder-backend';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { UrlReader } from '@backstage/backend-common';
// @public
@@ -28,6 +28,7 @@
"@backstage/errors": "workspace:^",
"@backstage/integration": "workspace:^",
"@backstage/plugin-scaffolder-backend": "workspace:^",
"@backstage/plugin-scaffolder-node": "workspace:^",
"@backstage/types": "workspace:^",
"command-exists": "^1.2.9",
"fs-extra": "^10.0.1"
@@ -19,10 +19,8 @@ import { JsonObject } from '@backstage/types';
import { InputError } from '@backstage/errors';
import { ScmIntegrations } from '@backstage/integration';
import fs from 'fs-extra';
import {
createTemplateAction,
fetchContents,
} from '@backstage/plugin-scaffolder-backend';
import { fetchContents } from '@backstage/plugin-scaffolder-backend';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { resolve as resolvePath } from 'path';
import { RailsNewRunner } from './railsNewRunner';
@@ -4,7 +4,7 @@
```ts
import { Config } from '@backstage/config';
import { TemplateAction } from '@backstage/plugin-scaffolder-backend';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
// @public
export function createSentryCreateProjectAction(options: {
@@ -25,7 +25,7 @@
"@backstage/config": "workspace:^",
"@backstage/errors": "workspace:^",
"@backstage/integration": "workspace:^",
"@backstage/plugin-scaffolder-backend": "workspace:^"
"@backstage/plugin-scaffolder-node": "workspace:^"
},
"peerDependencies": {
"react": "^16.13.1 || ^17.0.0"
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { createTemplateAction } from '@backstage/plugin-scaffolder-backend';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { InputError } from '@backstage/errors';
import { Config } from '@backstage/config';
@@ -4,7 +4,7 @@
```ts
import { JsonObject } from '@backstage/types';
import { TemplateAction } from '@backstage/plugin-scaffolder-backend';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
// @public
export function createRunYeomanAction(): TemplateAction<{
@@ -23,7 +23,7 @@
},
"dependencies": {
"@backstage/config": "workspace:^",
"@backstage/plugin-scaffolder-backend": "workspace:^",
"@backstage/plugin-scaffolder-node": "workspace:^",
"@backstage/types": "workspace:^",
"winston": "^3.2.1",
"yeoman-environment": "^3.9.1"
@@ -22,7 +22,7 @@ import { getVoidLogger } from '@backstage/backend-common';
import os from 'os';
import { PassThrough } from 'stream';
import { createRunYeomanAction } from './yeoman';
import type { ActionContext } from '@backstage/plugin-scaffolder-backend';
import type { ActionContext } from '@backstage/plugin-scaffolder-node';
import { JsonObject } from '@backstage/types';
describe('run:yeoman', () => {
@@ -15,7 +15,7 @@
*/
import { JsonObject } from '@backstage/types';
import { createTemplateAction } from '@backstage/plugin-scaffolder-backend';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { yeomanRun } from './yeomanRun';
/**
+48 -76
View File
@@ -5,6 +5,7 @@
```ts
/// <reference types="node" />
import { ActionContext as ActionContext_2 } from '@backstage/plugin-scaffolder-node';
import { BackendFeature } from '@backstage/backend-plugin-api';
import { CatalogApi } from '@backstage/catalog-client';
import { CatalogProcessor } from '@backstage/plugin-catalog-backend';
@@ -24,38 +25,23 @@ import { Observable } from '@backstage/types';
import { Octokit } from 'octokit';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { PluginTaskScheduler } from '@backstage/backend-tasks';
import { Schema } from 'jsonschema';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { ScmIntegrations } from '@backstage/integration';
import { SpawnOptionsWithoutStdio } from 'child_process';
import { TaskSecrets as TaskSecrets_2 } from '@backstage/plugin-scaffolder-node';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { TaskSpecV1beta3 } from '@backstage/plugin-scaffolder-common';
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
import { TemplateAction as TemplateAction_2 } from '@backstage/plugin-scaffolder-node';
import { UrlReader } from '@backstage/backend-common';
import { UserEntity } from '@backstage/catalog-model';
import { Writable } from 'stream';
// @public
export type ActionContext<Input extends JsonObject> = {
logger: Logger;
logStream: Writable;
secrets?: TaskSecrets;
workspacePath: string;
input: Input;
output(name: string, value: JsonValue): void;
createTemporaryDirectory(): Promise<string>;
templateInfo?: TemplateInfo;
isDryRun?: boolean;
user?: {
entity?: UserEntity;
ref?: string;
};
};
// @public @deprecated (undocumented)
export type ActionContext<TInput extends JsonObject> = ActionContext_2<TInput>;
// @public
export const createBuiltinActions: (
options: CreateBuiltInActionsOptions,
) => TemplateAction<JsonObject>[];
) => TemplateAction_2<JsonObject>[];
// @public
export interface CreateBuiltInActionsOptions {
@@ -72,7 +58,7 @@ export interface CreateBuiltInActionsOptions {
export function createCatalogRegisterAction(options: {
catalogClient: CatalogApi;
integrations: ScmIntegrations;
}): TemplateAction<
}): TemplateAction_2<
| {
catalogInfoUrl: string;
optional?: boolean | undefined;
@@ -85,13 +71,13 @@ export function createCatalogRegisterAction(options: {
>;
// @public
export function createCatalogWriteAction(): TemplateAction<{
export function createCatalogWriteAction(): TemplateAction_2<{
filePath?: string | undefined;
entity: Entity;
}>;
// @public
export function createDebugLogAction(): TemplateAction<{
export function createDebugLogAction(): TemplateAction_2<{
message?: string | undefined;
listWorkspace?: boolean | undefined;
}>;
@@ -99,7 +85,7 @@ export function createDebugLogAction(): TemplateAction<{
// @public
export function createFetchCatalogEntityAction(options: {
catalogClient: CatalogApi;
}): TemplateAction<{
}): TemplateAction_2<{
entityRef: string;
optional?: boolean | undefined;
}>;
@@ -108,7 +94,7 @@ export function createFetchCatalogEntityAction(options: {
export function createFetchPlainAction(options: {
reader: UrlReader;
integrations: ScmIntegrations;
}): TemplateAction<{
}): TemplateAction_2<{
url: string;
targetPath?: string | undefined;
}>;
@@ -119,7 +105,7 @@ export function createFetchTemplateAction(options: {
integrations: ScmIntegrations;
additionalTemplateFilters?: Record<string, TemplateFilter>;
additionalTemplateGlobals?: Record<string, TemplateGlobal>;
}): TemplateAction<{
}): TemplateAction_2<{
url: string;
targetPath?: string | undefined;
values: any;
@@ -131,12 +117,12 @@ export function createFetchTemplateAction(options: {
}>;
// @public
export const createFilesystemDeleteAction: () => TemplateAction<{
export const createFilesystemDeleteAction: () => TemplateAction_2<{
files: string[];
}>;
// @public
export const createFilesystemRenameAction: () => TemplateAction<{
export const createFilesystemRenameAction: () => TemplateAction_2<{
files: Array<{
from: string;
to: string;
@@ -148,7 +134,7 @@ export const createFilesystemRenameAction: () => TemplateAction<{
export function createGithubActionsDispatchAction(options: {
integrations: ScmIntegrations;
githubCredentialsProvider?: GithubCredentialsProvider;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
workflowId: string;
branchOrTagName: string;
@@ -164,7 +150,7 @@ export function createGithubActionsDispatchAction(options: {
export function createGithubIssuesLabelAction(options: {
integrations: ScmIntegrationRegistry;
githubCredentialsProvider?: GithubCredentialsProvider;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
number: number;
labels: string[];
@@ -194,7 +180,7 @@ export type CreateGithubPullRequestClientFactoryInput = {
export function createGithubRepoCreateAction(options: {
integrations: ScmIntegrationRegistry;
githubCredentialsProvider?: GithubCredentialsProvider;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
description?: string | undefined;
homepage?: string | undefined;
@@ -261,7 +247,7 @@ export function createGithubRepoPushAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
githubCredentialsProvider?: GithubCredentialsProvider;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
description?: string | undefined;
defaultBranch?: string | undefined;
@@ -300,7 +286,7 @@ export function createGithubWebhookAction(options: {
integrations: ScmIntegrationRegistry;
defaultWebhookSecret?: string;
githubCredentialsProvider?: GithubCredentialsProvider;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
webhookUrl: string;
webhookSecret?: string | undefined;
@@ -315,7 +301,7 @@ export function createGithubWebhookAction(options: {
export function createPublishAzureAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
description?: string | undefined;
defaultBranch?: string | undefined;
@@ -330,7 +316,7 @@ export function createPublishAzureAction(options: {
export function createPublishBitbucketAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
description?: string | undefined;
defaultBranch?: string | undefined;
@@ -347,7 +333,7 @@ export function createPublishBitbucketAction(options: {
export function createPublishBitbucketCloudAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
description?: string | undefined;
defaultBranch?: string | undefined;
@@ -360,7 +346,7 @@ export function createPublishBitbucketCloudAction(options: {
export function createPublishBitbucketServerAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
description?: string | undefined;
defaultBranch?: string | undefined;
@@ -377,7 +363,7 @@ export function createPublishBitbucketServerAction(options: {
export function createPublishGerritAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
description: string;
defaultBranch?: string | undefined;
@@ -391,7 +377,7 @@ export function createPublishGerritAction(options: {
export function createPublishGerritReviewAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
branch?: string | undefined;
sourcePath?: string | undefined;
@@ -405,7 +391,7 @@ export function createPublishGithubAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
githubCredentialsProvider?: GithubCredentialsProvider;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
description?: string | undefined;
homepage?: string | undefined;
@@ -478,7 +464,7 @@ export const createPublishGithubPullRequestAction: ({
integrations,
githubCredentialsProvider,
clientFactory,
}: CreateGithubPullRequestActionOptions) => TemplateAction<{
}: CreateGithubPullRequestActionOptions) => TemplateAction_2<{
title: string;
branchName: string;
description: string;
@@ -495,7 +481,7 @@ export const createPublishGithubPullRequestAction: ({
export function createPublishGitlabAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
}): TemplateAction<{
}): TemplateAction_2<{
repoUrl: string;
defaultBranch?: string | undefined;
repoVisibility?: 'internal' | 'private' | 'public' | undefined;
@@ -511,7 +497,7 @@ export function createPublishGitlabAction(options: {
// @public
export const createPublishGitlabMergeRequestAction: (options: {
integrations: ScmIntegrationRegistry;
}) => TemplateAction<{
}) => TemplateAction_2<{
repoUrl: string;
title: string;
description: string;
@@ -528,10 +514,10 @@ export const createPublishGitlabMergeRequestAction: (options: {
// @public
export function createRouter(options: RouterOptions): Promise<express.Router>;
// @public
// @public @deprecated (undocumented)
export const createTemplateAction: <TInput extends JsonObject>(
templateAction: TemplateAction<TInput>,
) => TemplateAction<TInput>;
templateAction: TemplateAction_2<TInput>,
) => TemplateAction_2<TInput>;
// @public
export type CreateWorkerOptions = {
@@ -548,7 +534,7 @@ export type CreateWorkerOptions = {
// @public
export interface CurrentClaimedTask {
createdBy?: string;
secrets?: TaskSecrets;
secrets?: TaskSecrets_2;
spec: TaskSpec;
taskId: string;
}
@@ -629,7 +615,7 @@ export type OctokitWithPullRequestPluginClient = Octokit & {
// @public
export interface RouterOptions {
// (undocumented)
actions?: TemplateAction<any>[];
actions?: TemplateAction_2<any>[];
// (undocumented)
additionalTemplateFilters?: Record<string, TemplateFilter>;
// (undocumented)
@@ -687,7 +673,7 @@ export const scaffolderPlugin: (
// @alpha
export type ScaffolderPluginOptions = {
actions?: TemplateAction<any>[];
actions?: TemplateAction_2<any>[];
taskWorkers?: number;
taskBroker?: TaskBroker;
additionalTemplateFilters?: Record<string, TemplateFilter>;
@@ -702,7 +688,7 @@ export type SerializedTask = {
createdAt: string;
lastHeartbeatAt?: string;
createdBy?: string;
secrets?: TaskSecrets;
secrets?: TaskSecrets_2;
};
// @public
@@ -739,7 +725,7 @@ export interface TaskBroker {
// @public
export type TaskBrokerDispatchOptions = {
spec: TaskSpec;
secrets?: TaskSecrets;
secrets?: TaskSecrets_2;
createdBy?: string;
};
@@ -766,7 +752,7 @@ export interface TaskContext {
// (undocumented)
isDryRun?: boolean;
// (undocumented)
secrets?: TaskSecrets;
secrets?: TaskSecrets_2;
// (undocumented)
spec: TaskSpec;
}
@@ -793,15 +779,13 @@ export class TaskManager implements TaskContext {
// (undocumented)
getWorkspaceName(): Promise<string>;
// (undocumented)
get secrets(): TaskSecrets | undefined;
get secrets(): TaskSecrets_2 | undefined;
// (undocumented)
get spec(): TaskSpecV1beta3;
}
// @public
export type TaskSecrets = Record<string, string> & {
backstageToken?: string;
};
// @public @deprecated (undocumented)
export type TaskSecrets = TaskSecrets_2;
// @public
export type TaskStatus =
@@ -853,7 +837,7 @@ export interface TaskStore {
export type TaskStoreCreateTaskOptions = {
spec: TaskSpec;
createdBy?: string;
secrets?: TaskSecrets;
secrets?: TaskSecrets_2;
};
// @public
@@ -890,30 +874,18 @@ export class TaskWorker {
start(): void;
}
// @public (undocumented)
export type TemplateAction<Input extends JsonObject> = {
id: string;
description?: string;
examples?: {
description: string;
example: string;
}[];
supportsDryRun?: boolean;
schema?: {
input?: Schema;
output?: Schema;
};
handler: (ctx: ActionContext<Input>) => Promise<void>;
};
// @public @deprecated (undocumented)
export type TemplateAction<TInput extends JsonObject> =
TemplateAction_2<TInput>;
// @public
export class TemplateActionRegistry {
// (undocumented)
get(actionId: string): TemplateAction<JsonObject>;
get(actionId: string): TemplateAction_2<JsonObject>;
// (undocumented)
list(): TemplateAction<JsonObject>[];
list(): TemplateAction_2<JsonObject>[];
// (undocumented)
register<TInput extends JsonObject>(action: TemplateAction<TInput>): void;
register<TInput extends JsonObject>(action: TemplateAction_2<TInput>): void;
}
// @public (undocumented)
+1
View File
@@ -46,6 +46,7 @@
"@backstage/plugin-catalog-backend": "workspace:^",
"@backstage/plugin-catalog-node": "workspace:^",
"@backstage/plugin-scaffolder-common": "workspace:^",
"@backstage/plugin-scaffolder-node": "workspace:^",
"@backstage/types": "workspace:^",
"@gitbeaker/core": "^35.6.0",
"@gitbeaker/node": "^35.1.0",
@@ -13,20 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
createBackendPlugin,
coreServices,
createExtensionPoint,
} from '@backstage/backend-plugin-api';
import { loggerToWinstonLogger } from '@backstage/backend-common';
import { ScmIntegrations } from '@backstage/integration';
import { catalogServiceRef } from '@backstage/plugin-catalog-node';
import {
scaffolderActionsExtensionPoint,
ScaffolderActionsExtensionPoint,
TemplateAction,
} from '@backstage/plugin-scaffolder-node';
import { TemplateFilter, TemplateGlobal } from './lib';
import { createBuiltinActions, TaskBroker, TemplateAction } from './scaffolder';
import { createBuiltinActions, TaskBroker } from './scaffolder';
import { createRouter } from './service/router';
/**
* Catalog plugin options
*
* @alpha
*/
export type ScaffolderPluginOptions = {
@@ -37,37 +43,23 @@ export type ScaffolderPluginOptions = {
additionalTemplateGlobals?: Record<string, TemplateGlobal>;
};
/**
* @alpha
* TODO: MOVE to scaffolder-node.
*/
interface ScaffolderActionsExtensionPoint {
addActions(...actions: TemplateAction<any>[]): void;
}
class ScaffolderActionsExtensionPointImpl
implements ScaffolderActionsExtensionPoint
{
#actions = new Array<TemplateAction<any>>();
addActions(...actions: TemplateAction<any>[]): void {
this.#actions.push(...actions);
}
get actions() {
return this.#actions;
}
}
/**
* @alpha
* TODO: MOVE to scaffolder-node.
*/
export const scaffolderActionsExtensionPoint =
createExtensionPoint<ScaffolderActionsExtensionPoint>({
id: 'scaffolder.actions',
});
/**
* Catalog plugin
*
* @alpha
*/
export const scaffolderPlugin = createBackendPlugin(
@@ -75,6 +67,7 @@ export const scaffolderPlugin = createBackendPlugin(
id: 'scaffolder',
register(env) {
const actionsExtensions = new ScaffolderActionsExtensionPointImpl();
env.registerExtensionPoint(
scaffolderActionsExtensionPoint,
actionsExtensions,
@@ -0,0 +1,49 @@
/*
* Copyright 2023 The Backstage Authors
*
* 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 {
ActionContext as ActionContextNode,
createTemplateAction as createTemplateActionNode,
TaskSecrets as TaskSecretsNode,
TemplateAction as TemplateActionNode,
} from '@backstage/plugin-scaffolder-node';
import { JsonObject } from '@backstage/types';
/**
* @public
* @deprecated Import from {@link @backstage/plugin-scaffolder-node#ActionContext} instead
*/
export type ActionContext<TInput extends JsonObject> =
ActionContextNode<TInput>;
/**
* @public
* @deprecated Use `createTemplateAction` from `@backstage/plugin-scaffolder-node` instead
*/
export const createTemplateAction = createTemplateActionNode;
/**
* @public
* @deprecated Use `TaskSecrets` from `@backstage/plugin-scaffolder-node` instead
*/
export type TaskSecrets = TaskSecretsNode;
/**
* @public
* @deprecated Use `TemplateAction` from `@backstage/plugin-scaffolder-node` instead
*/
export type TemplateAction<TInput extends JsonObject> =
TemplateActionNode<TInput>;
+2
View File
@@ -27,3 +27,5 @@ export * from './processor';
export * from './extension';
export { scaffolderPlugin } from './ScaffolderPlugin';
export type { ScaffolderPluginOptions } from './ScaffolderPlugin';
export * from './deprecated';
@@ -16,7 +16,7 @@
import { JsonObject } from '@backstage/types';
import { ConflictError, NotFoundError } from '@backstage/errors';
import { TemplateAction } from './types';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
/**
* Registry of all registered template actions.
@@ -15,7 +15,7 @@
*/
import { CatalogApi } from '@backstage/catalog-client';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import yaml from 'yaml';
const id = 'catalog:fetch';
@@ -18,7 +18,7 @@ import { InputError } from '@backstage/errors';
import { ScmIntegrations } from '@backstage/integration';
import { CatalogApi } from '@backstage/catalog-client';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import yaml from 'yaml';
const id = 'catalog:register';
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import * as yaml from 'yaml';
import { Entity } from '@backstage/catalog-model';
import { resolveSafeChildPath } from '@backstage/backend-common';
@@ -23,6 +23,7 @@ import {
ScmIntegrations,
} from '@backstage/integration';
import { JsonObject } from '@backstage/types';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import {
createCatalogRegisterAction,
createCatalogWriteAction,
@@ -30,7 +31,6 @@ import {
} from './catalog';
import { TemplateFilter, TemplateGlobal } from '../../../lib';
import { TemplateAction } from '../types';
import { createDebugLogAction } from './debug';
import { createFetchPlainAction, createFetchTemplateAction } from './fetch';
import {
@@ -16,7 +16,7 @@
import { readdir, stat } from 'fs-extra';
import { relative, join } from 'path';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import yaml from 'yaml';
const id = 'debug:log';
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
jest.mock('./helpers');
import os from 'os';
@@ -17,7 +17,7 @@
import { UrlReader, resolveSafeChildPath } from '@backstage/backend-common';
import { ScmIntegrations } from '@backstage/integration';
import { fetchContents } from './helpers';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
/**
* Downloads content and places it in the workspace, or optionally
@@ -26,8 +26,11 @@ import {
import { ScmIntegrations } from '@backstage/integration';
import { PassThrough } from 'stream';
import { fetchContents } from './helpers';
import { ActionContext, TemplateAction } from '../../types';
import { createFetchTemplateAction } from './template';
import {
ActionContext,
TemplateAction,
} from '@backstage/plugin-scaffolder-node';
jest.mock('./helpers', () => ({
fetchContents: jest.fn(),
@@ -19,7 +19,7 @@ import { resolveSafeChildPath, UrlReader } from '@backstage/backend-common';
import { InputError } from '@backstage/errors';
import { ScmIntegrations } from '@backstage/integration';
import { fetchContents } from './helpers';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import globby from 'globby';
import fs from 'fs-extra';
import { isBinaryFile } from 'isbinaryfile';
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { InputError } from '@backstage/errors';
import { resolveSafeChildPath } from '@backstage/backend-common';
import fs from 'fs-extra';
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createTemplateAction } from '../../createTemplateAction';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { InputError } from '@backstage/errors';
import fs from 'fs-extra';
@@ -14,9 +14,6 @@
* limitations under the License.
*/
import { TemplateAction } from '../../types';
import { createGithubActionsDispatchAction } from './githubActionsDispatch';
import {
ScmIntegrations,
DefaultGithubCredentialsProvider,
@@ -24,7 +21,9 @@ import {
} from '@backstage/integration';
import { ConfigReader } from '@backstage/config';
import { getVoidLogger } from '@backstage/backend-common';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { PassThrough } from 'stream';
import { createGithubActionsDispatchAction } from './githubActionsDispatch';
const mockOctokit = {
rest: {
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { InputError } from '@backstage/errors';
import {
GithubCredentialsProvider,
ScmIntegrations,
} from '@backstage/integration';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { Octokit } from 'octokit';
import { createTemplateAction } from '../../createTemplateAction';
import { parseRepoUrl } from '../publish/util';
import { getOctokitOptions } from './helpers';
@@ -22,8 +22,8 @@ import {
} from '@backstage/integration';
import { ConfigReader } from '@backstage/config';
import { getVoidLogger } from '@backstage/backend-common';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { PassThrough } from 'stream';
import { TemplateAction } from '../../types';
const mockOctokit = {
rest: {
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
GithubCredentialsProvider,
ScmIntegrationRegistry,
} from '@backstage/integration';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { assertError, InputError } from '@backstage/errors';
import { Octokit } from 'octokit';
import { getOctokitOptions } from './helpers';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { TemplateAction } from '../../types';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
jest.mock('../helpers');
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { InputError } from '@backstage/errors';
import {
GithubCredentialsProvider,
ScmIntegrationRegistry,
} from '@backstage/integration';
import { Octokit } from 'octokit';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { parseRepoUrl } from '../publish/util';
import {
createGithubRepoWithCollaboratorsAndTopics,
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { TemplateAction } from '../../types';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
jest.mock('../helpers');
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Config } from '@backstage/config';
import { InputError } from '@backstage/errors';
import {
@@ -20,7 +21,7 @@ import {
ScmIntegrationRegistry,
} from '@backstage/integration';
import { Octokit } from 'octokit';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { parseRepoUrl } from '../publish/util';
import { getOctokitOptions, initRepoPushAndProtect } from './helpers';
import * as inputProps from './inputProperties';
@@ -22,8 +22,8 @@ import {
} from '@backstage/integration';
import { ConfigReader } from '@backstage/config';
import { getVoidLogger } from '@backstage/backend-common';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { PassThrough } from 'stream';
import { TemplateAction } from '../../types';
const mockOctokit = {
rest: {
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
GithubCredentialsProvider,
ScmIntegrationRegistry,
} from '@backstage/integration';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { emitterEventNames } from '@octokit/webhooks';
import { assertError, InputError } from '@backstage/errors';
import { Octokit } from 'octokit';
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
jest.mock('azure-devops-node-api', () => ({
WebApi: jest.fn(),
getPersonalAccessTokenHandler: jest.fn().mockReturnValue(() => {}),
@@ -20,7 +20,7 @@ import { initRepoAndPush } from '../helpers';
import { GitRepositoryCreateOptions } from 'azure-devops-node-api/interfaces/GitInterfaces';
import { getPersonalAccessTokenHandler, WebApi } from 'azure-devops-node-api';
import { getRepoSourceDirectory, parseRepoUrl } from './util';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { Config } from '@backstage/config';
/**
@@ -19,9 +19,9 @@ import {
BitbucketIntegrationConfig,
ScmIntegrationRegistry,
} from '@backstage/integration';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import fetch, { Response, RequestInit } from 'node-fetch';
import { initRepoAndPush } from '../helpers';
import { createTemplateAction } from '../../createTemplateAction';
import { getRepoSourceDirectory, parseRepoUrl } from './util';
import { Config } from '@backstage/config';
@@ -16,9 +16,9 @@
import { InputError } from '@backstage/errors';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import fetch, { Response, RequestInit } from 'node-fetch';
import { initRepoAndPush } from '../helpers';
import { createTemplateAction } from '../../createTemplateAction';
import { getRepoSourceDirectory, parseRepoUrl } from './util';
import { Config } from '@backstage/config';
@@ -19,9 +19,9 @@ import {
getBitbucketServerRequestOptions,
ScmIntegrationRegistry,
} from '@backstage/integration';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import fetch, { Response, RequestInit } from 'node-fetch';
import { initRepoAndPush } from '../helpers';
import { createTemplateAction } from '../../createTemplateAction';
import { getRepoSourceDirectory, parseRepoUrl } from './util';
import { Config } from '@backstage/config';
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import crypto from 'crypto';
import { InputError } from '@backstage/errors';
import { Config } from '@backstage/config';
@@ -21,7 +22,7 @@ import {
getGerritRequestOptions,
ScmIntegrationRegistry,
} from '@backstage/integration';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { getRepoSourceDirectory, parseRepoUrl } from './util';
import fetch, { Response, RequestInit } from 'node-fetch';
import { initRepoAndPush } from '../helpers';
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import crypto from 'crypto';
import { InputError } from '@backstage/errors';
import { Config } from '@backstage/config';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { getRepoSourceDirectory, parseRepoUrl } from './util';
import { commitAndPushRepo } from '../helpers';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { TemplateAction } from '../../types';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
jest.mock('../helpers');
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Config } from '@backstage/config';
import { InputError } from '@backstage/errors';
import {
@@ -20,7 +21,7 @@ import {
ScmIntegrationRegistry,
} from '@backstage/integration';
import { Octokit } from 'octokit';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import {
createGithubRepoWithCollaboratorsAndTopics,
getOctokitOptions,
@@ -20,11 +20,14 @@ import {
GithubCredentialsProvider,
ScmIntegrations,
} from '@backstage/integration';
import {
ActionContext,
TemplateAction,
} from '@backstage/plugin-scaffolder-node';
import mockFs from 'mock-fs';
import os from 'os';
import { resolve as resolvePath } from 'path';
import { Writable } from 'stream';
import { ActionContext, TemplateAction } from '../../types';
import {
createPublishGithubPullRequestAction,
OctokitWithPullRequestPluginClient,
@@ -20,11 +20,11 @@ import {
GithubCredentialsProvider,
ScmIntegrationRegistry,
} from '@backstage/integration';
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { Octokit } from 'octokit';
import { InputError, CustomErrorBase } from '@backstage/errors';
import { createPullRequest } from 'octokit-plugin-create-pull-request';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { createPullRequest } from 'octokit-plugin-create-pull-request';
import { getOctokitOptions } from '../github/helpers';
import {
SerializedFile,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
jest.mock('../helpers');
import { createPublishGitlabAction } from './gitlab';
@@ -16,10 +16,10 @@
import { InputError } from '@backstage/errors';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { Gitlab } from '@gitbeaker/node';
import { initRepoAndPush } from '../helpers';
import { getRepoSourceDirectory, parseRepoUrl } from './util';
import { createTemplateAction } from '../../createTemplateAction';
import { Config } from '@backstage/config';
/**
@@ -16,11 +16,11 @@
import { getRootLogger } from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import { ScmIntegrations } from '@backstage/integration';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import mockFs from 'mock-fs';
import os from 'os';
import { resolve as resolvePath } from 'path';
import { Writable } from 'stream';
import { TemplateAction } from '../../types';
import { createPublishGitlabMergeRequestAction } from './gitlabMergeRequest';
const root = os.platform() === 'win32' ? 'C:\\root' : '/root';
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createTemplateAction } from '../../createTemplateAction';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { Gitlab } from '@gitbeaker/node';
import { Types } from '@gitbeaker/core';
import path from 'path';
@@ -16,5 +16,3 @@
export * from './builtin';
export { TemplateActionRegistry } from './TemplateActionRegistry';
export { createTemplateAction } from './createTemplateAction';
export type { ActionContext, TemplateAction } from './types';
@@ -14,8 +14,9 @@
* limitations under the License.
*/
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { JsonObject } from '@backstage/types';
import { TemplateAction, TemplateActionRegistry } from '../actions';
import { TemplateActionRegistry } from '../actions';
/** @internal */
export class DecoratedActionsRegistry extends TemplateActionRegistry {
@@ -26,12 +26,15 @@ import {
serializeDirectoryContents,
} from '../../lib/files';
import { TemplateFilter, TemplateGlobal } from '../../lib/templating';
import { createTemplateAction, TemplateActionRegistry } from '../actions';
import { TemplateActionRegistry } from '../actions';
import { NunjucksWorkflowRunner } from '../tasks/NunjucksWorkflowRunner';
import { TaskSecrets } from '../tasks/types';
import { DecoratedActionsRegistry } from './DecoratedActionsRegistry';
import fs from 'fs-extra';
import { resolveSafeChildPath } from '@backstage/backend-common';
import {
createTemplateAction,
TaskSecrets,
} from '@backstage/plugin-scaffolder-node';
interface DryRunInput {
spec: TaskSpec;
@@ -22,8 +22,9 @@ import { NunjucksWorkflowRunner } from './NunjucksWorkflowRunner';
import { TemplateActionRegistry } from '../actions';
import { ScmIntegrations } from '@backstage/integration';
import { ConfigReader } from '@backstage/config';
import { TaskContext, TaskSecrets } from './types';
import { TaskContext } from './types';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { TaskSecrets } from '@backstage/plugin-scaffolder-node';
import { UserEntity } from '@backstage/catalog-model';
// The Stream module is lazy loaded, so make sure it's in the module cache before mocking fs
@@ -26,7 +26,7 @@ import { PassThrough } from 'stream';
import { generateExampleOutput, isTruthy } from './helper';
import { validate as validateJsonSchema } from 'jsonschema';
import { parseRepoUrl } from '../actions/builtin/publish/util';
import { TemplateAction, TemplateActionRegistry } from '../actions';
import { TemplateActionRegistry } from '../actions';
import {
TemplateFilter,
SecureTemplater,
@@ -38,6 +38,7 @@ import {
TaskSpecV1beta3,
TaskStep,
} from '@backstage/plugin-scaffolder-common';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { UserEntity } from '@backstage/catalog-model';
import { createCounterMetric, createHistogramMetric } from '../../util/metrics';
@@ -17,9 +17,10 @@
import { getVoidLogger, DatabaseManager } from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { TaskSecrets } from '@backstage/plugin-scaffolder-node';
import { DatabaseTaskStore } from './DatabaseTaskStore';
import { StorageTaskBroker, TaskManager } from './StorageTaskBroker';
import { TaskSecrets, SerializedTaskEvent } from './types';
import { SerializedTaskEvent } from './types';
async function createStore(): Promise<DatabaseTaskStore> {
const manager = DatabaseManager.fromConfig(
@@ -15,6 +15,7 @@
*/
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { TaskSecrets } from '@backstage/plugin-scaffolder-node';
import { JsonObject, Observable } from '@backstage/types';
import { Logger } from 'winston';
import ObservableImpl from 'zen-observable';
@@ -25,7 +26,6 @@ import {
TaskBrokerDispatchOptions,
TaskCompletionState,
TaskContext,
TaskSecrets,
TaskStore,
} from './types';
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { DatabaseTaskStore } from './DatabaseTaskStore';
export type { DatabaseTaskStoreOptions } from './DatabaseTaskStore';
export { TaskManager } from './StorageTaskBroker';
@@ -20,7 +21,6 @@ export type { CurrentClaimedTask } from './StorageTaskBroker';
export { TaskWorker } from './TaskWorker';
export type { CreateWorkerOptions } from './TaskWorker';
export type {
TaskSecrets,
TaskCompletionState,
TaskStoreEmitOptions,
TaskStoreListEventsOptions,
@@ -16,6 +16,7 @@
import { JsonValue, JsonObject, Observable } from '@backstage/types';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { TaskSecrets } from '@backstage/plugin-scaffolder-node';
/**
* The status of each step of the Task
@@ -71,15 +72,6 @@ export type SerializedTaskEvent = {
createdAt: string;
};
/**
* TaskSecrets
*
* @public
*/
export type TaskSecrets = Record<string, string> & {
backstageToken?: string;
};
/**
* The result of {@link TaskBroker.dispatch}
*
@@ -43,7 +43,6 @@ import {
DatabaseTaskStore,
TaskBroker,
TaskWorker,
TemplateAction,
TemplateActionRegistry,
} from '../scaffolder';
import { createDryRunner } from '../scaffolder/dryrun';
@@ -53,6 +52,7 @@ import {
IdentityApi,
IdentityApiGetIdentityRequest,
} from '@backstage/plugin-auth-node';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
/**
* RouterOptions
+1
View File
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
+3
View File
@@ -0,0 +1,3 @@
# plugin-scaffolder-node
Houses types and utilities for building scaffolder-related modules.
+68
View File
@@ -0,0 +1,68 @@
## API Report File for "@backstage/plugin-scaffolder-node"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
/// <reference types="node" />
import { ExtensionPoint } from '@backstage/backend-plugin-api';
import { JsonObject } from '@backstage/types';
import { JsonValue } from '@backstage/types';
import { Logger } from 'winston';
import { Schema } from 'jsonschema';
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
import { UserEntity } from '@backstage/catalog-model';
import { Writable } from 'stream';
// @public
export type ActionContext<TInput extends JsonObject> = {
logger: Logger;
logStream: Writable;
secrets?: TaskSecrets;
workspacePath: string;
input: TInput;
output(name: string, value: JsonValue): void;
createTemporaryDirectory(): Promise<string>;
templateInfo?: TemplateInfo;
isDryRun?: boolean;
user?: {
entity?: UserEntity;
ref?: string;
};
};
// @public
export const createTemplateAction: <TInput extends JsonObject>(
templateAction: TemplateAction<TInput>,
) => TemplateAction<TInput>;
// @alpha
export interface ScaffolderActionsExtensionPoint {
// (undocumented)
addActions(...actions: TemplateAction<any>[]): void;
}
// @alpha
export const scaffolderActionsExtensionPoint: ExtensionPoint<ScaffolderActionsExtensionPoint>;
// @public
export type TaskSecrets = Record<string, string> & {
backstageToken?: string;
};
// @public (undocumented)
export type TemplateAction<TInput extends JsonObject> = {
id: string;
description?: string;
examples?: {
description: string;
example: string;
}[];
supportsDryRun?: boolean;
schema?: {
input?: Schema;
output?: Schema;
};
handler: (ctx: ActionContext<TInput>) => Promise<void>;
};
```
+41
View File
@@ -0,0 +1,41 @@
{
"name": "@backstage/plugin-scaffolder-node",
"description": "The plugin-scaffolder-node module for @backstage/plugin-scaffolder-backend",
"version": "0.0.0",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"alphaTypes": "dist/index.alpha.d.ts",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"backstage": {
"role": "node-library"
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build --experimental-type-build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/catalog-model": "workspace:^",
"@backstage/plugin-scaffolder-common": "workspace:^",
"@backstage/types": "workspace:^",
"jsonschema": "^1.2.6",
"winston": "^3.2.1"
},
"devDependencies": {
"@backstage/cli": "workspace:^"
},
"files": [
"alpha",
"dist"
]
}
@@ -19,6 +19,7 @@ import { TemplateAction } from './types';
/**
* This function is used to create new template actions to get type safety.
*
* @public
*/
export const createTemplateAction = <TInput extends JsonObject>(
@@ -0,0 +1,18 @@
/*
* Copyright 2023 The Backstage Authors
*
* 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 { createTemplateAction } from './createTemplateAction';
export { type ActionContext, type TemplateAction } from './types';
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Backstage Authors
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ import { Logger } from 'winston';
import { Writable } from 'stream';
import { JsonValue, JsonObject } from '@backstage/types';
import { Schema } from 'jsonschema';
import { TaskSecrets } from '../tasks';
import { TaskSecrets } from '../tasks/types';
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
import { UserEntity } from '@backstage/catalog-model';
@@ -26,12 +26,12 @@ import { UserEntity } from '@backstage/catalog-model';
* ActionContext is passed into scaffolder actions.
* @public
*/
export type ActionContext<Input extends JsonObject> = {
export type ActionContext<TInput extends JsonObject> = {
logger: Logger;
logStream: Writable;
secrets?: TaskSecrets;
workspacePath: string;
input: Input;
input: TInput;
output(name: string, value: JsonValue): void;
/**
@@ -63,7 +63,7 @@ export type ActionContext<Input extends JsonObject> = {
};
/** @public */
export type TemplateAction<Input extends JsonObject> = {
export type TemplateAction<TInput extends JsonObject> = {
id: string;
description?: string;
examples?: { description: string; example: string }[];
@@ -72,5 +72,5 @@ export type TemplateAction<Input extends JsonObject> = {
input?: Schema;
output?: Schema;
};
handler: (ctx: ActionContext<Input>) => Promise<void>;
handler: (ctx: ActionContext<TInput>) => Promise<void>;
};
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright 2022 The Backstage Authors
*
* 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 { createExtensionPoint } from '@backstage/backend-plugin-api';
import { TemplateAction } from './actions';
/**
* Extension point for managing scaffolder actions.
*
* @alpha
*/
export interface ScaffolderActionsExtensionPoint {
addActions(...actions: TemplateAction<any>[]): void;
}
/**
* Extension point for managing scaffolder actions.
*
* @alpha
*/
export const scaffolderActionsExtensionPoint =
createExtensionPoint<ScaffolderActionsExtensionPoint>({
id: 'scaffolder.actions',
});
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2022 The Backstage Authors
*
* 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.
*/
/**
* The scaffolder-node module for `@backstage/plugin-scaffolder-backend`.
*
* @packageDocumentation
*/
export * from './actions';
export * from './tasks';
export {
scaffolderActionsExtensionPoint,
type ScaffolderActionsExtensionPoint,
} from './extensions';
+17
View File
@@ -0,0 +1,17 @@
/*
* Copyright 2020 The Backstage Authors
*
* 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 {};
@@ -0,0 +1,17 @@
/*
* Copyright 2023 The Backstage Authors
*
* 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 { type TaskSecrets } from './types';
@@ -0,0 +1,24 @@
/*
* Copyright 2023 The Backstage Authors
*
* 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.
*/
/**
* TaskSecrets
*
* @public
*/
export type TaskSecrets = Record<string, string> & {
backstageToken?: string;
};