From 32ce3d914917234ece9d36e32e428fb90a0e0276 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 1 Nov 2022 15:49:23 +0200 Subject: [PATCH] tools: make fast_job.v more robust --- cmd/tools/fast/fast_job.v | 52 ++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/cmd/tools/fast/fast_job.v b/cmd/tools/fast/fast_job.v index c2db180c4b..787d4da6c2 100644 --- a/cmd/tools/fast/fast_job.v +++ b/cmd/tools/fast/fast_job.v @@ -4,44 +4,66 @@ import os import time +const vexe = @VEXE + +const sleep_period = 120 + fn elog(msg string) { eprintln('$time.now().format_ss_micro() $msg') } +fn delay() { + elog('Sleeping for $sleep_period seconds...') + time.sleep(sleep_period * time.second) +} + // A job that runs in the background, checks for repo updates, // runs fast.v, pushes the HTML result to the fast.vlang.io GH pages repo. fn main() { - elog('fast_job start') + os.chdir(os.dir(@FILE))! + os.setenv('LANG', 'C', true) + elog('fast_job start in os.getwd(): $os.getwd()') defer { elog('fast_job end') } + if !os.exists('website') { println('cloning the website repo...') os.system('git clone git@github.com:/vlang/website.git') } - if !os.exists('fast') { - println('"fast" binary (built with `v fast.v`) was not found') - return - } for { - eprintln('$time.now().format_ss_micro() checking for updates ...') + elog('------------------- Checking for updates ... -------------------') res_pull := os.execute('git pull --rebase') if res_pull.exit_code != 0 { println('failed to git pull. uncommitted changes?') - return + println('res_pull.output: $res_pull.output') + delay() + continue } - // println('running ./fast') + if res_pull.output.contains('Already up to date.') { + if os.args[1] or { '' } == '-force-update' { + elog('The repository was already updated, but -force-update was passed too.') + } else { + elog('Already updated.') + delay() + continue + } + } + + elog('recompiling V') + os.system('${os.quoted_path(vexe)} self') + + elog('recompiling ./fast') + os.execute('${os.quoted_path(vexe)} fast.v') + os.system('ls -la fast fast.v') + elog('running ./fast -upload') resp := os.execute('./fast -upload') - if resp.exit_code < 0 { - println(resp.output) - return - } if resp.exit_code != 0 { - println('resp != 0, skipping') + println('resp.exit_code = $resp.exit_code != 0') println(resp.output) } - elog('sleeping for 180 seconds...') - time.sleep(180 * time.second) + + delay() } }