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

81 lines
2.0 KiB
V
Raw Normal View History

2023-03-28 23:55:57 +03:00
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
import os
import time
const fast_dir = os.dir(@FILE)
const vdir = os.dir(os.dir(os.dir(fast_dir)))
const vexe = os.join_path(vdir, 'v')
2022-11-01 16:49:23 +03:00
const sleep_period = 120
fn elog(msg string) {
eprintln('${time.now().format_ss_micro()} ${msg}')
}
2022-11-01 16:49:23 +03:00
fn delay() {
elog('Sleeping for ${sleep_period} seconds...')
2022-11-01 16:49:23 +03:00
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() {
2022-11-01 16:49:23 +03:00
os.setenv('LANG', 'C', true)
elog('fast_job fast_dir: ${fast_dir} | vdir: ${vdir} | vexe: ${vexe}')
os.chdir(fast_dir)!
elog('fast_job start in os.getwd(): ${os.getwd()}')
defer {
elog('fast_job end')
}
2022-11-01 16:49:23 +03:00
if !os.exists('website') {
println('cloning the website repo...')
os.system('git clone --filter=blob:none git@github.com:/vlang/website.git')
}
for {
2022-11-01 16:49:23 +03:00
elog('------------------- Checking for updates ... -------------------')
res_pull := os.execute('git pull --rebase')
elog('> res_pull.output: ${res_pull.output}')
if res_pull.exit_code != 0 {
elog('Git pull failed. You may have uncommitted changes?')
2022-11-01 16:49:23 +03:00
delay()
continue
}
if res_pull.output.contains('Already up to date.') {
if os.args.contains('-force-update') {
2022-11-01 16:49:23 +03:00
elog('The repository was already updated, but -force-update was passed too.')
} else {
delay()
continue
}
}
2022-11-01 16:49:23 +03:00
elog('recompiling V')
os.system('${os.quoted_path(vexe)} self')
os.system('ls -la ${os.quoted_path(vexe)}')
2022-11-01 16:49:23 +03:00
elog('recompiling ./fast')
recompile_fast_v_code := os.system('${os.quoted_path(vexe)} fast.v')
if recompile_fast_v_code != 0 {
elog('WARNING: could not recompile fast.v')
delay()
continue
}
2022-11-01 16:49:23 +03:00
os.system('ls -la fast fast.v')
elog('running ./fast -upload')
fast_exit_code := os.system('./fast -upload')
if fast_exit_code != 0 {
println('fast_exit_code = ${fast_exit_code}, != 0')
}
2022-11-01 16:49:23 +03:00
delay()
}
}