Skip to content

Commit

Permalink
fix: allow multiple template paths
Browse files Browse the repository at this point in the history
  • Loading branch information
darioblanco committed Jun 10, 2021
1 parent f626dd8 commit 12576e3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions action.yml
Expand Up @@ -13,8 +13,8 @@ inputs:
description: The path in the current repository that will hold the generated workflow files.
required: false
default: .github/workflows
templatePath:
description: The path in the template repository that hold the YTT files to load with -f.
templatePaths:
description: The path (or comma separated list of paths) that hold YTT files to load with -f.
required: false
default: ytt
token:
Expand Down
2 changes: 1 addition & 1 deletion dist/run.js

Large diffs are not rendered by default.

38 changes: 20 additions & 18 deletions src/main.ts
Expand Up @@ -31,12 +31,12 @@ export async function run(): Promise<void> {

const configPath = pathJoin('.github', core.getInput('config'));
const outputFiles = pathResolve(cwd, core.getInput('outputFiles'));
const templatePath = pathResolve(cwd, core.getInput('templatePath'));
const templatePaths = core.getInput('templatePath').split(',');
core.debug(
`Configuration: ${JSON.stringify({
configPath,
outputFiles,
templatePath,
templatePaths,
})}`,
);

Expand All @@ -55,7 +55,7 @@ export async function run(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
config = yaml.load(content) as Config;
} else {
throw new Error(`Unable to load config from ${templatePath}`);
throw new Error(`Unable to load config from ${configPath}`);
}
// Show config, current folder and templates
core.debug(`Config content loaded from ${configPath} via octokit:\n ${JSON.stringify(config)}`);
Expand All @@ -64,8 +64,11 @@ export async function run(): Promise<void> {
await exec.exec('pwd');
core.debug('Current working directory contents:');
await exec.exec('ls -allh');
core.debug('Template directory contents:');
await exec.exec(`ls -allh ${templatePath}`);
for (const templatePath of templatePaths) {
const templateResolvedPath = pathResolve(cwd, templatePath);
core.debug(`Template directory ${templateResolvedPath} contents:`);
await exec.exec(`ls -allh ${templateResolvedPath}`);
}
core.debug('Output folder contents:');
await exec.exec(`ls -allh ${outputFiles}`);
}
Expand All @@ -76,7 +79,12 @@ export async function run(): Promise<void> {
core.debug(`Created temporary directory in ${tmpDir}`);

// Generate YTT templates for global workflows
const globalExtraParams: string[] = [];
const templateCommandParams = () =>
templatePaths.reduce<string[]>(
(commandParams, templatePath) => commandParams.concat('-f', pathResolve(cwd, templatePath)),
[],
);
const globalExtraParams: string[] = templateCommandParams();
config.global.workflows.forEach((workflow) => {
globalExtraParams.push('--file-mark');
globalExtraParams.push(`${workflow}:exclusive-for-output=true`);
Expand All @@ -90,16 +98,12 @@ export async function run(): Promise<void> {
globalExtraParams.push('--data-values-file');
globalExtraParams.push(globalValuesPath);
}
await exec.exec(
'ytt',
['-f', templatePath, '--output-files', outputFiles].concat(globalExtraParams),
{
listeners: {
stdout: (data: Buffer) => core.debug(data.toString()),
stderr: (error: Buffer) => core.error(error.toString()),
},
await exec.exec('ytt', ['--output-files', outputFiles].concat(globalExtraParams), {
listeners: {
stdout: (data: Buffer) => core.debug(data.toString()),
stderr: (error: Buffer) => core.error(error.toString()),
},
);
});
// Generate YTT templates for scoped workflows
for (const scope of config.scoped) {
const scopeValuesPath = pathJoin(tmpDir, `${scope.name}.yml`);
Expand All @@ -119,13 +123,11 @@ export async function run(): Promise<void> {
await exec.exec(
'ytt',
[
'-f',
templatePath,
'--data-values-file',
scopeValuesPath,
'--file-mark',
`${workflow}:exclusive-for-output=true`,
],
].concat(templateCommandParams()),
{
listeners: {
stdout: (data: Buffer) => fs.writeFileSync(scopeWorkflowPath, data),
Expand Down

0 comments on commit 12576e3

Please sign in to comment.