From ebec36db2df34497a617720f037d5a92fba3735c Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Wed, 13 Aug 2025 10:19:44 -0400 Subject: [PATCH 1/4] Fold output in Github Actions --- README.md | 4 ++++ changes/new-Fold-output-in-20250813-101858.md | 1 + src/linpkg/linlib.nim | 6 ++++++ 3 files changed, 11 insertions(+) create mode 100644 changes/new-Fold-output-in-20250813-101858.md diff --git a/README.md b/README.md index 92fc34c..a1b401d 100644 --- a/README.md +++ b/README.md @@ -82,3 +82,7 @@ Go [read the full docs](https://www.iffycan.com/lin/linlib.html), but here's a h Other helpful hints: - Sequences can include other sequences, thus chaining them together. See the `includes` param. + +# GitHub Actions + +When run on a Github Actions runner, step output will be put into folds by default. To disable this, set `LIN_DISABLE_FOLDS=true` diff --git a/changes/new-Fold-output-in-20250813-101858.md b/changes/new-Fold-output-in-20250813-101858.md new file mode 100644 index 0000000..351697c --- /dev/null +++ b/changes/new-Fold-output-in-20250813-101858.md @@ -0,0 +1 @@ +Fold output in Github Actions diff --git a/src/linpkg/linlib.nim b/src/linpkg/linlib.nim index c1b9088..8560ac8 100644 --- a/src/linpkg/linlib.nim +++ b/src/linpkg/linlib.nim @@ -297,6 +297,8 @@ proc stamp(d:Duration):string = proc run*(lin:Lin, args:openArray[string]):bool = addExitProc(resetAttributes) + let isGITHUBACTIONS = getEnv("GITHUB_ACTIONS") == "true" + let doGithubActionsGrouping = isGITHUBACTIONS and getEnv("LIN_DISABLE_FOLDS") == "" let steps = lin.collectSteps(args) let grand_start = getTime() result = true @@ -314,6 +316,8 @@ proc run*(lin:Lin, args:openArray[string]):bool = res:RunStatus start = getTime() step_total: Duration + if doGithubActionsGrouping: + echo &"::group::{fq_stepnumber} {step.fullname}" stderr.styledWrite(styleDim, "[lin] ") stderr.styledWriteLine(styleReverse, &"{fq_stepnumber} {step.fullname}") try: @@ -353,6 +357,8 @@ proc run*(lin:Lin, args:openArray[string]):bool = stderr.styledWriteLine(color, &" done {code} {step_total.stamp} {msg}") stderr.flushFile() stdout.flushFile() + if doGithubActionsGrouping: + echo "::endgroup::" if res == resFail: result = false break From eec17d9e6114d861e0e94ca3047832fc91011315 Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Wed, 13 Aug 2025 10:23:45 -0400 Subject: [PATCH 2/4] Fix flushing --- src/linpkg/linlib.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/linpkg/linlib.nim b/src/linpkg/linlib.nim index 8560ac8..b10e550 100644 --- a/src/linpkg/linlib.nim +++ b/src/linpkg/linlib.nim @@ -318,6 +318,8 @@ proc run*(lin:Lin, args:openArray[string]):bool = step_total: Duration if doGithubActionsGrouping: echo &"::group::{fq_stepnumber} {step.fullname}" + stdout.flushFile() + stderr.flushFile() stderr.styledWrite(styleDim, "[lin] ") stderr.styledWriteLine(styleReverse, &"{fq_stepnumber} {step.fullname}") try: @@ -356,9 +358,9 @@ proc run*(lin:Lin, args:openArray[string]):bool = stderr.styledWrite(color, styleReverse, &"{fq_stepnumber} {step.fullname}") stderr.styledWriteLine(color, &" done {code} {step_total.stamp} {msg}") stderr.flushFile() - stdout.flushFile() if doGithubActionsGrouping: echo "::endgroup::" + stdout.flushFile() if res == resFail: result = false break From a1c37b9f809de4568350fcc17ca97bf365c81234 Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Wed, 13 Aug 2025 10:25:34 -0400 Subject: [PATCH 3/4] Fix flushing --- src/linpkg/linlib.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/linpkg/linlib.nim b/src/linpkg/linlib.nim index b10e550..73265bd 100644 --- a/src/linpkg/linlib.nim +++ b/src/linpkg/linlib.nim @@ -354,12 +354,14 @@ proc run*(lin:Lin, args:openArray[string]):bool = color = fgCyan code = "skipped" + if doGithubActionsGrouping: + stderr.flushFile() + echo "::endgroup::" + stdout.flushFile() stderr.styledWrite(styleDim, "[lin] ") stderr.styledWrite(color, styleReverse, &"{fq_stepnumber} {step.fullname}") stderr.styledWriteLine(color, &" done {code} {step_total.stamp} {msg}") stderr.flushFile() - if doGithubActionsGrouping: - echo "::endgroup::" stdout.flushFile() if res == resFail: result = false From 9736db72d5e4bf256efb9b1e06ce6abcbf3da2f0 Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Wed, 13 Aug 2025 10:27:01 -0400 Subject: [PATCH 4/4] Fix flushing --- src/linpkg/linlib.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linpkg/linlib.nim b/src/linpkg/linlib.nim index 73265bd..9c9b101 100644 --- a/src/linpkg/linlib.nim +++ b/src/linpkg/linlib.nim @@ -317,7 +317,7 @@ proc run*(lin:Lin, args:openArray[string]):bool = start = getTime() step_total: Duration if doGithubActionsGrouping: - echo &"::group::{fq_stepnumber} {step.fullname}" + stderr.writeLine &"::group::{fq_stepnumber} {step.fullname}" stdout.flushFile() stderr.flushFile() stderr.styledWrite(styleDim, "[lin] ") @@ -356,7 +356,7 @@ proc run*(lin:Lin, args:openArray[string]):bool = if doGithubActionsGrouping: stderr.flushFile() - echo "::endgroup::" + stderr.writeLine "::endgroup::" stdout.flushFile() stderr.styledWrite(styleDim, "[lin] ") stderr.styledWrite(color, styleReverse, &"{fq_stepnumber} {step.fullname}")