Skip to content

Commit

Permalink
ci: change workflow config
Browse files Browse the repository at this point in the history
  • Loading branch information
darioblanco committed Jun 11, 2021
1 parent ab0b9bf commit 4273823
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflow-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ global:
values:
renovate_cronjob: '0 7,21 * * 1-5'
workflows:
- pr.yml
- file: pr.yml

scoped:
- name: my-app
Expand All @@ -12,4 +12,4 @@ scoped:
qa_url: 'https://qa.darioblanco.com'
stage_url: 'https://stage.darioblanco.com'
workflows:
- deployment-trigger.yml
- file: deployment-trigger.yml
2 changes: 1 addition & 1 deletion dist/run.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ export async function run(): Promise<void> {
[],
);
const globalExtraParams: string[] = templateCommandParams();
config.global.workflows.forEach((workflow) => {
config.global.workflows.forEach(({ file, overlays }) => {
globalExtraParams.push('--file-mark');
globalExtraParams.push(`${workflow}:exclusive-for-output=true`);
globalExtraParams.push(`${file}:exclusive-for-output=true`);
if (overlays) {
overlays.forEach((overlay) => {
globalExtraParams.push('--file-mark');
globalExtraParams.push(`${overlay}:exclusive-for-output=true`);
});
}
});
if (config.global.overlays) {
config.global.overlays.forEach((overlay) => {
globalExtraParams.push('--file-mark');
globalExtraParams.push(`${overlay}:exclusive-for-output=true`);
});
}
if (!config.global) {
throw Error(`The "global" configuration key is required in ${configPath}`);
}
Expand All @@ -120,17 +120,17 @@ export async function run(): Promise<void> {
const serializedValues: string = yaml.dump(scope.values);
core.debug(`Serialized values:\n${serializedValues}`);
fs.writeFileSync(scopeValuesPath, serializedValues);
for (const workflow of scope.workflows) {
const workflowBits = workflow.split('.');
for (const { file: workflowFile, overlays } of scope.workflows) {
const workflowBits = workflowFile.split('.');
const scopeWorkflowName = workflowBits
.slice(0, -1)
.concat(scope.name, workflowBits.slice(-1))
.join('.');
const scopeWorkflowPath = pathJoin(outputFiles, scopeWorkflowName);
core.debug(`Process workflow ${workflow} into ${scopeWorkflowPath} ...`);
const fileMarks = ['--file-mark', `${workflow}:exclusive-for-output=true`];
if (scope.overlays) {
scope.overlays.forEach((overlay) => {
core.debug(`Process workflow ${workflowFile} into ${scopeWorkflowPath} ...`);
const fileMarks = ['--file-mark', `${workflowFile}:exclusive-for-output=true`];
if (overlays) {
overlays.forEach((overlay) => {
fileMarks.push('--file-mark');
fileMarks.push(`${overlay}:exclusive-for-output=true`);
});
Expand Down
10 changes: 6 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
interface Workflow {
file: string;
overlays?: string[];
}
export interface Config {
global: {
overlays?: string[];
values?: Record<string, string>;
workflows: string[];
workflows: Workflow[];
};
scoped: {
name: string;
overlays?: string[];
values?: Record<string, string>;
workflows: string[];
workflows: Workflow[];
}[];
}
14 changes: 7 additions & 7 deletions test/workflow-creator.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
global:
values:
workflows:
- deployment.yml
- docs.yml
- pr.yml
- release-draft.yml
- workflow-creator.yml
- file: deployment.yml
- file: docs.yml
- file: pr.yml
- file: release-draft.yml
- file: workflow-creator.yml

scoped:
- name: my-app
values:
my_value: 'my-app'
workflows:
- check.yml
- deployment-trigger.yml
- file: check.yml
- file: deployment-trigger.yml

0 comments on commit 4273823

Please sign in to comment.