11//! CodeQL installation and management utilities
22//!
33//! This module provides helper functions for downloading and installing CodeQL,
4- //! particularly through alternative methods like GitHub CLI when the standard
4+ //! particularly through alternative methods like GitHub CLI when the standard
55//! installation process fails.
66
77use anyhow:: { Context , Result } ;
88use ghastoolkit:: CodeQL ;
99
1010/// Download and install the CodeQL CLI using the GitHub CLI
1111///
12- /// This function serves as a fallback installation method when the standard CodeQL
12+ /// This function serves as a fallback installation method when the standard CodeQL
1313/// installation process fails. It uses the GitHub CLI to:
1414/// 1. Install the gh-codeql extension
1515/// 2. Set the specified CodeQL version
@@ -22,26 +22,65 @@ use ghastoolkit::CodeQL;
2222/// * `Result<String>` - Path to the installed CodeQL binary or an error
2323pub async fn gh_codeql_download ( codeql_version : & str ) -> Result < String > {
2424 log:: info!( "Downloading CodeQL Extension for GitHub CLI..." ) ;
25- tokio:: process:: Command :: new ( "gh" )
25+ log:: debug!( "Running command: gh extensions install github/gh-codeql" ) ;
26+ let status = tokio:: process:: Command :: new ( "gh" )
2627 . args ( & [ "extensions" , "install" , "github/gh-codeql" ] )
2728 . status ( )
2829 . await
2930 . context ( "Failed to execute `gh extensions install github/gh-codeql` command" ) ?;
3031
32+ if !status. success ( ) {
33+ log:: error!(
34+ "Failed to install GitHub CLI CodeQL extension. Exit code: {:?}" ,
35+ status. code( )
36+ ) ;
37+ return Err ( anyhow:: anyhow!(
38+ "GitHub CLI CodeQL extension installation failed with exit code: {:?}" ,
39+ status. code( )
40+ ) ) ;
41+ }
42+ log:: debug!( "GitHub CLI CodeQL extension installed successfully" ) ;
43+
3144 log:: info!( "Setting CodeQL version to {codeql_version}..." ) ;
32- tokio:: process:: Command :: new ( "gh" )
45+ log:: debug!( "Running command: gh codeql set-version {codeql_version}" ) ;
46+ let status = tokio:: process:: Command :: new ( "gh" )
3347 . args ( & [ "codeql" , "set-version" , codeql_version] )
3448 . status ( )
3549 . await
3650 . context ( "Failed to execute `gh codeql set-version` command" ) ?;
3751
38- log:: info!( "Install CodeQL stub..." ) ;
39- tokio:: process:: Command :: new ( "gh" )
52+ if !status. success ( ) {
53+ log:: error!(
54+ "Failed to set CodeQL version. Exit code: {:?}" ,
55+ status. code( )
56+ ) ;
57+ return Err ( anyhow:: anyhow!(
58+ "Setting CodeQL version failed with exit code: {:?}" ,
59+ status. code( )
60+ ) ) ;
61+ }
62+ log:: debug!( "CodeQL version set to {codeql_version} successfully" ) ;
63+
64+ log:: info!( "Installing CodeQL stub..." ) ;
65+ log:: debug!( "Running command: gh codeql install-stub" ) ;
66+ let status = tokio:: process:: Command :: new ( "gh" )
4067 . args ( & [ "codeql" , "install-stub" ] )
4168 . status ( )
4269 . await
4370 . context ( "Failed to execute `gh codeql install-stub` command" ) ?;
4471
72+ if !status. success ( ) {
73+ log:: error!(
74+ "Failed to install CodeQL stub. Exit code: {:?}" ,
75+ status. code( )
76+ ) ;
77+ return Err ( anyhow:: anyhow!(
78+ "CodeQL stub installation failed with exit code: {:?}" ,
79+ status. code( )
80+ ) ) ;
81+ }
82+ log:: debug!( "CodeQL stub installed successfully" ) ;
83+
4584 let codeql = CodeQL :: new ( ) . await ;
4685 if codeql. is_installed ( ) . await {
4786 log:: info!( "CodeQL CLI installed successfully via GitHub CLI" ) ;
0 commit comments