From 7d89e8693f1cb9936947415fd35a16b2dd5e0d8f Mon Sep 17 00:00:00 2001 From: Mitch Date: Thu, 21 Sep 2023 09:55:32 -0500 Subject: [PATCH 1/3] Go side: add task prefixing in Github actions --- cli/internal/run/run.go | 4 ++- .../integration/tests/ordered/github.t | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index 6dab57705b9bc..b1b034b6e00fa 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -134,7 +134,9 @@ func configureRun(base *cmdutil.CmdBase, opts *Opts, signalWatcher *signals.Watc // that they want it. This should be fixed in Go and Rust at the same time. if opts.runOpts.LogOrder == "auto" && ci.Constant() == "GITHUB_ACTIONS" { opts.runOpts.LogOrder = "grouped" - opts.runOpts.LogPrefix = "none" + if opts.runOpts.LogPrefix != "task" { + opts.runOpts.LogPrefix = "none" + } opts.runOpts.IsGithubActions = true } diff --git a/turborepo-tests/integration/tests/ordered/github.t b/turborepo-tests/integration/tests/ordered/github.t index a2e205f179ade..638b220117a66 100644 --- a/turborepo-tests/integration/tests/ordered/github.t +++ b/turborepo-tests/integration/tests/ordered/github.t @@ -33,6 +33,36 @@ because otherwise prysk interprets them as multiline commands Cached: 0 cached, 2 total Time:\s*[\.0-9]+m?s (re) +# Build as if we are in Github Actions with a task log prefix. + $ export GITHUB_ACTIONS=1 + $ ${TURBO} run build --force --log-prefix="task" + \xe2\x80\xa2 Packages in scope: my-app, util (esc) + \xe2\x80\xa2 Running build in 2 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + ::group::my-app:build + my-app:build: cache bypass, force executing 4c3a4e8d472d74b2 + my-app:build: + my-app:build: > build + my-app:build: > echo 'building' && sleep 1 && echo 'done' + my-app:build: + my-app:build: building + my-app:build: done + ::endgroup:: + ::group::util:build + util:build: cache bypass, force executing 90d7154e362e3386 + util:build: + util:build: > build + util:build: > sleep 0.5 && echo 'building' && sleep 1 && echo 'completed' + util:build: + util:build: building + util:build: completed + ::endgroup:: + + Tasks: 2 successful, 2 total + Cached: 0 cached, 2 total + Time:\s*[\.0-9]+m?s (re) + + Verify that errors are grouped properly $ ${TURBO} run fail \xe2\x80\xa2 Packages in scope: my-app, util (esc) From 416d0b9e12c7e349f8e04ee97d83143e4121307c Mon Sep 17 00:00:00 2001 From: Mitch Date: Thu, 21 Sep 2023 10:32:06 -0500 Subject: [PATCH 2/3] add Rust fix for gh action log prefix --- cli/internal/run/run.go | 3 --- crates/turborepo-lib/src/opts.rs | 15 +++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index b1b034b6e00fa..1ca8cfdb56184 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -129,9 +129,6 @@ func optsFromArgs(args *turbostate.ParsedArgsFromRust) (*Opts, error) { } func configureRun(base *cmdutil.CmdBase, opts *Opts, signalWatcher *signals.Watcher) *run { - // TODO: We currently don't respect the user's input if they ask for task prefixes on - // GitHub Actions and forcibly strip tasks from their logs even if they specify - // that they want it. This should be fixed in Go and Rust at the same time. if opts.runOpts.LogOrder == "auto" && ci.Constant() == "GITHUB_ACTIONS" { opts.runOpts.LogOrder = "grouped" if opts.runOpts.LogPrefix != "task" { diff --git a/crates/turborepo-lib/src/opts.rs b/crates/turborepo-lib/src/opts.rs index 93a070700a7e9..fcb8354fd0c01 100644 --- a/crates/turborepo-lib/src/opts.rs +++ b/crates/turborepo-lib/src/opts.rs @@ -114,12 +114,15 @@ impl<'a> TryFrom<&'a RunArgs> for RunOpts<'a> { }); let (is_github_actions, log_order, log_prefix) = match args.log_order { - // TODO: We currently don't respect the user's input if they ask for task prefixes on - // GitHub Actions and forcibly strip tasks from their logs even if they specify - // that they want it. This should be fixed in Go and Rust at the same time. - LogOrder::Auto if turborepo_ci::Vendor::get_constant() == Some("GITHUB_ACTIONS") => { - (true, ResolvedLogOrder::Grouped, ResolvedLogPrefix::None) - } + LogOrder::Auto if turborepo_ci::Vendor::get_constant() == Some("GITHUB_ACTIONS") => ( + true, + ResolvedLogOrder::Grouped, + match args.log_prefix { + LogPrefix::Task => ResolvedLogPrefix::Task, + _ => ResolvedLogPrefix::None, + }, + ), + // Streaming is the default behavior except when running on GitHub Actions LogOrder::Auto | LogOrder::Stream => { (false, ResolvedLogOrder::Stream, args.log_prefix.into()) From b67a7e4a9c9e30f601c5bacfeed8b8ce00db696f Mon Sep 17 00:00:00 2001 From: Mitch Date: Thu, 21 Sep 2023 14:17:44 -0500 Subject: [PATCH 3/3] move github action env var to each test and filter flag to task test --- .../integration/tests/ordered/github.t | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/turborepo-tests/integration/tests/ordered/github.t b/turborepo-tests/integration/tests/ordered/github.t index 638b220117a66..04f70383e8116 100644 --- a/turborepo-tests/integration/tests/ordered/github.t +++ b/turborepo-tests/integration/tests/ordered/github.t @@ -5,8 +5,7 @@ # Build as if we are in Github Actions Note that we need to use (re) for lines that start with '> ' because otherwise prysk interprets them as multiline commands - $ export GITHUB_ACTIONS=1 - $ ${TURBO} run build --force + $ GITHUB_ACTIONS=1 ${TURBO} run build --force \xe2\x80\xa2 Packages in scope: my-app, util (esc) \xe2\x80\xa2 Running build in 2 packages (esc) \xe2\x80\xa2 Remote caching disabled (esc) @@ -34,20 +33,10 @@ because otherwise prysk interprets them as multiline commands Time:\s*[\.0-9]+m?s (re) # Build as if we are in Github Actions with a task log prefix. - $ export GITHUB_ACTIONS=1 - $ ${TURBO} run build --force --log-prefix="task" - \xe2\x80\xa2 Packages in scope: my-app, util (esc) - \xe2\x80\xa2 Running build in 2 packages (esc) + $ GITHUB_ACTIONS=1 ${TURBO} run build --force --log-prefix="task" --filter=util + \xe2\x80\xa2 Packages in scope: util (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) \xe2\x80\xa2 Remote caching disabled (esc) - ::group::my-app:build - my-app:build: cache bypass, force executing 4c3a4e8d472d74b2 - my-app:build: - my-app:build: > build - my-app:build: > echo 'building' && sleep 1 && echo 'done' - my-app:build: - my-app:build: building - my-app:build: done - ::endgroup:: ::group::util:build util:build: cache bypass, force executing 90d7154e362e3386 util:build: @@ -58,13 +47,13 @@ because otherwise prysk interprets them as multiline commands util:build: completed ::endgroup:: - Tasks: 2 successful, 2 total - Cached: 0 cached, 2 total + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total Time:\s*[\.0-9]+m?s (re) Verify that errors are grouped properly - $ ${TURBO} run fail + $ GITHUB_ACTIONS=1 ${TURBO} run fail \xe2\x80\xa2 Packages in scope: my-app, util (esc) \xe2\x80\xa2 Running fail in 2 packages (esc) \xe2\x80\xa2 Remote caching disabled (esc)