1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: make fast_job.v more robust

This commit is contained in:
Delyan Angelov 2022-11-01 15:49:23 +02:00
parent edb3f1df32
commit 32ce3d9149
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -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()
}
}