@backstage/plugin-scaffolder-backend 0.15.21 → 0.15.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/index.cjs.js +48 -17
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +23 -17
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend
|
|
2
2
|
|
|
3
|
+
## 0.15.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b09dd8f43b: chore(deps): bump `@gitbeaker/node` from 34.6.0 to 35.1.0
|
|
8
|
+
- ac2f1eeec0: This change is for adding the option of inputs on the `github:actions:dispatch` Backstage Action. This will allow users to pass data from Backstage to the GitHub Action.
|
|
9
|
+
- 0d5e846a78: Expose a new option to provide additional template filters via `@backstage/scaffolder-backend`'s `createRouter()` function.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- @backstage/plugin-catalog-backend@0.21.1
|
|
12
|
+
- @backstage/backend-common@0.10.5
|
|
13
|
+
|
|
3
14
|
## 0.15.21
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -361,6 +361,12 @@ const { render, renderCompat } = (() => {
|
|
|
361
361
|
});
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
if (typeof additionalTemplateFilters !== 'undefined') {
|
|
365
|
+
for (const [filterName, filterFn] of Object.entries(additionalTemplateFilters)) {
|
|
366
|
+
env.addFilter(filterName, (...args) => JSON.parse(filterFn(...args)));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
364
370
|
let uninstallCompat = undefined;
|
|
365
371
|
|
|
366
372
|
function render(str, values) {
|
|
@@ -393,12 +399,16 @@ const { render, renderCompat } = (() => {
|
|
|
393
399
|
`;
|
|
394
400
|
class SecureTemplater {
|
|
395
401
|
static async loadRenderer(options = {}) {
|
|
396
|
-
const { parseRepoUrl, cookiecutterCompat } = options;
|
|
397
|
-
|
|
402
|
+
const { parseRepoUrl, cookiecutterCompat, additionalTemplateFilters } = options;
|
|
403
|
+
const sandbox = {};
|
|
398
404
|
if (parseRepoUrl) {
|
|
399
|
-
sandbox =
|
|
400
|
-
|
|
401
|
-
|
|
405
|
+
sandbox.parseRepoUrl = (url) => JSON.stringify(parseRepoUrl(url));
|
|
406
|
+
}
|
|
407
|
+
if (additionalTemplateFilters) {
|
|
408
|
+
sandbox.additionalTemplateFilters = Object.fromEntries(Object.entries(additionalTemplateFilters).filter(([_, filterFunction]) => !!filterFunction).map(([filterName, filterFunction]) => [
|
|
409
|
+
filterName,
|
|
410
|
+
(...args) => JSON.stringify(filterFunction(...args))
|
|
411
|
+
]));
|
|
402
412
|
}
|
|
403
413
|
const vm = new vm2.VM({ sandbox });
|
|
404
414
|
const nunjucksSource = await fs__default["default"].readFile(backendCommon.resolvePackagePath("@backstage/plugin-scaffolder-backend", "assets/nunjucks.js.txt"), "utf-8");
|
|
@@ -419,7 +429,7 @@ class SecureTemplater {
|
|
|
419
429
|
}
|
|
420
430
|
|
|
421
431
|
function createFetchTemplateAction(options) {
|
|
422
|
-
const { reader, integrations } = options;
|
|
432
|
+
const { reader, integrations, additionalTemplateFilters } = options;
|
|
423
433
|
return createTemplateAction({
|
|
424
434
|
id: "fetch:template",
|
|
425
435
|
description: "Downloads a skeleton, templates variables into file and directory names and content, and places the result in the workspace, or optionally in a subdirectory specified by the 'targetPath' input option.",
|
|
@@ -510,7 +520,8 @@ function createFetchTemplateAction(options) {
|
|
|
510
520
|
};
|
|
511
521
|
ctx.logger.info(`Processing ${allEntriesInTemplate.length} template files/directories with input values`, ctx.input.values);
|
|
512
522
|
const renderTemplate = await SecureTemplater.loadRenderer({
|
|
513
|
-
cookiecutterCompat: ctx.input.cookiecutterCompat
|
|
523
|
+
cookiecutterCompat: ctx.input.cookiecutterCompat,
|
|
524
|
+
additionalTemplateFilters
|
|
514
525
|
});
|
|
515
526
|
for (const location of allEntriesInTemplate) {
|
|
516
527
|
let renderFilename;
|
|
@@ -1772,19 +1783,25 @@ function createGithubActionsDispatchAction(options) {
|
|
|
1772
1783
|
title: "Branch or Tag name",
|
|
1773
1784
|
description: "The git branch or tag name used to dispatch the workflow",
|
|
1774
1785
|
type: "string"
|
|
1786
|
+
},
|
|
1787
|
+
workflowInputs: {
|
|
1788
|
+
title: "Workflow Inputs",
|
|
1789
|
+
description: "Inputs keys and values to send to GitHub Action configured on the workflow file. The maximum number of properties is 10. ",
|
|
1790
|
+
type: "object"
|
|
1775
1791
|
}
|
|
1776
1792
|
}
|
|
1777
1793
|
}
|
|
1778
1794
|
},
|
|
1779
1795
|
async handler(ctx) {
|
|
1780
|
-
const { repoUrl, workflowId, branchOrTagName } = ctx.input;
|
|
1796
|
+
const { repoUrl, workflowId, branchOrTagName, workflowInputs } = ctx.input;
|
|
1781
1797
|
ctx.logger.info(`Dispatching workflow ${workflowId} for repo ${repoUrl} on ${branchOrTagName}`);
|
|
1782
1798
|
const { client, owner, repo } = await octokitProvider.getOctokit(repoUrl);
|
|
1783
1799
|
await client.rest.actions.createWorkflowDispatch({
|
|
1784
1800
|
owner,
|
|
1785
1801
|
repo,
|
|
1786
1802
|
workflow_id: workflowId,
|
|
1787
|
-
ref: branchOrTagName
|
|
1803
|
+
ref: branchOrTagName,
|
|
1804
|
+
inputs: workflowInputs
|
|
1788
1805
|
});
|
|
1789
1806
|
ctx.logger.info(`Workflow ${workflowId} dispatched successfully`);
|
|
1790
1807
|
}
|
|
@@ -1892,7 +1909,14 @@ function createGithubWebhookAction(options) {
|
|
|
1892
1909
|
}
|
|
1893
1910
|
|
|
1894
1911
|
const createBuiltinActions = (options) => {
|
|
1895
|
-
const {
|
|
1912
|
+
const {
|
|
1913
|
+
reader,
|
|
1914
|
+
integrations,
|
|
1915
|
+
containerRunner,
|
|
1916
|
+
catalogClient,
|
|
1917
|
+
config,
|
|
1918
|
+
additionalTemplateFilters
|
|
1919
|
+
} = options;
|
|
1896
1920
|
const githubCredentialsProvider = integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
|
|
1897
1921
|
const actions = [
|
|
1898
1922
|
createFetchPlainAction({
|
|
@@ -1901,7 +1925,8 @@ const createBuiltinActions = (options) => {
|
|
|
1901
1925
|
}),
|
|
1902
1926
|
createFetchTemplateAction({
|
|
1903
1927
|
integrations,
|
|
1904
|
-
reader
|
|
1928
|
+
reader,
|
|
1929
|
+
additionalTemplateFilters
|
|
1905
1930
|
}),
|
|
1906
1931
|
createPublishGithubAction({
|
|
1907
1932
|
integrations,
|
|
@@ -2541,7 +2566,8 @@ class NunjucksWorkflowRunner {
|
|
|
2541
2566
|
const renderTemplate = await SecureTemplater.loadRenderer({
|
|
2542
2567
|
parseRepoUrl(url) {
|
|
2543
2568
|
return parseRepoUrl(url, integrations);
|
|
2544
|
-
}
|
|
2569
|
+
},
|
|
2570
|
+
additionalTemplateFilters: this.options.additionalTemplateFilters
|
|
2545
2571
|
});
|
|
2546
2572
|
try {
|
|
2547
2573
|
await fs__default["default"].ensureDir(workspacePath);
|
|
@@ -2632,7 +2658,8 @@ class TaskWorker {
|
|
|
2632
2658
|
logger,
|
|
2633
2659
|
actionRegistry,
|
|
2634
2660
|
integrations,
|
|
2635
|
-
workingDirectory
|
|
2661
|
+
workingDirectory,
|
|
2662
|
+
additionalTemplateFilters
|
|
2636
2663
|
} = options;
|
|
2637
2664
|
const legacyWorkflowRunner = new HandlebarsWorkflowRunner({
|
|
2638
2665
|
logger,
|
|
@@ -2644,7 +2671,8 @@ class TaskWorker {
|
|
|
2644
2671
|
actionRegistry,
|
|
2645
2672
|
integrations,
|
|
2646
2673
|
logger,
|
|
2647
|
-
workingDirectory
|
|
2674
|
+
workingDirectory,
|
|
2675
|
+
additionalTemplateFilters
|
|
2648
2676
|
});
|
|
2649
2677
|
return new TaskWorker({
|
|
2650
2678
|
taskBroker,
|
|
@@ -2741,7 +2769,8 @@ async function createRouter(options) {
|
|
|
2741
2769
|
catalogClient,
|
|
2742
2770
|
actions,
|
|
2743
2771
|
containerRunner,
|
|
2744
|
-
taskWorkers
|
|
2772
|
+
taskWorkers,
|
|
2773
|
+
additionalTemplateFilters
|
|
2745
2774
|
} = options;
|
|
2746
2775
|
const logger = parentLogger.child({ plugin: "scaffolder" });
|
|
2747
2776
|
const workingDirectory = await getWorkingDirectory(config, logger);
|
|
@@ -2764,7 +2793,8 @@ async function createRouter(options) {
|
|
|
2764
2793
|
actionRegistry,
|
|
2765
2794
|
integrations,
|
|
2766
2795
|
logger,
|
|
2767
|
-
workingDirectory
|
|
2796
|
+
workingDirectory,
|
|
2797
|
+
additionalTemplateFilters
|
|
2768
2798
|
});
|
|
2769
2799
|
workers.push(worker);
|
|
2770
2800
|
}
|
|
@@ -2773,7 +2803,8 @@ async function createRouter(options) {
|
|
|
2773
2803
|
catalogClient,
|
|
2774
2804
|
containerRunner,
|
|
2775
2805
|
reader,
|
|
2776
|
-
config
|
|
2806
|
+
config,
|
|
2807
|
+
additionalTemplateFilters
|
|
2777
2808
|
});
|
|
2778
2809
|
actionsToRegister.forEach((action) => actionRegistry.register(action));
|
|
2779
2810
|
workers.forEach((worker) => worker.start());
|