|
4 | 4 | import os |
5 | 5 | import time |
6 | 6 |
|
| 7 | +const vexe = @VEXE |
| 8 | + |
| 9 | +const sleep_period = 120 |
| 10 | + |
7 | 11 | fn elog(msg string) { |
8 | 12 | eprintln('$time.now().format_ss_micro() $msg') |
9 | 13 | } |
10 | 14 |
|
| 15 | +fn delay() { |
| 16 | + elog('Sleeping for $sleep_period seconds...') |
| 17 | + time.sleep(sleep_period * time.second) |
| 18 | +} |
| 19 | + |
11 | 20 | // A job that runs in the background, checks for repo updates, |
12 | 21 | // runs fast.v, pushes the HTML result to the fast.vlang.io GH pages repo. |
13 | 22 | fn main() { |
14 | | - elog('fast_job start') |
| 23 | + os.chdir(os.dir(@FILE))! |
| 24 | + os.setenv('LANG', 'C', true) |
| 25 | + elog('fast_job start in os.getwd(): $os.getwd()') |
15 | 26 | defer { |
16 | 27 | elog('fast_job end') |
17 | 28 | } |
| 29 | + |
18 | 30 | if !os.exists('website') { |
19 | 31 | println('cloning the website repo...') |
20 | 32 | os.system('git clone git@github.com:/vlang/website.git') |
21 | 33 | } |
22 | | - if !os.exists('fast') { |
23 | | - println('"fast" binary (built with `v fast.v`) was not found') |
24 | | - return |
25 | | - } |
26 | 34 | for { |
27 | | - eprintln('$time.now().format_ss_micro() checking for updates ...') |
| 35 | + elog('------------------- Checking for updates ... -------------------') |
28 | 36 | res_pull := os.execute('git pull --rebase') |
29 | 37 | if res_pull.exit_code != 0 { |
30 | 38 | println('failed to git pull. uncommitted changes?') |
31 | | - return |
| 39 | + println('res_pull.output: $res_pull.output') |
| 40 | + delay() |
| 41 | + continue |
| 42 | + } |
| 43 | + if res_pull.output.contains('Already up to date.') { |
| 44 | + if os.args[1] or { '' } == '-force-update' { |
| 45 | + elog('The repository was already updated, but -force-update was passed too.') |
| 46 | + } else { |
| 47 | + elog('Already updated.') |
| 48 | + delay() |
| 49 | + continue |
| 50 | + } |
32 | 51 | } |
33 | | - // println('running ./fast') |
| 52 | + |
| 53 | + elog('recompiling V') |
| 54 | + os.system('${os.quoted_path(vexe)} self') |
| 55 | + |
| 56 | + elog('recompiling ./fast') |
| 57 | + os.execute('${os.quoted_path(vexe)} fast.v') |
| 58 | + os.system('ls -la fast fast.v') |
| 59 | + |
34 | 60 | elog('running ./fast -upload') |
35 | 61 | resp := os.execute('./fast -upload') |
36 | | - if resp.exit_code < 0 { |
37 | | - println(resp.output) |
38 | | - return |
39 | | - } |
40 | 62 | if resp.exit_code != 0 { |
41 | | - println('resp != 0, skipping') |
| 63 | + println('resp.exit_code = $resp.exit_code != 0') |
42 | 64 | println(resp.output) |
43 | 65 | } |
44 | | - elog('sleeping for 180 seconds...') |
45 | | - time.sleep(180 * time.second) |
| 66 | + |
| 67 | + delay() |
46 | 68 | } |
47 | 69 | } |
0 commit comments