File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,32 @@ impl Action {
136136 . collect ( )
137137 }
138138
139+ pub fn get_codeql_dir ( & self ) -> Result < PathBuf > {
140+ let paths = vec ! [
141+ // Local CodeQL directory in the working directory
142+ self . working_directory( ) ?. join( ".codeql" ) ,
143+ // Runner temp directory
144+ PathBuf :: from( std:: env:: var( "RUNNER_TEMP" ) . unwrap_or_else( |_| "/tmp" . to_string( ) ) )
145+ . join( ".codeql" ) ,
146+ ] ;
147+
148+ for path in paths {
149+ if !path. exists ( ) {
150+ log:: debug!( "Creating CodeQL directory at `{}`" , path. display( ) ) ;
151+ if std:: fs:: create_dir_all ( & path) . is_ok ( ) {
152+ return Ok ( path) ;
153+ } else {
154+ log:: warn!( "Failed to create CodeQL directory at `{}`" , path. display( ) ) ;
155+ }
156+ } else {
157+ log:: debug!( "CodeQL directory already exists at `{}`" , path. display( ) ) ;
158+ return Ok ( path) ;
159+ }
160+ }
161+
162+ Err ( anyhow:: anyhow!( "Failed to create CodeQL directory" , ) )
163+ }
164+
139165 pub fn validate_languages ( & self , codeql_languages : & Vec < CodeQLLanguage > ) -> Result < ( ) > {
140166 for lang in self . languages ( ) {
141167 let mut supported = false ;
Original file line number Diff line number Diff line change @@ -23,8 +23,10 @@ async fn main() -> Result<()> {
2323 let cwd = action
2424 . working_directory ( )
2525 . context ( "Failed to get working directory" ) ?;
26- let databases = cwd. join ( ".codeql" ) ;
27- let sarif_output = databases. join ( "results" ) ;
26+ let codeql_dir = action. get_codeql_dir ( ) ?;
27+
28+ let databases = codeql_dir. join ( "databases" ) ;
29+ let sarif_output = codeql_dir. join ( "results" ) ;
2830
2931 group ! ( "Setting up CodeQL" ) ;
3032
You can’t perform that action at this time.
0 commit comments