@@ -3079,78 +3079,100 @@ fn deploy(
30793079 program_str : Option < String > ,
30803080 program_keypair : Option < String > ,
30813081) -> Result < ( ) > {
3082+ // Execute the code within the workspace
30823083 with_workspace ( cfg_override, |cfg| {
30833084 let url = cluster_url ( cfg, & cfg. test_validator ) ;
30843085 let keypair = cfg. provider . wallet . to_string ( ) ;
30853086
30863087 // Deploy the programs.
3087- println ! ( "Deploying workspace: {url}" ) ;
3088- println ! ( "Upgrade authority: {keypair}" ) ;
3088+ println ! ( "Deploying cluster: {}" , url) ;
3089+ println ! ( "Upgrade authority: {}" , keypair) ;
3090+
3091+ let mut program_found = true ; // Flag to track if the specified program is found
30893092
30903093 for mut program in cfg. read_all_programs ( ) ? {
3094+ // If a program string is provided
30913095 if let Some ( single_prog_str) = & program_str {
30923096 let program_name = program. path . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
3097+
3098+ // Check if the provided program string matches the program name
30933099 if single_prog_str. as_str ( ) != program_name {
3094- continue ;
3100+ program_found = false ;
3101+ } else {
3102+ program_found = true ;
30953103 }
30963104 }
3097- let binary_path = program. binary_path ( ) . display ( ) . to_string ( ) ;
30983105
3099- println ! (
3100- "Deploying program {:?}..." ,
3101- program. path. file_name( ) . unwrap( ) . to_str( ) . unwrap( )
3102- ) ;
3106+ if program_found {
3107+ let binary_path = program. binary_path ( ) . display ( ) . to_string ( ) ;
31033108
3104- println ! ( "Program path: {binary_path}..." ) ;
3105-
3106- let ( program_keypair_filepath, program_id) = match & program_keypair {
3107- Some ( path) => (
3108- path. clone ( ) ,
3109- solana_sdk:: signature:: read_keypair_file ( path)
3110- . map_err ( |_| anyhow ! ( "Unable to read keypair file" ) ) ?
3111- . pubkey ( ) ,
3112- ) ,
3113- None => (
3114- program. keypair_file ( ) ?. path ( ) . display ( ) . to_string ( ) ,
3115- program. pubkey ( ) ?,
3116- ) ,
3117- } ;
3109+ println ! (
3110+ "Deploying program {:?}..." ,
3111+ program. path. file_name( ) . unwrap( ) . to_str( ) . unwrap( )
3112+ ) ;
3113+ println ! ( "Program path: {}..." , binary_path) ;
3114+
3115+ let ( program_keypair_filepath, program_id) = match & program_keypair {
3116+ Some ( path) => (
3117+ path. clone ( ) ,
3118+ solana_sdk:: signature:: read_keypair_file ( path)
3119+ . map_err ( |_| anyhow ! ( "Unable to read keypair file" ) ) ?
3120+ . pubkey ( ) ,
3121+ ) ,
3122+ None => (
3123+ program. keypair_file ( ) ?. path ( ) . display ( ) . to_string ( ) ,
3124+ program. pubkey ( ) ?,
3125+ ) ,
3126+ } ;
31183127
3119- // Send deploy transactions.
3120- let exit = std:: process:: Command :: new ( "solana" )
3121- . arg ( "program" )
3122- . arg ( "deploy" )
3123- . arg ( "--url" )
3124- . arg ( & url)
3125- . arg ( "--keypair" )
3126- . arg ( & keypair)
3127- . arg ( "--program-id" )
3128- . arg ( strip_workspace_prefix ( program_keypair_filepath) )
3129- . arg ( strip_workspace_prefix ( binary_path) )
3130- . stdout ( Stdio :: inherit ( ) )
3131- . stderr ( Stdio :: inherit ( ) )
3132- . output ( )
3133- . expect ( "Must deploy" ) ;
3134- if !exit. status . success ( ) {
3135- println ! ( "There was a problem deploying: {exit:?}." ) ;
3136- std:: process:: exit ( exit. status . code ( ) . unwrap_or ( 1 ) ) ;
3137- }
3128+ // Send deploy transactions using the Solana CLI
3129+ let exit = std:: process:: Command :: new ( "solana" )
3130+ . arg ( "program" )
3131+ . arg ( "deploy" )
3132+ . arg ( "--url" )
3133+ . arg ( & url)
3134+ . arg ( "--keypair" )
3135+ . arg ( & keypair)
3136+ . arg ( "--program-id" )
3137+ . arg ( strip_workspace_prefix ( program_keypair_filepath) )
3138+ . arg ( strip_workspace_prefix ( binary_path) )
3139+ . stdout ( Stdio :: inherit ( ) )
3140+ . stderr ( Stdio :: inherit ( ) )
3141+ . output ( )
3142+ . expect ( "Must deploy" ) ;
3143+
3144+ // Check if deployment was successful
3145+ if !exit. status . success ( ) {
3146+ println ! ( "There was a problem deploying: {exit:?}." ) ;
3147+ std:: process:: exit ( exit. status . code ( ) . unwrap_or ( 1 ) ) ;
3148+ }
31383149
3139- if let Some ( mut idl) = program. idl . as_mut ( ) {
3140- // Add program address to the IDL.
3141- idl. metadata = Some ( serde_json:: to_value ( IdlTestMetadata {
3142- address : program_id. to_string ( ) ,
3143- } ) ?) ;
3150+ if let Some ( mut idl) = program. idl . as_mut ( ) {
3151+ // Add program address to the IDL.
3152+ idl. metadata = Some ( serde_json:: to_value ( IdlTestMetadata {
3153+ address : program_id. to_string ( ) ,
3154+ } ) ?) ;
3155+
3156+ // Persist it.
3157+ let idl_out = PathBuf :: from ( "target/idl" )
3158+ . join ( & idl. name )
3159+ . with_extension ( "json" ) ;
3160+ write_idl ( idl, OutFile :: File ( idl_out) ) ?;
3161+ }
3162+ }
31443163
3145- // Persist it.
3146- let idl_out = PathBuf :: from ( "target/idl" )
3147- . join ( & idl. name )
3148- . with_extension ( "json" ) ;
3149- write_idl ( idl, OutFile :: File ( idl_out) ) ?;
3164+ // Break the loop if a specific programme is discovered and program_str is not None.
3165+ if program_str. is_some ( ) && program_found {
3166+ break ;
31503167 }
31513168 }
31523169
3153- println ! ( "Deploy success" ) ;
3170+ // If a program string is provided but not found
3171+ if program_str. is_some ( ) && !program_found {
3172+ println ! ( "Specified program not found" ) ;
3173+ } else {
3174+ println ! ( "Deploy success" ) ;
3175+ }
31543176
31553177 Ok ( ( ) )
31563178 } )
0 commit comments