Add taskID and tests

Signed-off-by: Fabio Vincenzi <fabio.vincenzi2001@gmail.com>
This commit is contained in:
Fabio Vincenzi
2024-11-11 13:00:22 +01:00
parent e17b82c83b
commit 662d7b0b33
2 changed files with 38 additions and 1 deletions
@@ -684,6 +684,34 @@ describe('NunjucksWorkflowRunner', () => {
expect(output.foo).toEqual('BACKSTAGE');
});
it('should include task ID in the templated context', async () => {
const task = createMockTaskWithSpec({
apiVersion: 'scaffolder.backstage.io/v1beta3',
steps: [
{
id: 'test',
name: 'name',
action: 'jest-mock-action',
input: {
values: {
taskId: '${{context.task.id}}',
},
},
},
],
output: {},
parameters: {},
});
await runner.execute(task);
expect(fakeActionHandler).toHaveBeenCalledWith(
expect.objectContaining({
input: { values: { taskId: 'test-workspace' } },
}),
);
});
});
describe('redactions', () => {
@@ -80,6 +80,11 @@ type TemplateContext = {
ref?: string;
};
each?: JsonValue;
context: {
task: {
id: string;
};
};
};
type CheckpointState =
@@ -480,11 +485,15 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
const taskTrack = await this.tracker.taskStart(task);
await fs.ensureDir(workspacePath);
const context: TemplateContext = {
parameters: task.spec.parameters,
steps: {},
user: task.spec.user,
context: {
task: {
id: taskId,
},
},
};
const [decision]: PolicyDecision[] =