Skip to content

Commit 6da1923

Browse files
committed
ci,tools: implement support for VREPEAT_SILENT=1 and v repeat -S, to only show the summary of the runs, without the progress lines
1 parent 5a4dbf1 commit 6da1923

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

.github/workflows/other_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Build the repeat tool
3939
run: ./v cmd/tools/vrepeat.v
4040
- name: Run compare_pr_to_master.v
41-
run: ./v run .github/workflows/compare_pr_to_master.v
41+
run: VREPEAT_SILENT=1 ./v run .github/workflows/compare_pr_to_master.v
4242

4343
prevent-gpl-licenses:
4444
runs-on: ubuntu-24.04

cmd/tools/vrepeat.v

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ mut:
6464
warmup int
6565
show_help bool
6666
show_output bool
67+
is_silent bool // do not print progress lines
6768
use_newline bool // use \n instead of \r, so the last line is not overwritten
6869
fail_on_regress_percent int
6970
fail_on_maxtime int // in ms
@@ -149,9 +150,19 @@ fn flushed_print(s string) {
149150
}
150151

151152
fn (mut context Context) clear_line() {
153+
if context.is_silent {
154+
return
155+
}
152156
flushed_print(context.cline)
153157
}
154158

159+
fn (mut context Context) flushed_print(s string) {
160+
if context.is_silent {
161+
return
162+
}
163+
flushed_print(s)
164+
}
165+
155166
fn (mut context Context) expand_all_commands(commands []string) []string {
156167
mut all_commands := []string{}
157168
for cmd in commands {
@@ -165,14 +176,10 @@ fn (mut context Context) expand_all_commands(commands []string) []string {
165176
scmd := cscmd.replace('{${paramk}}', paramv)
166177
new_substituted_commands << scmd
167178
}
168-
for sc in new_substituted_commands {
169-
substituted_commands << sc
170-
}
179+
substituted_commands << new_substituted_commands
171180
}
172181
}
173-
for sc in substituted_commands {
174-
all_commands << sc
175-
}
182+
all_commands << substituted_commands
176183
}
177184
mut unique := map[string]int{}
178185
for x in all_commands {
@@ -195,11 +202,11 @@ fn (mut context Context) run() {
195202
series_label := '${icmd + 1}/${context.commands.len}, ${si + 1}/${context.series}'
196203
line_prefix := '${context.cgoback}Command: ${c(tgray, cmd)}, ${series_label:9}'
197204
if context.series != 1 || context.commands.len != 1 {
198-
flushed_print(line_prefix)
205+
context.flushed_print(line_prefix)
199206
}
200207
if context.warmup > 0 {
201208
for i in 0 .. context.warmup {
202-
flushed_print('${line_prefix}, warm up run: ${i + 1:4}/${context.warmup:-4}, took: ${f64(duration) / 1000:6.1f}ms ...')
209+
context.flushed_print('${line_prefix}, warm up run: ${i + 1:4}/${context.warmup:-4}, took: ${f64(duration) / 1000:6.1f}ms ...')
203210
mut sw := time.new_stopwatch()
204211
res := os.execute(cmd)
205212
duration = i64(sw.elapsed().microseconds())
@@ -234,16 +241,15 @@ fn (mut context Context) run() {
234241
runs++
235242
avg = (f64(sum) / f64(i + 1))
236243
cavg := '${avg / 1000:9.3f}ms'
237-
flushed_print('${line_prefix}, current average: ${c(tgreen, cavg)}, run ${i + 1:4}/${context.run_count:-4}, took: ${f64(duration) / 1000:6} ms')
244+
context.flushed_print('${line_prefix}, current average: ${c(tgreen, cavg)}, run ${
245+
i + 1:4}/${context.run_count:-4}, took: ${f64(duration) / 1000:6} ms')
238246
if context.show_output {
239-
flushed_print(' | result: ${oldres:s}')
247+
context.flushed_print(' | result: ${oldres:s}')
240248
}
241249
trimmed_output := res.output.trim_right('\r\n')
242250
trimmed_normalized := trimmed_output.replace('\r\n', '\n')
243251
lines := trimmed_normalized.split('\n')
244-
for line in lines {
245-
context.results[icmd].outputs << line
246-
}
252+
context.results[icmd].outputs << lines
247253
context.results[icmd].timings << duration
248254
oldres = res.output.replace('\n', ' ')
249255
if should_show_fail_output {
@@ -257,7 +263,7 @@ fn (mut context Context) run() {
257263
context.results[icmd].atiming = new_aints(context.results[icmd].timings, context.nmins,
258264
context.nmaxs)
259265
context.clear_line()
260-
flushed_print(context.cgoback)
266+
context.flushed_print(context.cgoback)
261267
context.show_timings_details(si, icmd, cmd)
262268
}
263269
}
@@ -421,6 +427,10 @@ fn (mut context Context) parse_options() ! {
421427
context.ignore_failed = fp.bool('ignore', `e`, false, 'Ignore failed commands (returning a non 0 exit code).')
422428
context.no_vexe_setenv = fp.bool('no_vexe_reset', `N`, false, 'Do not reset the VEXE env variable at the start. \n By default, VEXE will be set to "", to allow for measuring different V executables. Use this option to override it')
423429
context.use_newline = fp.bool('newline', `n`, false, 'Use \\n, do not overwrite the last line. Produces more output, but easier to diagnose.')
430+
context.is_silent = fp.bool('silent', `S`, false, 'Do not show progress lines, print only the final summary. Suitable for CIs.')
431+
if os.getenv('VREPEAT_SILENT') != '' {
432+
context.is_silent = true
433+
}
424434
context.show_output = fp.bool('output', `O`, false, 'Show command stdout/stderr in the progress indicator for each command. Note: slower, for verbose commands.')
425435
context.verbose = fp.bool('verbose', `v`, false, 'Be more verbose.')
426436
context.fail_on_maxtime = fp.int('max_time', `m`, max_time, 'Fail with exit code 2, when first cmd takes above M milliseconds (regression). Default: ${max_time}')

0 commit comments

Comments
 (0)