Skip to content

Commit e4be53e

Browse files
authored
fix: Allow no inputs to TRW (#2203)
Fixes #1780 --------- Signed-off-by: Ian Lewis <ianlewis@google.com>
1 parent 7726ba6 commit e4be53e

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

.github/actions/verify-token/__tests__/inputs.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ import { updateSLSAToken } from "../src/inputs";
2020
import { rawTokenInterface } from "../src/types";
2121

2222
describe("updateSLSAToken", () => {
23+
it("no inputs", async () => {
24+
const inputs = JSON.parse("{}");
25+
const token = createToken(inputs);
26+
const content = `
27+
on:
28+
workflow_call:
29+
`;
30+
const ret = updateSLSAToken(content, token);
31+
expect(ret.tool.inputs).toEqual(
32+
new Map<string, string | number | boolean>()
33+
);
34+
});
35+
2336
it("remove bool", async () => {
2437
const inputs = JSON.parse(
2538
'{"name1": "value1", "name2": 2, "name3": "", "name4": true}'

.github/actions/verify-token/dist/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,17 @@ function filterWorkflowInputs(slsaToken, ghToken, repoName, hash, workflowPath)
272272
}
273273
exports.filterWorkflowInputs = filterWorkflowInputs;
274274
function updateSLSAToken(content, slsaToken) {
275+
var _a, _b, _c;
275276
const ret = Object.create(slsaToken);
276277
const workflow = YAML.parse(content);
277278
slsaToken.tool.inputs = (0, utils_1.asMap)(slsaToken.tool.inputs);
278-
if (!workflow.on) {
279-
throw new Error("no 'on' field");
280-
}
281-
if (!workflow.on.workflow_call) {
279+
// NOTE: We need to check the presence of workflow_call but it could be empty
280+
// (e.g. no inputs).
281+
if (((_a = workflow.on) === null || _a === void 0 ? void 0 : _a.workflow_call) === undefined) {
282282
throw new Error("no 'workflow_call' field");
283283
}
284284
// No inputs field defined.
285-
if (!workflow.on.workflow_call.inputs) {
285+
if (!((_c = (_b = workflow.on) === null || _b === void 0 ? void 0 : _b.workflow_call) === null || _c === void 0 ? void 0 : _c.inputs)) {
286286
core.info("no input defined in the workflow");
287287
ret.tool.inputs = new Map();
288288
return ret;

.github/actions/verify-token/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/verify-token/src/inputs.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export function updateSLSAToken(
4646
slsaToken.tool.inputs = asMap<string | number | boolean>(
4747
slsaToken.tool.inputs
4848
);
49-
if (!workflow.on) {
50-
throw new Error("no 'on' field");
51-
}
52-
if (!workflow.on.workflow_call) {
49+
50+
// NOTE: We need to check the presence of workflow_call but it could be empty
51+
// (e.g. no inputs).
52+
if (workflow.on?.workflow_call === undefined) {
5353
throw new Error("no 'workflow_call' field");
5454
}
5555

5656
// No inputs field defined.
57-
if (!workflow.on.workflow_call.inputs) {
57+
if (!workflow.on?.workflow_call?.inputs) {
5858
core.info("no input defined in the workflow");
5959
ret.tool.inputs = new Map();
6060
return ret;

0 commit comments

Comments
 (0)