Convert secrets, complete secrets in called workflow
This commit is contained in:
@@ -314,4 +314,71 @@ jobs:
|
||||
jobs: []
|
||||
});
|
||||
});
|
||||
|
||||
// Extra coverage since workflow_call components are not all covered by x-lang parsers
|
||||
it("converts workflow_call on", async () => {
|
||||
const result = parseWorkflow(
|
||||
{
|
||||
name: "wf.yaml",
|
||||
content: `on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
test:
|
||||
type: string
|
||||
description: 'a test'
|
||||
required: true
|
||||
default: 'testing 123'
|
||||
secrets:
|
||||
secret1:
|
||||
description: 'first secret'
|
||||
required: true
|
||||
secret2:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest`
|
||||
},
|
||||
nullTrace
|
||||
);
|
||||
|
||||
const template = await convertWorkflowTemplate(result.context, result.value!, undefined, {
|
||||
errorPolicy: ErrorPolicy.TryConversion
|
||||
});
|
||||
|
||||
expect(serializeTemplate(template)).toEqual({
|
||||
events: {
|
||||
workflow_call: {
|
||||
inputs: {
|
||||
test: {
|
||||
description: "a test",
|
||||
required: true,
|
||||
type: "string",
|
||||
default: "testing 123"
|
||||
}
|
||||
},
|
||||
secrets: {
|
||||
secret1: {
|
||||
description: "first secret",
|
||||
required: true
|
||||
},
|
||||
secret2: {}
|
||||
}
|
||||
}
|
||||
},
|
||||
jobs: [
|
||||
{
|
||||
id: "build",
|
||||
if: {
|
||||
expr: "success()",
|
||||
type: 3
|
||||
},
|
||||
name: "build",
|
||||
needs: undefined,
|
||||
outputs: undefined,
|
||||
"runs-on": "ubuntu-latest",
|
||||
steps: [],
|
||||
type: "job"
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from "../workflow-template";
|
||||
import {isValidCron} from "./cron";
|
||||
import {convertStringList} from "./string-list";
|
||||
import {convertEventWorkflowCall} from "./workflow-call";
|
||||
import {convertEventWorkflowDispatchInputs} from "./workflow-dispatch";
|
||||
|
||||
export function convertOn(context: TemplateContext, token: TemplateToken): EventsConfig {
|
||||
@@ -66,8 +67,9 @@ export function convertOn(context: TemplateContext, token: TemplateToken): Event
|
||||
...convertPatternFilter("paths", eventToken),
|
||||
...convertFilter("types", eventToken),
|
||||
...convertFilter("workflows", eventToken),
|
||||
// TODO - share input parsing for now, but workflow_call also needs outputs and secrets
|
||||
...convertEventWorkflowDispatchInputs(context, eventToken)
|
||||
// workflow_call and workflow_dispatch share input parsing
|
||||
...convertEventWorkflowDispatchInputs(context, eventToken),
|
||||
...convertEventWorkflowCall(context, eventToken)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import {TemplateContext} from "../../templates/template-context";
|
||||
import {MappingToken, TemplateToken} from "../../templates/tokens";
|
||||
import {isMapping} from "../../templates/tokens/type-guards";
|
||||
import {SecretConfig, WorkflowCallConfig} from "../workflow-template";
|
||||
|
||||
export function convertEventWorkflowCall(context: TemplateContext, token: MappingToken): WorkflowCallConfig {
|
||||
const result: WorkflowCallConfig = {};
|
||||
|
||||
for (const item of token) {
|
||||
const key = item.key.assertString("workflow dispatch input key");
|
||||
|
||||
switch (key.value) {
|
||||
case "inputs":
|
||||
// Ignore, these are handled by convertEventWorkflowDispatchInputs
|
||||
break;
|
||||
|
||||
case "secrets":
|
||||
result.secrets = convertWorkflowCallSecrets(context, item.value.assertMapping("workflow dispatch inputs"));
|
||||
break;
|
||||
|
||||
case "outputs":
|
||||
// TODO - outputs
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function convertWorkflowCallSecrets(
|
||||
context: TemplateContext,
|
||||
token: MappingToken
|
||||
): {[secretName: string]: SecretConfig} {
|
||||
const result: {[secretName: string]: SecretConfig} = {};
|
||||
|
||||
for (const item of token) {
|
||||
const secretName = item.key.assertString("secret name");
|
||||
|
||||
result[secretName.value] = convertWorkflowCallSecret(context, item.value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function convertWorkflowCallSecret(context: TemplateContext, token: TemplateToken): SecretConfig {
|
||||
const result: SecretConfig = {};
|
||||
|
||||
if (isMapping(token)) {
|
||||
for (const item of token) {
|
||||
const key = item.key.assertString("workflow call secret key");
|
||||
|
||||
switch (key.value) {
|
||||
case "description":
|
||||
result.description = item.value.assertString("secret description").value;
|
||||
break;
|
||||
|
||||
case "required":
|
||||
result.required = item.value.assertBoolean("secret required").value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -158,10 +158,10 @@ export type WorkflowDispatchConfig = {
|
||||
};
|
||||
|
||||
export type WorkflowCallConfig = {
|
||||
inputs: {[inputName: string]: InputConfig};
|
||||
inputs?: {[inputName: string]: InputConfig};
|
||||
secrets?: {[secretName: string]: SecretConfig};
|
||||
// TODO - these are supported in C# and Go but not in TS yet
|
||||
// outputs: { [outputName: string]: OutputConfig }
|
||||
// secrets: { [secretName: string]: SecretConfig }
|
||||
};
|
||||
|
||||
export enum InputType {
|
||||
@@ -179,6 +179,11 @@ export type InputConfig = {
|
||||
options?: string[];
|
||||
};
|
||||
|
||||
export type SecretConfig = {
|
||||
description?: string;
|
||||
required?: boolean;
|
||||
};
|
||||
|
||||
export type ScheduleConfig = {
|
||||
cron: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user