@@ -42,6 +42,11 @@ pub async fn execute_build(job: &Job, sot_path: &Path, runner: &RunnerConfig) ->
4242 } ;
4343
4444 let build_dir = git:: get_build_dir ( sot_path, & job. id ) ;
45+ let job_dir = git:: get_job_dir ( sot_path, & job. id ) ;
46+ let mut log_file = job
47+ . log_file
48+ . as_ref ( )
49+ . and_then ( |p| create_log_file ( & job_dir, p, job. log_max_size ) ) ;
4550
4651 info ! (
4752 target: "rollcron::job" ,
@@ -50,11 +55,20 @@ pub async fn execute_build(job: &Job, sot_path: &Path, runner: &RunnerConfig) ->
5055 "Starting build"
5156 ) ;
5257
58+ if let Some ( ref mut file) = log_file {
59+ write_log_marker ( file, & runner. timezone , job. timezone . as_ref ( ) , "Build started" ) ;
60+ }
61+
5362 let result = run_build_command ( job, build_config, & build_dir, sot_path, runner) . await ;
5463
5564 match & result {
5665 BuildCommandResult :: Completed ( output) if output. status . success ( ) => {
5766 info ! ( target: "rollcron::job" , job_id = %job. id, "Build completed" ) ;
67+ if let Some ( ref mut file) = log_file {
68+ let _ = file. write_all ( & output. stdout ) ;
69+ let _ = file. write_all ( & output. stderr ) ;
70+ write_log_marker ( file, & runner. timezone , job. timezone . as_ref ( ) , "Build finished (success)" ) ;
71+ }
5872 BuildResult :: Success
5973 }
6074 BuildCommandResult :: Completed ( output) => {
@@ -66,6 +80,13 @@ pub async fn execute_build(job: &Job, sot_path: &Path, runner: &RunnerConfig) ->
6680 "Build failed"
6781 ) ;
6882
83+ if let Some ( ref mut file) = log_file {
84+ let _ = file. write_all ( & output. stdout ) ;
85+ let _ = file. write_all ( & output. stderr ) ;
86+ let marker = format ! ( "Build finished (failed, exit code {:?})" , output. status. code( ) ) ;
87+ write_log_marker ( file, & runner. timezone , job. timezone . as_ref ( ) , & marker) ;
88+ }
89+
6990 // Send webhook notifications
7091 if !job. webhook . is_empty ( ) {
7192 let failure = BuildFailure {
@@ -93,6 +114,12 @@ pub async fn execute_build(job: &Job, sot_path: &Path, runner: &RunnerConfig) ->
93114 BuildCommandResult :: ExecError ( e) => {
94115 error ! ( target: "rollcron::job" , job_id = %job. id, error = %e, "Build failed to execute" ) ;
95116
117+ if let Some ( ref mut file) = log_file {
118+ let _ = writeln ! ( file, "[rollcron] Error: {}" , e) ;
119+ let marker = format ! ( "Build finished (error: {})" , e) ;
120+ write_log_marker ( file, & runner. timezone , job. timezone . as_ref ( ) , & marker) ;
121+ }
122+
96123 if !job. webhook . is_empty ( ) {
97124 let failure = BuildFailure {
98125 job_id : & job. id ,
@@ -119,6 +146,12 @@ pub async fn execute_build(job: &Job, sot_path: &Path, runner: &RunnerConfig) ->
119146 BuildCommandResult :: Timeout => {
120147 error ! ( target: "rollcron::job" , job_id = %job. id, timeout = ?build_config. timeout, "Build timeout" ) ;
121148
149+ if let Some ( ref mut file) = log_file {
150+ let _ = writeln ! ( file, "[rollcron] Timeout after {:?}" , build_config. timeout) ;
151+ let marker = format ! ( "Build finished (timeout after {:?})" , build_config. timeout) ;
152+ write_log_marker ( file, & runner. timezone , job. timezone . as_ref ( ) , & marker) ;
153+ }
154+
122155 if !job. webhook . is_empty ( ) {
123156 let failure = BuildFailure {
124157 job_id : & job. id ,
@@ -286,11 +319,12 @@ fn merge_env_vars_for_build(
286319
287320pub async fn execute_job ( job : & Job , sot_path : & Path , runner : & RunnerConfig ) -> bool {
288321 let run_dir = git:: get_run_dir ( sot_path, & job. id ) ;
322+ let job_dir = git:: get_job_dir ( sot_path, & job. id ) ;
289323 let work_dir = resolve_work_dir ( & run_dir, & job. id , & job. working_dir ) ;
290324 let mut log_file = job
291325 . log_file
292326 . as_ref ( )
293- . and_then ( |p| create_log_file ( & run_dir , p, job. log_max_size ) ) ;
327+ . and_then ( |p| create_log_file ( & job_dir , p, job. log_max_size ) ) ;
294328
295329 let max_attempts = job. retry . as_ref ( ) . map ( |r| r. max + 1 ) . unwrap_or ( 1 ) ;
296330 let mut last_result: Option < CommandResult > = None ;
0 commit comments