Skip to content

Commit ade5aba

Browse files
authored
Merge pull request #13807 from quarto-dev/gha/improve-logging
GHA TESTS - Improve logging to group in the right place and reduce log in CI in non debug mode
2 parents a6e37ac + f664f1c commit ade5aba

6 files changed

Lines changed: 93 additions & 38 deletions

File tree

.github/workflows/test-smokes.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,19 @@ jobs:
264264
env:
265265
# Useful as TinyTeX latest release is checked in run-test.sh
266266
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
267-
QUARTO_LOG_LEVEL: DEBUG
268267
run: |
269268
haserror=0
270269
failed_tests=()
271270
readarray -t my_array < <(echo '${{ inputs.buckets }}' | jq -rc '.[]')
272271
for file in "${my_array[@]}"; do
272+
echo "::group::Testing ${file}"
273273
echo ">>> ./run-tests.sh ${file}"
274274
# Run tests without -e so we don't exit on first failure
275275
set +e
276276
shopt -s globstar && ./run-tests.sh "$file"
277277
status=$?
278278
set -e
279+
echo "::endgroup::"
279280
if [ $status -ne 0 ]; then
280281
echo "::error title=Test Bucket Failed::Test bucket ${file} failed with exit code ${status}"
281282
echo ">>> Error found in test file: ${file}"
@@ -305,9 +306,11 @@ jobs:
305306
$haserror=$false
306307
$failed_tests=@()
307308
foreach ($file in ('${{ inputs.buckets }}' | ConvertFrom-Json)) {
309+
Write-Host "::group::Testing ${file}"
308310
Write-Host ">>> ./run-tests.ps1 ${file}"
309311
./run-tests.ps1 $file
310312
$status=$LASTEXITCODE
313+
Write-Host "::endgroup::"
311314
if ($status -ne 0) {
312315
Write-Host "::error title=Test Bucket Failed::Test bucket ${file} failed with exit code ${status}"
313316
Write-Host ">>> Error found in test file: ${file}"

src/core/log.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { onCleanup } from "./cleanup.ts";
2222
import { execProcess } from "./process.ts";
2323
import { pandocBinaryPath } from "./resources.ts";
2424
import { Block, pandoc } from "./pandoc/json.ts";
25+
import { isGitHubActions, isVerboseMode } from "../tools/github.ts";
2526

2627
export type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR" | "CRITICAL";
2728
export type LogFormat = "plain" | "json-stream";
@@ -99,8 +100,17 @@ export function logOptions(args: Args) {
99100
if (logOptions.log) {
100101
ensureDirSync(dirname(logOptions.log));
101102
}
102-
logOptions.level = args.ll || args["log-level"] ||
103-
Deno.env.get("QUARTO_LOG_LEVEL");
103+
104+
// Determine log level with priority: explicit args > QUARTO_LOG_LEVEL > GitHub Actions debug mode
105+
let level = args.ll || args["log-level"] || Deno.env.get("QUARTO_LOG_LEVEL");
106+
107+
// Enable DEBUG logging when GitHub Actions debug mode is on (RUNNER_DEBUG=1)
108+
// Can be overridden by explicit --log-level or QUARTO_LOG_LEVEL
109+
if (!level && isGitHubActions() && isVerboseMode()) {
110+
level = "DEBUG";
111+
}
112+
113+
logOptions.level = level;
104114
logOptions.quiet = args.q || args.quiet;
105115
logOptions.format = parseFormat(
106116
args.lf || args["log-format"] || Deno.env.get("QUARTO_LOG_FORMAT"),

src/tools/github.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ export function error(
6161
message: string,
6262
properties?: AnnotationProperties,
6363
): void {
64-
if (!isGitHubActions()) return;
64+
if (!isGitHubActions()) {
65+
console.log(message);
66+
return;
67+
}
6568
const props = properties ? formatProperties(properties) : "";
6669
console.log(`::error${props}::${escapeData(message)}`);
6770
}
@@ -70,7 +73,10 @@ export function warning(
7073
message: string,
7174
properties?: AnnotationProperties,
7275
): void {
73-
if (!isGitHubActions()) return;
76+
if (!isGitHubActions()) {
77+
console.log(message);
78+
return;
79+
}
7480
const props = properties ? formatProperties(properties) : "";
7581
console.log(`::warning${props}::${escapeData(message)}`);
7682
}
@@ -79,7 +85,10 @@ export function notice(
7985
message: string,
8086
properties?: AnnotationProperties,
8187
): void {
82-
if (!isGitHubActions()) return;
88+
if (!isGitHubActions()) {
89+
console.log(message);
90+
return;
91+
}
8392
const props = properties ? formatProperties(properties) : "";
8493
console.log(`::notice${props}::${escapeData(message)}`);
8594
}
@@ -96,6 +105,10 @@ export function endGroup(): void {
96105
}
97106

98107
export function withGroup<T>(title: string, fn: () => T): T {
108+
if (!isGitHubActions()) {
109+
console.log(title);
110+
return fn();
111+
}
99112
startGroup(title);
100113
try {
101114
return fn();
@@ -108,6 +121,10 @@ export async function withGroupAsync<T>(
108121
title: string,
109122
fn: () => Promise<T>,
110123
): Promise<T> {
124+
if (!isGitHubActions()) {
125+
console.log(title);
126+
return await fn();
127+
}
111128
startGroup(title);
112129
try {
113130
return await fn();

tests/integration/playwright-tests.test.ts

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { execProcess } from "../../src/core/process.ts";
1616
import { quartoDevCmd } from "../utils.ts";
1717
import { fail } from "testing/asserts";
1818
import { isWindows } from "../../src/deno_ral/platform.ts";
19-
import { join } from "../../src/deno_ral/path.ts";
19+
import { join, relative } from "../../src/deno_ral/path.ts";
2020
import { existsSync } from "../../src/deno_ral/fs.ts";
2121
import * as gha from "../../src/tools/github.ts";
2222

@@ -37,7 +37,6 @@ await initState();
3737
const multiplexServerPath = "integration/playwright/multiplex-server";
3838
const multiplexNodeModules = join(multiplexServerPath, "node_modules");
3939
if (!existsSync(multiplexNodeModules)) {
40-
console.log("Installing multiplex server dependencies...");
4140
await execProcess({
4241
cmd: isWindows ? "npm.cmd" : "npm",
4342
args: ["install", "--loglevel=error"],
@@ -48,44 +47,66 @@ if (!existsSync(multiplexNodeModules)) {
4847

4948
// const promises = [];
5049
const fileNames: string[] = [];
51-
const extraOpts = [
52-
{
53-
pathSuffix: "docs/playwright/embed-resources/issue-11860/main.qmd",
54-
options: ["--output-dir=inner"],
55-
}
56-
]
5750

58-
for (const { path: fileName } of globOutput) {
59-
const input = fileName;
60-
const options: string[] = [];
61-
for (const extraOpt of extraOpts) {
62-
if (fileName.endsWith(extraOpt.pathSuffix)) {
63-
options.push(...extraOpt.options);
51+
// To avoid re-rendering, see QUARTO_PLAYWRIGHT_SKIP_RENDER env var
52+
if (Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_RENDER") === "true") {
53+
console.log("Skipping render of test documents.");
54+
} else {
55+
const extraOpts = [
56+
{
57+
pathSuffix: "docs/playwright/embed-resources/issue-11860/main.qmd",
58+
options: ["--output-dir=inner"],
6459
}
65-
}
60+
]
6661

67-
// sigh, we have a race condition somewhere in
68-
// mediabag inspection if we don't wait all renders
69-
// individually. This is very slow..
70-
await execProcess({
71-
cmd: quartoDevCmd(),
72-
args: ["render", input, ...options],
73-
});
74-
fileNames.push(fileName);
62+
for (const { path: fileName } of globOutput) {
63+
const input = relative(Deno.cwd(), fileName);
64+
const options: string[] = [];
65+
for (const extraOpt of extraOpts) {
66+
if (fileName.endsWith(extraOpt.pathSuffix)) {
67+
options.push(...extraOpt.options);
68+
}
69+
}
70+
71+
// sigh, we have a race condition somewhere in
72+
// mediabag inspection if we don't wait all renders
73+
// individually. This is very slow..
74+
console.log(`Rendering ${input}...`);
75+
const result = await execProcess({
76+
cmd: quartoDevCmd(),
77+
args: ["render", input, ...options],
78+
stdout: "piped",
79+
stderr: "piped",
80+
});
81+
82+
if (!result.success) {
83+
gha.error(`Failed to render ${input}`)
84+
if (result.stdout) console.log(result.stdout);
85+
if (result.stderr) console.error(result.stderr);
86+
throw new Error(`Render failed with code ${result.code}`);
87+
}
88+
89+
fileNames.push(fileName);
90+
}
7591
}
7692

7793
Deno.test({
7894
name: "Playwright tests are passing",
7995
// currently we run playwright tests only on Linux
80-
ignore: isWindows,
96+
ignore: gha.isGitHubActions() && isWindows,
8197
fn: async () => {
8298
try {
8399
// run playwright
84100
const res = await execProcess({
85-
cmd: isWindows ? "npx.cmd" : "npx",
101+
cmd: isWindows ? "npx.cmd" : "npx",
86102
args: ["playwright", "test", "--ignore-snapshots"],
87103
cwd: "integration/playwright",
88-
});
104+
},
105+
undefined, // stdin
106+
undefined, // mergeOutput
107+
undefined, // stderrFilter
108+
true // respectStreams - write directly to stderr/stdout
109+
);
89110
if (!res.success) {
90111
if (gha.isGitHubActions() && Deno.env.get("GITHUB_REPOSITORY") && Deno.env.get("GITHUB_RUN_ID")) {
91112
const runUrl = `https://github.com/${Deno.env.get("GITHUB_REPOSITORY")}/actions/runs/${Deno.env.get("GITHUB_RUN_ID")}`;
@@ -99,11 +120,15 @@ Deno.test({
99120
}
100121
fail("Failed tests with playwright. Look at playwright report for more details.")
101122
}
102-
123+
103124
} finally {
104-
for (const fileName of fileNames) {
105-
cleanoutput(fileName, "html");
106-
}
125+
// skip cleanoutput if requested
126+
if (Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_CLEANOUTPUT") === "true" || Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_RENDER") === "true") {
127+
console.log("Skipping cleanoutput of test documents.");
128+
} else
129+
for (const fileName of fileNames) {
130+
cleanoutput(fileName, "html");
131+
}
107132
}
108133
}
109134
});

tests/integration/playwright/playwright.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default defineConfig({
101101
url: 'http://127.0.0.1:8080',
102102
reuseExistingServer: !isCI,
103103
cwd: '../../docs/playwright',
104+
stderr: 'ignore', // Suppress verbose HTTP request logs
104105
},
105106
{
106107
// Socket.IO multiplex server for RevealJS
@@ -109,6 +110,7 @@ export default defineConfig({
109110
reuseExistingServer: !isCI,
110111
cwd: './multiplex-server',
111112
timeout: 10000,
113+
stderr: 'ignore', // Suppress verbose logs
112114
}
113115
],
114116
});

tests/run-tests.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,12 @@ else
117117
TESTS_TO_RUN=""
118118
if [[ ! -z "$*" ]]; then
119119
for file in "$*"; do
120-
echo $file
121120
filename=$(basename "$file")
122121
# smoke-all.test.ts works with .qmd, .md and .ipynb but will ignored file starting with _
123122
if [[ $filename =~ ^[^_].*[.]qmd$ ]] || [[ $filename =~ ^[^_].*[.]ipynb$ ]] || [[ $filename =~ ^[^_].*[.]md$ ]]; then
124123
SMOKE_ALL_FILES="${SMOKE_ALL_FILES} ${file}"
125124
elif [[ $file =~ .*[.]ts$ ]]; then
126125
TESTS_TO_RUN="${TESTS_TO_RUN} ${file}"
127-
echo $TESTS_TO_RUN
128126
else
129127
echo "#### WARNING"
130128
echo "Only .ts, or .qmd, .md and .ipynb passed to smoke-all.test.ts are accepted (file starting with _ are ignored)."

0 commit comments

Comments
 (0)