@@ -355,8 +355,8 @@ impl CircleCIGenerator {
355355
356356 circleci_job. docker = Some ( docker_images) ;
357357
358- // Add checkout step as the first step (standard CircleCI practice)
359- let checkout_step = serde_yaml :: Value :: String ( "checkout" . to_string ( ) ) ;
358+ // Add checkout step based on configuration hierarchy
359+ let checkout_step = self . resolve_checkout_step ( config , None , job ) ? ;
360360 circleci_job. steps . push ( CircleCIStep :: new ( checkout_step) ) ;
361361
362362 // Add skip logic if job has source_files defined (job-status cache)
@@ -1182,4 +1182,119 @@ echo "$(date): Job completed successfully" > "/tmp/cigen_skip_cache/job_${{JOB_H
11821182
11831183 Ok ( ( ) )
11841184 }
1185+
1186+ /// Resolve checkout configuration based on hierarchy (job > workflow > global > default)
1187+ fn resolve_checkout_step (
1188+ & self ,
1189+ config : & Config ,
1190+ workflow_config : Option < & crate :: models:: config:: WorkflowConfig > ,
1191+ job : & Job ,
1192+ ) -> Result < serde_yaml:: Value > {
1193+ use crate :: models:: config:: CheckoutConfig ;
1194+
1195+ // Resolve checkout config with hierarchy: job > workflow > global > default
1196+ let checkout_config = job
1197+ . checkout
1198+ . as_ref ( )
1199+ . or_else ( || workflow_config?. checkout . as_ref ( ) )
1200+ . or ( config. checkout . as_ref ( ) )
1201+ . cloned ( )
1202+ . unwrap_or ( CheckoutConfig {
1203+ shallow : true , // Default to shallow checkout
1204+ clone_options : None ,
1205+ fetch_options : None ,
1206+ tag_fetch_options : None ,
1207+ keyscan : None ,
1208+ path : None ,
1209+ } ) ;
1210+
1211+ if checkout_config. shallow {
1212+ // Use our vendored shallow checkout command
1213+ let mut shallow_checkout = serde_yaml:: Mapping :: new ( ) ;
1214+
1215+ // Add parameters if specified
1216+ if let Some ( clone_options) = & checkout_config. clone_options {
1217+ shallow_checkout. insert (
1218+ serde_yaml:: Value :: String ( "clone_options" . to_string ( ) ) ,
1219+ serde_yaml:: Value :: String ( clone_options. clone ( ) ) ,
1220+ ) ;
1221+ }
1222+ if let Some ( fetch_options) = & checkout_config. fetch_options {
1223+ shallow_checkout. insert (
1224+ serde_yaml:: Value :: String ( "fetch_options" . to_string ( ) ) ,
1225+ serde_yaml:: Value :: String ( fetch_options. clone ( ) ) ,
1226+ ) ;
1227+ }
1228+ if let Some ( tag_fetch_options) = & checkout_config. tag_fetch_options {
1229+ shallow_checkout. insert (
1230+ serde_yaml:: Value :: String ( "tag_fetch_options" . to_string ( ) ) ,
1231+ serde_yaml:: Value :: String ( tag_fetch_options. clone ( ) ) ,
1232+ ) ;
1233+ }
1234+ if let Some ( keyscan) = & checkout_config. keyscan {
1235+ if keyscan. get ( "github" ) . unwrap_or ( & false ) == & true {
1236+ shallow_checkout. insert (
1237+ serde_yaml:: Value :: String ( "keyscan_github" . to_string ( ) ) ,
1238+ serde_yaml:: Value :: Bool ( true ) ,
1239+ ) ;
1240+ }
1241+ if keyscan. get ( "gitlab" ) . unwrap_or ( & false ) == & true {
1242+ shallow_checkout. insert (
1243+ serde_yaml:: Value :: String ( "keyscan_gitlab" . to_string ( ) ) ,
1244+ serde_yaml:: Value :: Bool ( true ) ,
1245+ ) ;
1246+ }
1247+ if keyscan. get ( "bitbucket" ) . unwrap_or ( & false ) == & true {
1248+ shallow_checkout. insert (
1249+ serde_yaml:: Value :: String ( "keyscan_bitbucket" . to_string ( ) ) ,
1250+ serde_yaml:: Value :: Bool ( true ) ,
1251+ ) ;
1252+ }
1253+ }
1254+ if let Some ( path) = & checkout_config. path {
1255+ shallow_checkout. insert (
1256+ serde_yaml:: Value :: String ( "path" . to_string ( ) ) ,
1257+ serde_yaml:: Value :: String ( path. clone ( ) ) ,
1258+ ) ;
1259+ }
1260+
1261+ if shallow_checkout. is_empty ( ) {
1262+ // Simple command with no parameters
1263+ Ok ( serde_yaml:: Value :: String ( "shallow_checkout" . to_string ( ) ) )
1264+ } else {
1265+ // Command with parameters
1266+ let mut shallow_step = serde_yaml:: Mapping :: new ( ) ;
1267+ shallow_step. insert (
1268+ serde_yaml:: Value :: String ( "shallow_checkout" . to_string ( ) ) ,
1269+ serde_yaml:: Value :: Mapping ( shallow_checkout) ,
1270+ ) ;
1271+ Ok ( serde_yaml:: Value :: Mapping ( shallow_step) )
1272+ }
1273+ } else {
1274+ // Use standard CircleCI checkout
1275+ let mut checkout_step = serde_yaml:: Mapping :: new ( ) ;
1276+ let mut checkout_params = serde_yaml:: Mapping :: new ( ) ;
1277+
1278+ if let Some ( path) = & checkout_config. path {
1279+ checkout_params. insert (
1280+ serde_yaml:: Value :: String ( "path" . to_string ( ) ) ,
1281+ serde_yaml:: Value :: String ( path. clone ( ) ) ,
1282+ ) ;
1283+ }
1284+
1285+ if checkout_params. is_empty ( ) {
1286+ checkout_step. insert (
1287+ serde_yaml:: Value :: String ( "checkout" . to_string ( ) ) ,
1288+ serde_yaml:: Value :: Null ,
1289+ ) ;
1290+ } else {
1291+ checkout_step. insert (
1292+ serde_yaml:: Value :: String ( "checkout" . to_string ( ) ) ,
1293+ serde_yaml:: Value :: Mapping ( checkout_params) ,
1294+ ) ;
1295+ }
1296+
1297+ Ok ( serde_yaml:: Value :: Mapping ( checkout_step) )
1298+ }
1299+ }
11851300}
0 commit comments