File tree Expand file tree Collapse file tree 3 files changed +47
-9
lines changed
Expand file tree Collapse file tree 3 files changed +47
-9
lines changed Original file line number Diff line number Diff line change 11FROM ghcr.io/advanced-security/codeql-extractor-action:v0.1.0
22
3- ARG INPUT_TOKEN
4-
5- RUN export GH_TOKEN=$INPUT_TOKEN && \
6- gh extensions install github/gh-codeql
7-
83ENTRYPOINT [ "codeql-extractor-action" ]
Original file line number Diff line number Diff line change 1+ use anyhow:: { Result , Context } ;
2+ use ghastoolkit:: CodeQL ;
3+
4+ /// Download the CodeQL CLI using the GitHub CLI
5+ pub async fn gh_codeql_download ( codeql_version : & str ) -> Result < String > {
6+
7+ log:: info!( "Downloading CodeQL Extension for GitHub CLI..." ) ;
8+ tokio:: process:: Command :: new ( "gh" )
9+ . args ( & [ "extensions" , "install" , "github/gh-codeql" ] )
10+ . status ( )
11+ . await
12+ . context ( "Failed to execute `gh extensions install github/gh-codeql` command" ) ?;
13+
14+ log:: info!( "Setting CodeQL version to {codeql_version}..." ) ;
15+ tokio:: process:: Command :: new ( "gh" )
16+ . args ( & [ "codeql" , "set-version" , codeql_version] )
17+ . status ( )
18+ . await
19+ . context ( "Failed to execute `gh codeql set-version` command" ) ?;
20+
21+ log:: info!( "Install CodeQL stub..." ) ;
22+ tokio:: process:: Command :: new ( "gh" )
23+ . args ( & [ "codeql" , "install-stub" ] )
24+ . status ( )
25+ . await
26+ . context ( "Failed to execute `gh codeql install-stub` command" ) ?;
27+
28+ let codeql = CodeQL :: new ( ) . await ;
29+ if codeql. is_installed ( ) . await {
30+ log:: info!( "CodeQL CLI installed successfully via GitHub CLI" ) ;
31+ } else {
32+ log:: error!( "CodeQL CLI installation via GitHub CLI failed" ) ;
33+ return Err ( anyhow:: anyhow!( "CodeQL CLI installation failed" ) ) ;
34+ }
35+
36+ Ok ( "/usr/local/bin/codeql" . to_string ( ) )
37+ }
Original file line number Diff line number Diff line change @@ -6,10 +6,13 @@ use ghastoolkit::prelude::*;
66use log:: { debug, info} ;
77
88mod action;
9+ mod codeql;
910mod extractors;
1011
1112use action:: { AUTHORS , Action , BANNER , VERSION } ;
1213
14+ use crate :: codeql:: gh_codeql_download;
15+
1316#[ tokio:: main]
1417async fn main ( ) -> Result < ( ) > {
1518 let mut action = Action :: init ( ) ?;
@@ -46,11 +49,14 @@ async fn main() -> Result<()> {
4649 log:: warn!( "Failed to install CodeQL: {error:?}" ) ;
4750 log:: info!( "Attempting to install CodeQL using GitHub CLI..." ) ;
4851
49- tokio:: process:: Command :: new ( "gh" )
50- . args ( & [ "codeql" , "set-version" , codeql_version. into ( ) ] )
51- . status ( )
52+ let location = gh_codeql_download ( codeql_version) . await
53+ . context ( "Failed to download CodeQL using GitHub CLI" ) ?;
54+
55+ codeql = CodeQL :: init ( )
56+ . path ( location)
57+ . build ( )
5258 . await
53- . context ( "Failed to execute `gh codeql set-version` command " ) ?;
59+ . context ( "Failed to create CodeQL instance after GitHub CLI installation " ) ?;
5460 }
5561
5662 log:: info!( "CodeQL installed" ) ;
You can’t perform that action at this time.
0 commit comments