@@ -177,6 +177,47 @@ impl Action {
177177 languages
178178 }
179179
180+ /// Gets the possible directories for CodeQL operations.
181+ ///
182+ /// This function identifies potential locations for CodeQL operation directories in the following order:
183+ /// 1. The `.codeql` directory in the GitHub workspace (if running in GitHub Actions)
184+ /// 2. The `.codeql` directory in the current working directory
185+ /// 3. The `.codeql` directory in the GitHub Actions runner's temp directory (if available)
186+ /// 4. The `.codeql` directory in the system's temporary directory
187+ ///
188+ /// Each path is checked for existence and created if necessary by the caller.
189+ ///
190+ /// # Returns
191+ /// - `Result<Vec<PathBuf>>`: A vector of possible directory paths for CodeQL operations
192+ ///
193+ /// # Errors
194+ /// - If `working_directory()` fails
195+ /// - If path canonicalization fails
196+ fn get_codeql_directories ( & self ) -> Result < Vec < PathBuf > > {
197+ let mut paths = Vec :: new ( ) ;
198+
199+ // GITHUB_WORKSPACE
200+ if let Ok ( github_workspace) = std:: env:: var ( "GITHUB_WORKSPACE" ) {
201+ paths. push ( PathBuf :: from ( github_workspace) . join ( ".codeql" ) ) ;
202+ }
203+
204+ // Local CodeQL directory in the working directory
205+ if let Ok ( local_codeql) = self . working_directory ( ) ?. join ( ".codeql" ) . canonicalize ( ) {
206+ paths. push ( local_codeql) ;
207+ }
208+
209+ // Runner temp directory
210+ if let Ok ( runner_temp) = std:: env:: var ( "RUNNER_TEMP" ) {
211+ paths. push ( PathBuf :: from ( runner_temp) . join ( ".codeql" ) . canonicalize ( ) ?) ;
212+ }
213+ // temp_dir
214+ if let Ok ( temp_dir) = std:: env:: temp_dir ( ) . canonicalize ( ) {
215+ paths. push ( temp_dir. join ( ".codeql" ) ) ;
216+ }
217+
218+ Ok ( paths)
219+ }
220+
180221 /// Returns the directory to use for CodeQL operations.
181222 ///
182223 /// Gets the CodeQL directory to use for the action. It will first check if a local
@@ -187,17 +228,8 @@ impl Action {
187228 /// It uses the parent of the working directory to to stop issues where the
188229 /// database/sarif files gets indexed by CodeQL.
189230 pub fn get_codeql_dir ( & self ) -> Result < PathBuf > {
190- let paths = vec ! [
191- // Local CodeQL directory in the working directory parent
192- self . working_directory( ) ?
193- . join( ".." )
194- . join( ".codeql" )
195- . canonicalize( ) ?,
196- // Runner temp directory
197- PathBuf :: from( std:: env:: var( "RUNNER_TEMP" ) . unwrap_or_else( |_| "/tmp" . to_string( ) ) )
198- . join( ".codeql" )
199- . canonicalize( ) ?,
200- ] ;
231+ let paths = self . get_codeql_directories ( ) ?;
232+ log:: debug!( "Possible CodeQL directories: {:?}" , paths) ;
201233
202234 for path in paths {
203235 if !path. exists ( ) {
0 commit comments