File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,33 @@ 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+ std:: env:: var( "RUNNER_TEMP" )
145+ . unwrap_or_else( |_| "/tmp" . to_string( ) )
146+ . into( ) ,
147+ ] ;
148+
149+ for path in paths {
150+ if !path. exists ( ) {
151+ log:: debug!( "Creating CodeQL directory at `{}`" , path. display( ) ) ;
152+ if std:: fs:: create_dir ( & path) . is_ok ( ) {
153+ return Ok ( path) ;
154+ } else {
155+ log:: warn!( "Failed to create CodeQL directory at `{}`" , path. display( ) ) ;
156+ }
157+ } else {
158+ log:: debug!( "CodeQL directory already exists at `{}`" , path. display( ) ) ;
159+ return Ok ( path) ;
160+ }
161+ }
162+
163+ Err ( anyhow:: anyhow!( "Failed to create CodeQL directory" , ) )
164+ }
165+
139166 pub fn validate_languages ( & self , codeql_languages : & Vec < CodeQLLanguage > ) -> Result < ( ) > {
140167 for lang in self . languages ( ) {
141168 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