Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for parsing github-output vars #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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*(.*)=(.*)/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, if this gets done, we can generalize it to other side effects, e.g.:

[Android Build/Unit Tests]   ✅  Success - Main Set up Java for Android SDK.
[Android Build/Unit Tests]   ⚙  ::set-env:: JAVA_HOME=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.10-7/x64
[Android Build/Unit Tests]   ⚙  ::set-env:: JAVA_HOME_17_X64=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.10-7/x64
[Android Build/Unit Tests]   ⚙  ::set-output:: distribution=Temurin-Hotspot
[Android Build/Unit Tests]   ⚙  ::set-output:: path=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.10-7/x64
[Android Build/Unit Tests]   ⚙  ::set-output:: version=17.0.10+7
[Android Build/Unit Tests]   ⚙  ::add-path:: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.10-7/x64/bin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#73

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
Loading