Add step info to scaffolder action context
Signed-off-by: Stephen Glass <stephen@stephen.glass>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-node-test-utils': patch
|
||||
'@backstage/plugin-scaffolder-backend': minor
|
||||
'@backstage/plugin-scaffolder-node': patch
|
||||
---
|
||||
|
||||
Add step info to scaffolder action context to access the step id and name.
|
||||
@@ -361,6 +361,24 @@ describe('NunjucksWorkflowRunner', () => {
|
||||
expect.objectContaining({ backstageToken: token }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should pass step info through', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
name: 'name',
|
||||
action: 'jest-validated-action',
|
||||
input: { foo: 1 },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await runner.execute(task);
|
||||
|
||||
expect(fakeActionHandler.mock.calls[0][0].step.id).toEqual('test');
|
||||
expect(fakeActionHandler.mock.calls[0][0].step.name).toEqual('name');
|
||||
});
|
||||
});
|
||||
|
||||
describe('conditionals', () => {
|
||||
@@ -1447,6 +1465,35 @@ describe('NunjucksWorkflowRunner', () => {
|
||||
fakeActionHandler.mock.calls[0][0].templateInfo.entity.metadata.name,
|
||||
).toEqual('test-template');
|
||||
});
|
||||
|
||||
it('should have step info in action context during dry run', async () => {
|
||||
const task = createMockTaskWithSpec(
|
||||
{
|
||||
templateInfo: {
|
||||
entityRef: 'dryRun-Entity',
|
||||
entity: { metadata: { name: 'test-template' } },
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
name: 'name',
|
||||
action: 'jest-validated-action',
|
||||
input: { foo: 1 },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
backstageToken: token,
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
await runner.execute(task);
|
||||
|
||||
expect(fakeActionHandler.mock.calls[0][0].isDryRun).toEqual(true);
|
||||
expect(fakeActionHandler.mock.calls[0][0].step.id).toEqual('test');
|
||||
expect(fakeActionHandler.mock.calls[0][0].step.name).toEqual('name');
|
||||
});
|
||||
});
|
||||
|
||||
describe('permissions', () => {
|
||||
|
||||
@@ -438,6 +438,10 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
|
||||
isDryRun: task.isDryRun,
|
||||
signal: task.cancelSignal,
|
||||
getInitiatorCredentials: () => task.getInitiatorCredentials(),
|
||||
step: {
|
||||
id: step.id,
|
||||
name: step.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,10 @@ export function createMockActionContext<
|
||||
task: {
|
||||
id: 'mock-task-id',
|
||||
},
|
||||
step: {
|
||||
id: 'mock-step-id',
|
||||
name: 'mock step name',
|
||||
},
|
||||
};
|
||||
|
||||
const createDefaultWorkspace = () => ({
|
||||
|
||||
@@ -53,6 +53,10 @@ export type ActionContext<
|
||||
};
|
||||
signal?: AbortSignal;
|
||||
each?: JsonObject;
|
||||
step?: {
|
||||
id?: string;
|
||||
name?: string;
|
||||
};
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -93,6 +93,20 @@ export type ActionContext<
|
||||
* Optional value of each invocation
|
||||
*/
|
||||
each?: JsonObject;
|
||||
|
||||
/**
|
||||
* Step information
|
||||
*/
|
||||
step?: {
|
||||
/**
|
||||
* The id of step which triggered the action
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* The name of the step which triggered the action
|
||||
*/
|
||||
name?: string;
|
||||
};
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
Reference in New Issue
Block a user