Skip to content

Commit

Permalink
feat: added support for parsing github-output vars
Browse files Browse the repository at this point in the history
  • Loading branch information
im-sampm-demo authored and im-sampm committed Jan 6, 2024
1 parent cde04aa commit 00ef129
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/act/act.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const DEFAULT_JOB: Step = {
name: "",
status: -1,
output: "",
outputs: {},
};

export const ACT_BINARY = process.env["ACT_BINARY"] ?? path.resolve(__dirname, "..", "..", "bin", "act");
1 change: 1 addition & 0 deletions src/act/act.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Step = {
name: string;
status: number;
output: string;
outputs: Record<string, string>;
groups?: Group[];
};

Expand Down
22 changes: 22 additions & 0 deletions src/output-parser/output-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class OutputParser {
// keep track of output for the current step of a job
private outputMatrix: Record<string, string>;

private outputsMatrix: Record<string, Record<string, string>>;

// keep track of groups for the current step of a job
private groupMatrix: Record<string, Group[]>;

Expand All @@ -19,6 +21,7 @@ export class OutputParser {
this.output = output;
this.stepMatrix = {};
this.outputMatrix = {};
this.outputsMatrix = {};
this.groupMatrix = {};
this.isPartOfGroup = {};
}
Expand All @@ -37,6 +40,7 @@ export class OutputParser {
this.parseStartGroup(line);
this.parseEndGroup(line);
this.parseStepOutput(line);
this.parseStepOutputs(line);
}

const result: Step[] = [];
Expand All @@ -63,6 +67,7 @@ export class OutputParser {
if (!this.stepMatrix[runMatcherResult[1]]) {
this.stepMatrix[runMatcherResult[1]] = {};
this.outputMatrix[runMatcherResult[1]] = "";
this.outputsMatrix[runMatcherResult[1]] = {};
this.groupMatrix[runMatcherResult[1]] = [];
}

Expand Down Expand Up @@ -94,6 +99,7 @@ export class OutputParser {
],
status: 0,
output: this.outputMatrix[successMatcherResult[1]].trim(),
outputs: this.outputsMatrix[successMatcherResult[1]],
// only add groups attribute if there are any. don't add empty array
...(groups.length > 0 ? { groups } : {}),
};
Expand Down Expand Up @@ -121,6 +127,7 @@ export class OutputParser {
],
status: 1,
output: this.outputMatrix[failureMatcherResult[1]].trim(),
outputs: this.outputsMatrix[failureMatcherResult[1]],
};

this.resetOutputAndGroupMatrix(failureMatcherResult[1]);
Expand Down Expand Up @@ -150,6 +157,21 @@ export class OutputParser {
}
}

/**
* Check if the line contains a set-output annotation. If it does then parse
* and store the output
* @param line
*/
private parseStepOutputs(line: string) {
const stepOutputsMatcher = /^\s*(\[.+\])\s*\u2699\s*::set-output::\s*(.*)=(.*)/;
const stepOutputsMatcherResult = stepOutputsMatcher.exec(line);

// if the line is an output line
if (stepOutputsMatcherResult !== null) {
this.outputsMatrix[stepOutputsMatcherResult[1]][stepOutputsMatcherResult[2]] = stepOutputsMatcherResult[3];
}
}

/**
* Check if the line indicates the end of a group annotation. If it does then accordingly
* update the bookkeeping variables
Expand Down

0 comments on commit 00ef129

Please sign in to comment.