@@ -7,28 +7,27 @@ metadata:
|
||||
spec:
|
||||
type: website
|
||||
parameters:
|
||||
- name: Enter some stuff
|
||||
description: Enter some stuff
|
||||
properties:
|
||||
inputString:
|
||||
type: string
|
||||
title: string input test
|
||||
inputObject:
|
||||
type: object
|
||||
title: object input test
|
||||
properties:
|
||||
first:
|
||||
type: string
|
||||
title: first
|
||||
second:
|
||||
type: number
|
||||
title: second
|
||||
- name: Enter some stuff
|
||||
description: Enter some stuff
|
||||
properties:
|
||||
inputString:
|
||||
type: string
|
||||
title: string input test
|
||||
inputObject:
|
||||
type: object
|
||||
title: object input test
|
||||
properties:
|
||||
first:
|
||||
type: string
|
||||
title: first
|
||||
second:
|
||||
type: number
|
||||
title: second
|
||||
steps:
|
||||
- id: debug
|
||||
name: Debug
|
||||
action: debug:log
|
||||
input:
|
||||
message: ${{ parameters.inputString }}
|
||||
extra: ${{ parameters.inputObject }}
|
||||
|
||||
|
||||
- id: debug
|
||||
if: ${{ true === true }}
|
||||
name: Debug
|
||||
action: debug:log
|
||||
input:
|
||||
message: ${{ parameters.inputString }}
|
||||
extra: ${{ parameters.inputObject }}
|
||||
|
||||
@@ -136,6 +136,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
expect(fakeActionHandler).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('conditionals', () => {
|
||||
it('should execute steps conditionally', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
@@ -340,4 +341,32 @@ describe('DefaultWorkflowRunner', () => {
|
||||
expect(output.foo).toEqual('BACKSTAGE');
|
||||
});
|
||||
});
|
||||
|
||||
describe('filters', () => {
|
||||
it('provides the parseRepoUrl filter', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
name: 'name',
|
||||
action: 'output-action',
|
||||
input: {},
|
||||
},
|
||||
],
|
||||
output: {
|
||||
foo: '${{parameters.repoUrl | parseRepoUrl}}',
|
||||
},
|
||||
parameters: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
},
|
||||
});
|
||||
|
||||
const { output } = await runner.execute(task);
|
||||
|
||||
expect(output.foo.host).toEqual('github.com');
|
||||
expect(output.foo.owner).toEqual('owner');
|
||||
expect(output.foo.repo).toEqual('repo');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,6 +32,7 @@ import { InputError } from '@backstage/errors';
|
||||
import { PassThrough } from 'stream';
|
||||
import { isTruthy } from './helper';
|
||||
import { validate as validateJsonSchema } from 'jsonschema';
|
||||
import { parseRepoUrl } from '../actions/builtin/publish/util';
|
||||
|
||||
type Options = {
|
||||
workingDirectory: string;
|
||||
@@ -80,8 +81,6 @@ export class DefaultWorkflowRunner implements WorkflowRunner {
|
||||
private readonly nunjucks: nunjucks.Environment;
|
||||
|
||||
constructor(private readonly options: Options) {
|
||||
// TODO(blam): Probably need the repo helper here.
|
||||
// Or we move to returning Objects in the RepoUrlPickerV2 or something?
|
||||
this.nunjucks = nunjucks.configure({
|
||||
autoescape: false,
|
||||
tags: {
|
||||
@@ -89,6 +88,18 @@ export class DefaultWorkflowRunner implements WorkflowRunner {
|
||||
variableEnd: '}}',
|
||||
},
|
||||
});
|
||||
|
||||
// TODO(blam): let's work out how we can deprecate these.
|
||||
// We shouln't really need to be exposing these now we can deal with
|
||||
// objects in the params block
|
||||
this.nunjucks.addFilter('parseRepoUrl', repoUrl => {
|
||||
return JSON.stringify(parseRepoUrl(repoUrl, this.options.integrations));
|
||||
});
|
||||
|
||||
this.nunjucks.addFilter('projectSlug', repoUrl => {
|
||||
const { owner, repo } = parseRepoUrl(repoUrl, this.options.integrations);
|
||||
return `${owner}/${repo}`;
|
||||
});
|
||||
}
|
||||
|
||||
private render<T>(input: T, context: TemplateContext): T {
|
||||
|
||||
@@ -69,7 +69,7 @@ export interface TaskSpecV1beta3 {
|
||||
baseUrl?: string;
|
||||
parameters: JsonObject;
|
||||
steps: TaskStep[];
|
||||
output: { [name: string]: string };
|
||||
output: { [name: string]: JsonValue };
|
||||
}
|
||||
|
||||
export type TaskSpec = TaskSpecV1beta2 | TaskSpecV1beta3;
|
||||
@@ -141,7 +141,7 @@ export interface TaskStore {
|
||||
}: TaskStoreGetEventsOptions): Promise<{ events: DbTaskEventRow[] }>;
|
||||
}
|
||||
|
||||
export type WorkflowResponse = { output: { [name: string]: JsonValue } };
|
||||
export type WorkflowResponse = { output: { [key: string]: JsonObject } };
|
||||
export interface WorkflowRunner {
|
||||
execute(task: Task): Promise<WorkflowResponse>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user