create new package scaffolder-node

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-01-19 14:57:26 +01:00
parent d20742a349
commit d72866f0cc
79 changed files with 392 additions and 142 deletions
+8
View File
@@ -0,0 +1,8 @@
---
'@backstage/plugin-scaffolder-backend-module-cookiecutter': patch
'@backstage/plugin-scaffolder-backend-module-sentry': patch
'@backstage/plugin-scaffolder-backend-module-yeoman': patch
'@backstage/plugin-scaffolder-backend-module-rails': patch
---
Internal refactor to use the new scaffolder-node package for some functionality
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-node': minor
---
New package that takes over some of the types and functionality from scaffolder-backend that are shared with other modules
@@ -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';
/**
+2 -46
View File
@@ -24,34 +24,16 @@ 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 } 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 } 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
export const createBuiltinActions: (
options: CreateBuiltInActionsOptions,
@@ -528,11 +510,6 @@ export const createPublishGitlabMergeRequestAction: (options: {
// @public
export function createRouter(options: RouterOptions): Promise<express.Router>;
// @public
export const createTemplateAction: <TInput extends JsonObject>(
templateAction: TemplateAction<TInput>,
) => TemplateAction<TInput>;
// @public
export type CreateWorkerOptions = {
taskBroker: TaskBroker;
@@ -798,11 +775,6 @@ export class TaskManager implements TaskContext {
get spec(): TaskSpecV1beta3;
}
// @public
export type TaskSecrets = Record<string, string> & {
backstageToken?: string;
};
// @public
export type TaskStatus =
| 'open'
@@ -890,22 +862,6 @@ 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
export class TemplateActionRegistry {
// (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,
@@ -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<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
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<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>;
};
```
+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';
+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;
};
+19 -2
View File
@@ -7075,6 +7075,7 @@ __metadata:
"@backstage/errors": "workspace:^"
"@backstage/integration": "workspace:^"
"@backstage/plugin-scaffolder-backend": "workspace:^"
"@backstage/plugin-scaffolder-node": "workspace:^"
"@backstage/types": "workspace:^"
"@types/command-exists": ^1.2.0
"@types/fs-extra": ^9.0.1
@@ -7098,6 +7099,7 @@ __metadata:
"@backstage/errors": "workspace:^"
"@backstage/integration": "workspace:^"
"@backstage/plugin-scaffolder-backend": "workspace:^"
"@backstage/plugin-scaffolder-node": "workspace:^"
"@backstage/types": "workspace:^"
"@types/command-exists": ^1.2.0
"@types/fs-extra": ^9.0.1
@@ -7120,7 +7122,7 @@ __metadata:
"@backstage/dev-utils": "workspace:^"
"@backstage/errors": "workspace:^"
"@backstage/integration": "workspace:^"
"@backstage/plugin-scaffolder-backend": "workspace:^"
"@backstage/plugin-scaffolder-node": "workspace:^"
"@backstage/test-utils": "workspace:^"
"@testing-library/jest-dom": ^5.10.1
"@testing-library/react": ^12.1.3
@@ -7140,7 +7142,7 @@ __metadata:
"@backstage/backend-common": "workspace:^"
"@backstage/cli": "workspace:^"
"@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
@@ -7165,6 +7167,7 @@ __metadata:
"@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
@@ -7224,6 +7227,20 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-scaffolder-node@workspace:^, @backstage/plugin-scaffolder-node@workspace:plugins/scaffolder-node":
version: 0.0.0-use.local
resolution: "@backstage/plugin-scaffolder-node@workspace:plugins/scaffolder-node"
dependencies:
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/catalog-model": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/plugin-scaffolder-common": "workspace:^"
"@backstage/types": "workspace:^"
jsonschema: ^1.2.6
winston: ^3.2.1
languageName: unknown
linkType: soft
"@backstage/plugin-scaffolder-react@workspace:^, @backstage/plugin-scaffolder-react@workspace:plugins/scaffolder-react":
version: 0.0.0-use.local
resolution: "@backstage/plugin-scaffolder-react@workspace:plugins/scaffolder-react"