@backstage/plugin-scaffolder-backend 0.0.0-nightly-202201122931 → 0.0.0-nightly-20221122231
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 +64 -11
- package/dist/index.cjs.js +102 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +40 -25
- package/package.json +15 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,22 +1,75 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend
|
|
2
2
|
|
|
3
|
-
## 0.0.0-nightly-
|
|
3
|
+
## 0.0.0-nightly-20221122231
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2e0dbb0e50: Migrate from deprecated package @octokit/rest to octokit
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/plugin-catalog-backend@0.0.0-nightly-20221122231
|
|
10
|
+
|
|
11
|
+
## 0.15.22
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- b09dd8f43b: chore(deps): bump `@gitbeaker/node` from 34.6.0 to 35.1.0
|
|
16
|
+
- 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.
|
|
17
|
+
- 0d5e846a78: Expose a new option to provide additional template filters via `@backstage/scaffolder-backend`'s `createRouter()` function.
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/plugin-catalog-backend@0.21.1
|
|
20
|
+
- @backstage/backend-common@0.10.5
|
|
21
|
+
|
|
22
|
+
## 0.15.21
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- b05d303226: Added the ability to support supplying secrets when creating tasks in the `scaffolder-backend`.
|
|
27
|
+
|
|
28
|
+
**deprecation**: Deprecated `ctx.token` from actions in the `scaffolder-backend`. Please move to using `ctx.secrets.backstageToken` instead.
|
|
29
|
+
|
|
30
|
+
**deprecation**: Deprecated `task.token` in `TaskSpec` in the `scaffolder-backend`. Please move to using `task.secrets.backstageToken` instead.
|
|
31
|
+
|
|
32
|
+
- Updated dependencies
|
|
33
|
+
- @backstage/plugin-catalog-backend@0.21.0
|
|
34
|
+
- @backstage/integration@0.7.2
|
|
35
|
+
- @backstage/backend-common@0.10.4
|
|
36
|
+
- @backstage/config@0.1.13
|
|
37
|
+
- @backstage/catalog-model@0.9.10
|
|
38
|
+
- @backstage/catalog-client@0.5.5
|
|
39
|
+
- @backstage/plugin-scaffolder-backend-module-cookiecutter@0.1.9
|
|
40
|
+
- @backstage/plugin-scaffolder-common@0.1.3
|
|
41
|
+
|
|
42
|
+
## 0.15.21-next.0
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- Updated dependencies
|
|
47
|
+
- @backstage/plugin-catalog-backend@0.21.0-next.0
|
|
48
|
+
- @backstage/backend-common@0.10.4-next.0
|
|
49
|
+
- @backstage/config@0.1.13-next.0
|
|
50
|
+
- @backstage/catalog-model@0.9.10-next.0
|
|
51
|
+
- @backstage/catalog-client@0.5.5-next.0
|
|
52
|
+
- @backstage/integration@0.7.2-next.0
|
|
53
|
+
- @backstage/plugin-scaffolder-backend-module-cookiecutter@0.1.9-next.0
|
|
54
|
+
- @backstage/plugin-scaffolder-common@0.1.3-next.0
|
|
55
|
+
|
|
56
|
+
## 0.15.20
|
|
4
57
|
|
|
5
58
|
### Patch Changes
|
|
6
59
|
|
|
7
60
|
- 9fbd3b90ae: fix: Register plugin to prioritise Component kind for entityRef
|
|
61
|
+
- 451ef0aa07: Fix token pass-through for software templates using beta 3 version
|
|
8
62
|
- 5333451def: Cleaned up API exports
|
|
63
|
+
- 3b4d8caff6: Allow a GitHubCredentialsProvider to be passed to the GitHub scaffolder tasks actions.
|
|
9
64
|
- Updated dependencies
|
|
10
|
-
- @backstage/config@0.
|
|
11
|
-
- @backstage/
|
|
12
|
-
- @backstage/backend-common@0.
|
|
13
|
-
- @backstage/
|
|
14
|
-
- @backstage/errors@0.
|
|
15
|
-
- @backstage/catalog-client@0.
|
|
16
|
-
- @backstage/catalog-model@0.
|
|
17
|
-
- @backstage/
|
|
18
|
-
- @backstage/plugin-scaffolder-backend-module-cookiecutter@0.0.0-nightly-202201122931
|
|
19
|
-
- @backstage/plugin-scaffolder-common@0.0.0-nightly-202201122931
|
|
65
|
+
- @backstage/config@0.1.12
|
|
66
|
+
- @backstage/integration@0.7.1
|
|
67
|
+
- @backstage/backend-common@0.10.3
|
|
68
|
+
- @backstage/plugin-catalog-backend@0.20.0
|
|
69
|
+
- @backstage/errors@0.2.0
|
|
70
|
+
- @backstage/catalog-client@0.5.4
|
|
71
|
+
- @backstage/catalog-model@0.9.9
|
|
72
|
+
- @backstage/plugin-scaffolder-backend-module-cookiecutter@0.1.8
|
|
20
73
|
|
|
21
74
|
## 0.15.19
|
|
22
75
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -7,6 +7,7 @@ var catalogModel = require('@backstage/catalog-model');
|
|
|
7
7
|
var fs = require('fs-extra');
|
|
8
8
|
var yaml = require('yaml');
|
|
9
9
|
var backendCommon = require('@backstage/backend-common');
|
|
10
|
+
var integration = require('@backstage/integration');
|
|
10
11
|
var path = require('path');
|
|
11
12
|
var globby = require('globby');
|
|
12
13
|
var isbinaryfile = require('isbinaryfile');
|
|
@@ -16,8 +17,7 @@ var child_process = require('child_process');
|
|
|
16
17
|
var stream = require('stream');
|
|
17
18
|
var azureDevopsNodeApi = require('azure-devops-node-api');
|
|
18
19
|
var fetch = require('node-fetch');
|
|
19
|
-
var
|
|
20
|
-
var rest = require('@octokit/rest');
|
|
20
|
+
var octokit = require('octokit');
|
|
21
21
|
var lodash = require('lodash');
|
|
22
22
|
var octokitPluginCreatePullRequest = require('octokit-plugin-create-pull-request');
|
|
23
23
|
var node = require('@gitbeaker/node');
|
|
@@ -119,6 +119,7 @@ function createCatalogRegisterAction(options) {
|
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
121
|
async handler(ctx) {
|
|
122
|
+
var _a, _b;
|
|
122
123
|
const { input } = ctx;
|
|
123
124
|
let catalogInfoUrl;
|
|
124
125
|
if ("catalogInfoUrl" in input) {
|
|
@@ -138,13 +139,13 @@ function createCatalogRegisterAction(options) {
|
|
|
138
139
|
await catalogClient.addLocation({
|
|
139
140
|
type: "url",
|
|
140
141
|
target: catalogInfoUrl
|
|
141
|
-
}, ctx.
|
|
142
|
+
}, ((_a = ctx.secrets) == null ? void 0 : _a.backstageToken) ? { token: ctx.secrets.backstageToken } : {});
|
|
142
143
|
try {
|
|
143
144
|
const result = await catalogClient.addLocation({
|
|
144
145
|
dryRun: true,
|
|
145
146
|
type: "url",
|
|
146
147
|
target: catalogInfoUrl
|
|
147
|
-
}, ctx.
|
|
148
|
+
}, ((_b = ctx.secrets) == null ? void 0 : _b.backstageToken) ? { token: ctx.secrets.backstageToken } : {});
|
|
148
149
|
if (result.entities.length > 0) {
|
|
149
150
|
const { entities } = result;
|
|
150
151
|
let entity;
|
|
@@ -360,6 +361,12 @@ const { render, renderCompat } = (() => {
|
|
|
360
361
|
});
|
|
361
362
|
}
|
|
362
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
|
+
|
|
363
370
|
let uninstallCompat = undefined;
|
|
364
371
|
|
|
365
372
|
function render(str, values) {
|
|
@@ -392,12 +399,16 @@ const { render, renderCompat } = (() => {
|
|
|
392
399
|
`;
|
|
393
400
|
class SecureTemplater {
|
|
394
401
|
static async loadRenderer(options = {}) {
|
|
395
|
-
const { parseRepoUrl, cookiecutterCompat } = options;
|
|
396
|
-
|
|
402
|
+
const { parseRepoUrl, cookiecutterCompat, additionalTemplateFilters } = options;
|
|
403
|
+
const sandbox = {};
|
|
397
404
|
if (parseRepoUrl) {
|
|
398
|
-
sandbox =
|
|
399
|
-
|
|
400
|
-
|
|
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
|
+
]));
|
|
401
412
|
}
|
|
402
413
|
const vm = new vm2.VM({ sandbox });
|
|
403
414
|
const nunjucksSource = await fs__default["default"].readFile(backendCommon.resolvePackagePath("@backstage/plugin-scaffolder-backend", "assets/nunjucks.js.txt"), "utf-8");
|
|
@@ -418,7 +429,7 @@ class SecureTemplater {
|
|
|
418
429
|
}
|
|
419
430
|
|
|
420
431
|
function createFetchTemplateAction(options) {
|
|
421
|
-
const { reader, integrations } = options;
|
|
432
|
+
const { reader, integrations, additionalTemplateFilters } = options;
|
|
422
433
|
return createTemplateAction({
|
|
423
434
|
id: "fetch:template",
|
|
424
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.",
|
|
@@ -509,7 +520,8 @@ function createFetchTemplateAction(options) {
|
|
|
509
520
|
};
|
|
510
521
|
ctx.logger.info(`Processing ${allEntriesInTemplate.length} template files/directories with input values`, ctx.input.values);
|
|
511
522
|
const renderTemplate = await SecureTemplater.loadRenderer({
|
|
512
|
-
cookiecutterCompat: ctx.input.cookiecutterCompat
|
|
523
|
+
cookiecutterCompat: ctx.input.cookiecutterCompat,
|
|
524
|
+
additionalTemplateFilters
|
|
513
525
|
});
|
|
514
526
|
for (const location of allEntriesInTemplate) {
|
|
515
527
|
let renderFilename;
|
|
@@ -729,7 +741,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
|
|
|
729
741
|
}) => {
|
|
730
742
|
const tryOnce = async () => {
|
|
731
743
|
try {
|
|
732
|
-
await client.repos.updateBranchProtection({
|
|
744
|
+
await client.rest.repos.updateBranchProtection({
|
|
733
745
|
mediaType: {
|
|
734
746
|
previews: ["luke-cage-preview"]
|
|
735
747
|
},
|
|
@@ -1156,12 +1168,9 @@ function createPublishFileAction() {
|
|
|
1156
1168
|
}
|
|
1157
1169
|
|
|
1158
1170
|
class OctokitProvider {
|
|
1159
|
-
constructor(integrations) {
|
|
1171
|
+
constructor(integrations, githubCredentialsProvider) {
|
|
1160
1172
|
this.integrations = integrations;
|
|
1161
|
-
this.
|
|
1162
|
-
const provider = integration.SingleInstanceGithubCredentialsProvider.create(integration$1.config);
|
|
1163
|
-
return [integration$1.config.host, provider];
|
|
1164
|
-
}));
|
|
1173
|
+
this.githubCredentialsProvider = githubCredentialsProvider || integration.DefaultGithubCredentialsProvider.fromIntegrations(this.integrations);
|
|
1165
1174
|
}
|
|
1166
1175
|
async getOctokit(repoUrl) {
|
|
1167
1176
|
var _a;
|
|
@@ -1173,17 +1182,13 @@ class OctokitProvider {
|
|
|
1173
1182
|
if (!integrationConfig) {
|
|
1174
1183
|
throw new errors.InputError(`No integration for host ${host}`);
|
|
1175
1184
|
}
|
|
1176
|
-
const
|
|
1177
|
-
if (!credentialsProvider) {
|
|
1178
|
-
throw new errors.InputError(`No matching credentials for host ${host}, please check your integrations config`);
|
|
1179
|
-
}
|
|
1180
|
-
const { token } = await credentialsProvider.getCredentials({
|
|
1185
|
+
const { token } = await this.githubCredentialsProvider.getCredentials({
|
|
1181
1186
|
url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`
|
|
1182
1187
|
});
|
|
1183
1188
|
if (!token) {
|
|
1184
1189
|
throw new errors.InputError(`No token available for host: ${host}, with owner ${owner}, and repo ${repo}`);
|
|
1185
1190
|
}
|
|
1186
|
-
const client = new
|
|
1191
|
+
const client = new octokit.Octokit({
|
|
1187
1192
|
auth: token,
|
|
1188
1193
|
baseUrl: integrationConfig.apiBaseUrl,
|
|
1189
1194
|
previews: ["nebula-preview"]
|
|
@@ -1193,8 +1198,8 @@ class OctokitProvider {
|
|
|
1193
1198
|
}
|
|
1194
1199
|
|
|
1195
1200
|
function createPublishGithubAction(options) {
|
|
1196
|
-
const { integrations, config } = options;
|
|
1197
|
-
const octokitProvider = new OctokitProvider(integrations);
|
|
1201
|
+
const { integrations, config, githubCredentialsProvider } = options;
|
|
1202
|
+
const octokitProvider = new OctokitProvider(integrations, githubCredentialsProvider || integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations));
|
|
1198
1203
|
return createTemplateAction({
|
|
1199
1204
|
id: "publish:github",
|
|
1200
1205
|
description: "Initializes a git repository of contents in workspace and publishes it to GitHub.",
|
|
@@ -1290,16 +1295,16 @@ function createPublishGithubAction(options) {
|
|
|
1290
1295
|
topics
|
|
1291
1296
|
} = ctx.input;
|
|
1292
1297
|
const { client, token, owner, repo } = await octokitProvider.getOctokit(repoUrl);
|
|
1293
|
-
const user = await client.users.getByUsername({
|
|
1298
|
+
const user = await client.rest.users.getByUsername({
|
|
1294
1299
|
username: owner
|
|
1295
1300
|
});
|
|
1296
|
-
const repoCreationPromise = user.data.type === "Organization" ? client.repos.createInOrg({
|
|
1301
|
+
const repoCreationPromise = user.data.type === "Organization" ? client.rest.repos.createInOrg({
|
|
1297
1302
|
name: repo,
|
|
1298
1303
|
org: owner,
|
|
1299
1304
|
private: repoVisibility === "private",
|
|
1300
1305
|
visibility: repoVisibility,
|
|
1301
1306
|
description
|
|
1302
|
-
}) : client.repos.createForAuthenticatedUser({
|
|
1307
|
+
}) : client.rest.repos.createForAuthenticatedUser({
|
|
1303
1308
|
name: repo,
|
|
1304
1309
|
private: repoVisibility === "private",
|
|
1305
1310
|
description
|
|
@@ -1307,7 +1312,7 @@ function createPublishGithubAction(options) {
|
|
|
1307
1312
|
const { data: newRepo } = await repoCreationPromise;
|
|
1308
1313
|
if (access == null ? void 0 : access.startsWith(`${owner}/`)) {
|
|
1309
1314
|
const [, team] = access.split("/");
|
|
1310
|
-
await client.teams.addOrUpdateRepoPermissionsInOrg({
|
|
1315
|
+
await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
|
|
1311
1316
|
org: owner,
|
|
1312
1317
|
team_slug: team,
|
|
1313
1318
|
owner,
|
|
@@ -1315,7 +1320,7 @@ function createPublishGithubAction(options) {
|
|
|
1315
1320
|
permission: "admin"
|
|
1316
1321
|
});
|
|
1317
1322
|
} else if (access && access !== owner) {
|
|
1318
|
-
await client.repos.addCollaborator({
|
|
1323
|
+
await client.rest.repos.addCollaborator({
|
|
1319
1324
|
owner,
|
|
1320
1325
|
repo,
|
|
1321
1326
|
username: access,
|
|
@@ -1328,7 +1333,7 @@ function createPublishGithubAction(options) {
|
|
|
1328
1333
|
username: team_slug
|
|
1329
1334
|
} of collaborators) {
|
|
1330
1335
|
try {
|
|
1331
|
-
await client.teams.addOrUpdateRepoPermissionsInOrg({
|
|
1336
|
+
await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
|
|
1332
1337
|
org: owner,
|
|
1333
1338
|
team_slug,
|
|
1334
1339
|
owner,
|
|
@@ -1343,7 +1348,7 @@ function createPublishGithubAction(options) {
|
|
|
1343
1348
|
}
|
|
1344
1349
|
if (topics) {
|
|
1345
1350
|
try {
|
|
1346
|
-
await client.repos.replaceAllTopics({
|
|
1351
|
+
await client.rest.repos.replaceAllTopics({
|
|
1347
1352
|
owner,
|
|
1348
1353
|
repo,
|
|
1349
1354
|
names: topics.map((t) => t.toLowerCase())
|
|
@@ -1394,6 +1399,7 @@ class GithubResponseError extends errors.CustomErrorBase {
|
|
|
1394
1399
|
}
|
|
1395
1400
|
const defaultClientFactory = async ({
|
|
1396
1401
|
integrations,
|
|
1402
|
+
githubCredentialsProvider,
|
|
1397
1403
|
owner,
|
|
1398
1404
|
repo,
|
|
1399
1405
|
host = "github.com"
|
|
@@ -1403,17 +1409,14 @@ const defaultClientFactory = async ({
|
|
|
1403
1409
|
if (!integrationConfig) {
|
|
1404
1410
|
throw new errors.InputError(`No integration for host ${host}`);
|
|
1405
1411
|
}
|
|
1406
|
-
const credentialsProvider = integration.SingleInstanceGithubCredentialsProvider.create(integrationConfig);
|
|
1407
|
-
if (!credentialsProvider) {
|
|
1408
|
-
throw new errors.InputError(`No matching credentials for host ${host}, please check your integrations config`);
|
|
1409
|
-
}
|
|
1412
|
+
const credentialsProvider = githubCredentialsProvider || integration.SingleInstanceGithubCredentialsProvider.create(integrationConfig);
|
|
1410
1413
|
const { token } = await credentialsProvider.getCredentials({
|
|
1411
1414
|
url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`
|
|
1412
1415
|
});
|
|
1413
1416
|
if (!token) {
|
|
1414
1417
|
throw new errors.InputError(`No token available for host: ${host}, with owner ${owner}, and repo ${repo}`);
|
|
1415
1418
|
}
|
|
1416
|
-
const OctokitPR =
|
|
1419
|
+
const OctokitPR = octokit.Octokit.plugin(octokitPluginCreatePullRequest.createPullRequest);
|
|
1417
1420
|
return new OctokitPR({
|
|
1418
1421
|
auth: token,
|
|
1419
1422
|
baseUrl: integrationConfig.apiBaseUrl
|
|
@@ -1421,6 +1424,7 @@ const defaultClientFactory = async ({
|
|
|
1421
1424
|
};
|
|
1422
1425
|
const createPublishGithubPullRequestAction = ({
|
|
1423
1426
|
integrations,
|
|
1427
|
+
githubCredentialsProvider,
|
|
1424
1428
|
clientFactory = defaultClientFactory
|
|
1425
1429
|
}) => {
|
|
1426
1430
|
return createTemplateAction({
|
|
@@ -1487,7 +1491,13 @@ const createPublishGithubPullRequestAction = ({
|
|
|
1487
1491
|
if (!owner) {
|
|
1488
1492
|
throw new errors.InputError(`No owner provided for host: ${host}, and repo ${repo}`);
|
|
1489
1493
|
}
|
|
1490
|
-
const client = await clientFactory({
|
|
1494
|
+
const client = await clientFactory({
|
|
1495
|
+
integrations,
|
|
1496
|
+
githubCredentialsProvider,
|
|
1497
|
+
host,
|
|
1498
|
+
owner,
|
|
1499
|
+
repo
|
|
1500
|
+
});
|
|
1491
1501
|
const fileRoot = sourcePath ? backendCommon.resolveSafeChildPath(ctx.workspacePath, sourcePath) : ctx.workspacePath;
|
|
1492
1502
|
const localFilePaths = await globby__default["default"](["./**", "./**/.*", "!.git"], {
|
|
1493
1503
|
cwd: fileRoot,
|
|
@@ -1749,8 +1759,8 @@ const createPublishGitlabMergeRequestAction = (options) => {
|
|
|
1749
1759
|
};
|
|
1750
1760
|
|
|
1751
1761
|
function createGithubActionsDispatchAction(options) {
|
|
1752
|
-
const { integrations } = options;
|
|
1753
|
-
const octokitProvider = new OctokitProvider(integrations);
|
|
1762
|
+
const { integrations, githubCredentialsProvider } = options;
|
|
1763
|
+
const octokitProvider = new OctokitProvider(integrations, githubCredentialsProvider || integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations));
|
|
1754
1764
|
return createTemplateAction({
|
|
1755
1765
|
id: "github:actions:dispatch",
|
|
1756
1766
|
description: "Dispatches a GitHub Action workflow for a given branch or tag",
|
|
@@ -1773,19 +1783,25 @@ function createGithubActionsDispatchAction(options) {
|
|
|
1773
1783
|
title: "Branch or Tag name",
|
|
1774
1784
|
description: "The git branch or tag name used to dispatch the workflow",
|
|
1775
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"
|
|
1776
1791
|
}
|
|
1777
1792
|
}
|
|
1778
1793
|
}
|
|
1779
1794
|
},
|
|
1780
1795
|
async handler(ctx) {
|
|
1781
|
-
const { repoUrl, workflowId, branchOrTagName } = ctx.input;
|
|
1796
|
+
const { repoUrl, workflowId, branchOrTagName, workflowInputs } = ctx.input;
|
|
1782
1797
|
ctx.logger.info(`Dispatching workflow ${workflowId} for repo ${repoUrl} on ${branchOrTagName}`);
|
|
1783
1798
|
const { client, owner, repo } = await octokitProvider.getOctokit(repoUrl);
|
|
1784
1799
|
await client.rest.actions.createWorkflowDispatch({
|
|
1785
1800
|
owner,
|
|
1786
1801
|
repo,
|
|
1787
1802
|
workflow_id: workflowId,
|
|
1788
|
-
ref: branchOrTagName
|
|
1803
|
+
ref: branchOrTagName,
|
|
1804
|
+
inputs: workflowInputs
|
|
1789
1805
|
});
|
|
1790
1806
|
ctx.logger.info(`Workflow ${workflowId} dispatched successfully`);
|
|
1791
1807
|
}
|
|
@@ -1793,8 +1809,8 @@ function createGithubActionsDispatchAction(options) {
|
|
|
1793
1809
|
}
|
|
1794
1810
|
|
|
1795
1811
|
function createGithubWebhookAction(options) {
|
|
1796
|
-
const { integrations, defaultWebhookSecret } = options;
|
|
1797
|
-
const octokitProvider = new OctokitProvider(integrations);
|
|
1812
|
+
const { integrations, defaultWebhookSecret, githubCredentialsProvider } = options;
|
|
1813
|
+
const octokitProvider = new OctokitProvider(integrations, githubCredentialsProvider != null ? githubCredentialsProvider : integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations));
|
|
1798
1814
|
const eventNames = webhooks.emitterEventNames.filter((event) => !event.includes("."));
|
|
1799
1815
|
return createTemplateAction({
|
|
1800
1816
|
id: "github:webhook",
|
|
@@ -1871,7 +1887,7 @@ function createGithubWebhookAction(options) {
|
|
|
1871
1887
|
const { client, owner, repo } = await octokitProvider.getOctokit(repoUrl);
|
|
1872
1888
|
try {
|
|
1873
1889
|
const insecure_ssl = insecureSsl ? "1" : "0";
|
|
1874
|
-
await client.repos.createWebhook({
|
|
1890
|
+
await client.rest.repos.createWebhook({
|
|
1875
1891
|
owner,
|
|
1876
1892
|
repo,
|
|
1877
1893
|
config: {
|
|
@@ -1893,7 +1909,15 @@ function createGithubWebhookAction(options) {
|
|
|
1893
1909
|
}
|
|
1894
1910
|
|
|
1895
1911
|
const createBuiltinActions = (options) => {
|
|
1896
|
-
const {
|
|
1912
|
+
const {
|
|
1913
|
+
reader,
|
|
1914
|
+
integrations,
|
|
1915
|
+
containerRunner,
|
|
1916
|
+
catalogClient,
|
|
1917
|
+
config,
|
|
1918
|
+
additionalTemplateFilters
|
|
1919
|
+
} = options;
|
|
1920
|
+
const githubCredentialsProvider = integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
|
|
1897
1921
|
const actions = [
|
|
1898
1922
|
createFetchPlainAction({
|
|
1899
1923
|
reader,
|
|
@@ -1901,14 +1925,17 @@ 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,
|
|
1908
|
-
config
|
|
1933
|
+
config,
|
|
1934
|
+
githubCredentialsProvider
|
|
1909
1935
|
}),
|
|
1910
1936
|
createPublishGithubPullRequestAction({
|
|
1911
|
-
integrations
|
|
1937
|
+
integrations,
|
|
1938
|
+
githubCredentialsProvider
|
|
1912
1939
|
}),
|
|
1913
1940
|
createPublishGitlabAction({
|
|
1914
1941
|
integrations,
|
|
@@ -1931,10 +1958,12 @@ const createBuiltinActions = (options) => {
|
|
|
1931
1958
|
createFilesystemDeleteAction(),
|
|
1932
1959
|
createFilesystemRenameAction(),
|
|
1933
1960
|
createGithubActionsDispatchAction({
|
|
1934
|
-
integrations
|
|
1961
|
+
integrations,
|
|
1962
|
+
githubCredentialsProvider
|
|
1935
1963
|
}),
|
|
1936
1964
|
createGithubWebhookAction({
|
|
1937
|
-
integrations
|
|
1965
|
+
integrations,
|
|
1966
|
+
githubCredentialsProvider
|
|
1938
1967
|
})
|
|
1939
1968
|
];
|
|
1940
1969
|
if (containerRunner) {
|
|
@@ -2020,7 +2049,8 @@ class DatabaseTaskStore {
|
|
|
2020
2049
|
}
|
|
2021
2050
|
const updateCount = await tx("tasks").where({ id: task.id, status: "open" }).update({
|
|
2022
2051
|
status: "processing",
|
|
2023
|
-
last_heartbeat_at: this.db.fn.now()
|
|
2052
|
+
last_heartbeat_at: this.db.fn.now(),
|
|
2053
|
+
secrets: null
|
|
2024
2054
|
});
|
|
2025
2055
|
if (updateCount < 1) {
|
|
2026
2056
|
return void 0;
|
|
@@ -2084,8 +2114,7 @@ class DatabaseTaskStore {
|
|
|
2084
2114
|
id: taskId,
|
|
2085
2115
|
status: oldStatus
|
|
2086
2116
|
}).update({
|
|
2087
|
-
status
|
|
2088
|
-
secrets: null
|
|
2117
|
+
status
|
|
2089
2118
|
});
|
|
2090
2119
|
if (updateCount !== 1) {
|
|
2091
2120
|
throw new errors.ConflictError(`Failed to update status to '${status}' for taskId ${taskId}`);
|
|
@@ -2298,7 +2327,7 @@ class HandlebarsWorkflowRunner {
|
|
|
2298
2327
|
this.handlebars.registerHelper("eq", (a, b) => a === b);
|
|
2299
2328
|
}
|
|
2300
2329
|
async execute(task) {
|
|
2301
|
-
var _a, _b;
|
|
2330
|
+
var _a, _b, _c;
|
|
2302
2331
|
if (!isValidTaskSpec$1(task.spec)) {
|
|
2303
2332
|
throw new errors.InputError(`Task spec is not a valid v1beta2 task spec`);
|
|
2304
2333
|
}
|
|
@@ -2402,6 +2431,7 @@ class HandlebarsWorkflowRunner {
|
|
|
2402
2431
|
logStream: stream$1,
|
|
2403
2432
|
input,
|
|
2404
2433
|
token: (_b = task.secrets) == null ? void 0 : _b.token,
|
|
2434
|
+
secrets: (_c = task.secrets) != null ? _c : {},
|
|
2405
2435
|
workspacePath,
|
|
2406
2436
|
async createTemporaryDirectory() {
|
|
2407
2437
|
const tmpDir = await fs__default["default"].mkdtemp(`${workspacePath}_step-${step.id}-`);
|
|
@@ -2527,7 +2557,7 @@ class NunjucksWorkflowRunner {
|
|
|
2527
2557
|
});
|
|
2528
2558
|
}
|
|
2529
2559
|
async execute(task) {
|
|
2530
|
-
var _a, _b;
|
|
2560
|
+
var _a, _b, _c, _d;
|
|
2531
2561
|
if (!isValidTaskSpec(task.spec)) {
|
|
2532
2562
|
throw new errors.InputError("Wrong template version executed with the workflow engine");
|
|
2533
2563
|
}
|
|
@@ -2536,7 +2566,8 @@ class NunjucksWorkflowRunner {
|
|
|
2536
2566
|
const renderTemplate = await SecureTemplater.loadRenderer({
|
|
2537
2567
|
parseRepoUrl(url) {
|
|
2538
2568
|
return parseRepoUrl(url, integrations);
|
|
2539
|
-
}
|
|
2569
|
+
},
|
|
2570
|
+
additionalTemplateFilters: this.options.additionalTemplateFilters
|
|
2540
2571
|
});
|
|
2541
2572
|
try {
|
|
2542
2573
|
await fs__default["default"].ensureDir(workspacePath);
|
|
@@ -2576,6 +2607,8 @@ class NunjucksWorkflowRunner {
|
|
|
2576
2607
|
await action.handler({
|
|
2577
2608
|
baseUrl: task.spec.baseUrl,
|
|
2578
2609
|
input,
|
|
2610
|
+
token: (_c = task.secrets) == null ? void 0 : _c.token,
|
|
2611
|
+
secrets: (_d = task.secrets) != null ? _d : {},
|
|
2579
2612
|
logger: taskLogger,
|
|
2580
2613
|
logStream: streamLogger,
|
|
2581
2614
|
workspacePath,
|
|
@@ -2625,7 +2658,8 @@ class TaskWorker {
|
|
|
2625
2658
|
logger,
|
|
2626
2659
|
actionRegistry,
|
|
2627
2660
|
integrations,
|
|
2628
|
-
workingDirectory
|
|
2661
|
+
workingDirectory,
|
|
2662
|
+
additionalTemplateFilters
|
|
2629
2663
|
} = options;
|
|
2630
2664
|
const legacyWorkflowRunner = new HandlebarsWorkflowRunner({
|
|
2631
2665
|
logger,
|
|
@@ -2637,7 +2671,8 @@ class TaskWorker {
|
|
|
2637
2671
|
actionRegistry,
|
|
2638
2672
|
integrations,
|
|
2639
2673
|
logger,
|
|
2640
|
-
workingDirectory
|
|
2674
|
+
workingDirectory,
|
|
2675
|
+
additionalTemplateFilters
|
|
2641
2676
|
});
|
|
2642
2677
|
return new TaskWorker({
|
|
2643
2678
|
taskBroker,
|
|
@@ -2734,7 +2769,8 @@ async function createRouter(options) {
|
|
|
2734
2769
|
catalogClient,
|
|
2735
2770
|
actions,
|
|
2736
2771
|
containerRunner,
|
|
2737
|
-
taskWorkers
|
|
2772
|
+
taskWorkers,
|
|
2773
|
+
additionalTemplateFilters
|
|
2738
2774
|
} = options;
|
|
2739
2775
|
const logger = parentLogger.child({ plugin: "scaffolder" });
|
|
2740
2776
|
const workingDirectory = await getWorkingDirectory(config, logger);
|
|
@@ -2757,7 +2793,8 @@ async function createRouter(options) {
|
|
|
2757
2793
|
actionRegistry,
|
|
2758
2794
|
integrations,
|
|
2759
2795
|
logger,
|
|
2760
|
-
workingDirectory
|
|
2796
|
+
workingDirectory,
|
|
2797
|
+
additionalTemplateFilters
|
|
2761
2798
|
});
|
|
2762
2799
|
workers.push(worker);
|
|
2763
2800
|
}
|
|
@@ -2766,7 +2803,8 @@ async function createRouter(options) {
|
|
|
2766
2803
|
catalogClient,
|
|
2767
2804
|
containerRunner,
|
|
2768
2805
|
reader,
|
|
2769
|
-
config
|
|
2806
|
+
config,
|
|
2807
|
+
additionalTemplateFilters
|
|
2770
2808
|
});
|
|
2771
2809
|
actionsToRegister.forEach((action) => actionRegistry.register(action));
|
|
2772
2810
|
workers.forEach((worker) => worker.start());
|
|
@@ -2857,6 +2895,8 @@ async function createRouter(options) {
|
|
|
2857
2895
|
throw new errors.InputError(`Unsupported apiVersion field in schema entity, ${template.apiVersion}`);
|
|
2858
2896
|
}
|
|
2859
2897
|
const result = await taskBroker.dispatch(taskSpec, {
|
|
2898
|
+
...req.body.secrets,
|
|
2899
|
+
backstageToken: token,
|
|
2860
2900
|
token
|
|
2861
2901
|
});
|
|
2862
2902
|
res.status(201).json({ id: result.taskId });
|