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 an option for logging tasks for Github Actions #16

Open
wants to merge 1 commit into
base: master
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
4 changes: 4 additions & 0 deletions lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class Env {
"--abort-exits": false,
"--always-make": false,
"--dry-run": false,
"--github-actions": false,
"--help": false,
"--list-all": false,
"--list-tasks": false,
Expand All @@ -38,6 +39,7 @@ export class Env {
case "--always-make":
case "--debug":
case "--dry-run":
case "--github-actions":
case "--help":
case "--list-all":
case "--list-tasks":
Expand Down Expand Up @@ -130,6 +132,7 @@ export class Env {
"-D": "--debug",
"-d": "--directory",
"-n": "--dry-run",
"-g": "--github-actions",
"-h": "--help",
"-l": "--list-tasks",
"-L": "--list-all",
Expand All @@ -141,6 +144,7 @@ export class Env {
switch (arg) {
case "--always-make":
case "--debug":
case "--github-actions":
case "--dry-run":
case "--help":
case "--list-tasks":
Expand Down
1 change: 1 addition & 0 deletions lib/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OPTIONS
-a, --always-make Unconditionally execute tasks.
--cache FILE Set Drake cache file path to FILE.
-d, --directory DIR Change to directory DIR before running drakefile.
-g, --github-actions logs expandable targets for Github Actions
-D, --debug Write debug information to stderr.
-h, --help Display this help message.
-l, -L, --list-tasks List tasks (-L for hidden tasks and prerequisites).
Expand Down
14 changes: 11 additions & 3 deletions lib/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export class TaskRegistry extends Map<string, Task> {
let msg = "";
let startTime: number = 0;
if (names.length === 1) {
msg = `${colors.green(colors.bold(`${names[0]}:`))}`;
msg = `${colors.green(colors.bold(`${names[0]}` + (env("--github-actions") ? "" : ":")))}`;
} else {
msg = colors.green(colors.bold(`execute ${names.length} tasks:`));
log(`${msg} started`);
Expand All @@ -432,7 +432,11 @@ export class TaskRegistry extends Map<string, Task> {
continue;
}
if (names.length === 1) {
log(`${msg} started`);
if (env("--github-actions")) {
log(`::group::${msg}`)
} else {
log(`${msg} started`);
}
startTime = new Date().getTime();
}
if (task.action.constructor.name === "AsyncFunction") {
Expand All @@ -447,7 +451,11 @@ export class TaskRegistry extends Map<string, Task> {
task.updateCache();
}
if (startTime) {
log(`${msg} finished (${new Date().getTime() - startTime}ms)`);
if (env("--github-actions")) {
log("::endgroup::");
} else {
log(`${msg} finished (${new Date().getTime() - startTime}ms)`);
}
}
}
}
Expand Down