2022-07-04 13:19:25 -04:00
|
|
|
import fs from "fs";
|
|
|
|
import yaml from "yaml";
|
|
|
|
|
|
|
|
interface ActionInput {
|
|
|
|
description?: string;
|
|
|
|
required?: boolean;
|
|
|
|
default?: string;
|
|
|
|
unique?: boolean;
|
|
|
|
publisher?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function processActionYamlTemplate() {
|
|
|
|
processActionTemplate("./action.template.yml", "./action.yml");
|
|
|
|
}
|
|
|
|
|
|
|
|
function processActionTemplate(pathIn: string, pathOut: string) {
|
|
|
|
const content = fs.readFileSync(pathIn, "utf8");
|
|
|
|
const action = yaml.parse(content) as { inputs?: Record<string, ActionInput> };
|
|
|
|
if (!action.inputs) {
|
|
|
|
action.inputs = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
action.inputs = processInputs(action.inputs);
|
|
|
|
|
|
|
|
const updatedContent = yaml.stringify(action);
|
|
|
|
fs.writeFileSync(pathOut, updatedContent, "utf8");
|
|
|
|
}
|
|
|
|
|
|
|
|
function processInputs(inputs: Record<string, ActionInput>) {
|
|
|
|
const publishers = Object.entries(inputs).filter(([_, input]) => input.publisher).map(([key, _]) => key);
|
|
|
|
const nestedInputs = Object.entries(inputs).filter(([key, input]) => !input.publisher && !input.unique && !publishers.find(p => key.startsWith(p)));
|
|
|
|
|
|
|
|
for (const [key, input] of Object.entries(inputs)) {
|
|
|
|
if (input.publisher) {
|
|
|
|
delete inputs[key];
|
|
|
|
}
|
|
|
|
delete input.unique;
|
|
|
|
|
|
|
|
if (typeof input.required !== "boolean") {
|
|
|
|
input.required = false;
|
|
|
|
}
|
|
|
|
if (input.default === undefined) {
|
|
|
|
input.default = "${undefined}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const publisher of publishers) {
|
|
|
|
for (const [name, input] of nestedInputs) {
|
2022-08-21 08:21:52 -04:00
|
|
|
inputs[`${publisher}-${name}`] = {
|
|
|
|
...input,
|
|
|
|
default: "${undefined}"
|
|
|
|
};
|
2022-07-04 13:19:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return inputs;
|
|
|
|
}
|