File tree Expand file tree Collapse file tree 5 files changed +79
-5
lines changed
Expand file tree Collapse file tree 5 files changed +79
-5
lines changed Original file line number Diff line number Diff line change 9595 # latest / main
9696 type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
9797
98+ - name : Login to GitHub Container Registry
99+ uses : docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
100+ with :
101+ registry : ${{ env.REGISTRY }}
102+ username : ${{ github.actor }}
103+ password : ${{ secrets.GITHUB_TOKEN }}
104+
98105 - name : Build Container ${{ github.repository }}
99106 uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
100107 id : build
@@ -106,6 +113,9 @@ jobs:
106113 labels : ${{ steps.meta.outputs.labels }}
107114 # SBOM Settings
108115 sbom : true
116+ # Pass GitHub token as a build secret
117+ secrets : |
118+ "github_token=${{ secrets.GITHUB_TOKEN }}"
109119
110120 # Upload Software Bill of Materials (SBOM) to GitHub
111121 - name : Upload SBOM
Original file line number Diff line number Diff line change 1- FROM ghcr.io/advanced-security/codeql-extractor-action:v0.1.1
1+ FROM ghcr.io/advanced-security/codeql-extractor-action:v0.1.0
22
33ENTRYPOINT [ "codeql-extractor-action" ]
Original file line number Diff line number Diff line change 1+ use anyhow:: { Context , Result } ;
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+ log:: info!( "Downloading CodeQL Extension for GitHub CLI..." ) ;
7+ tokio:: process:: Command :: new ( "gh" )
8+ . args ( & [ "extensions" , "install" , "github/gh-codeql" ] )
9+ . status ( )
10+ . await
11+ . context ( "Failed to execute `gh extensions install github/gh-codeql` command" ) ?;
12+
13+ log:: info!( "Setting CodeQL version to {codeql_version}..." ) ;
14+ tokio:: process:: Command :: new ( "gh" )
15+ . args ( & [ "codeql" , "set-version" , codeql_version] )
16+ . status ( )
17+ . await
18+ . context ( "Failed to execute `gh codeql set-version` command" ) ?;
19+
20+ log:: info!( "Install CodeQL stub..." ) ;
21+ tokio:: process:: Command :: new ( "gh" )
22+ . args ( & [ "codeql" , "install-stub" ] )
23+ . status ( )
24+ . await
25+ . context ( "Failed to execute `gh codeql install-stub` command" ) ?;
26+
27+ let codeql = CodeQL :: new ( ) . await ;
28+ if codeql. is_installed ( ) . await {
29+ log:: info!( "CodeQL CLI installed successfully via GitHub CLI" ) ;
30+ } else {
31+ log:: error!( "CodeQL CLI installation via GitHub CLI failed" ) ;
32+ return Err ( anyhow:: anyhow!( "CodeQL CLI installation failed" ) ) ;
33+ }
34+
35+ Ok ( "/usr/local/bin/codeql" . to_string ( ) )
36+ }
Original file line number Diff line number Diff line change @@ -86,6 +86,19 @@ pub async fn fetch_extractor(
8686 }
8787 } ;
8888
89+ // Get and log the size of the extractor archive
90+ if let Ok ( metadata) = std:: fs:: metadata ( & extractor_archive) {
91+ let size_bytes = metadata. len ( ) ;
92+ let size_mb = size_bytes as f64 / 1_048_576.0 ; // Convert to MB (1 MB = 1,048,576 bytes)
93+ log:: info!(
94+ "Extractor archive size: {:.2} MB ({} bytes)" ,
95+ size_mb,
96+ size_bytes
97+ ) ;
98+ } else {
99+ log:: warn!( "Unable to get size information for the extractor archive" ) ;
100+ }
101+
89102 if attest {
90103 log:: info!( "Attesting asset {extractor_tarball:?}" ) ;
91104
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 ( ) ?;
@@ -41,10 +44,22 @@ async fn main() -> Result<()> {
4144 if !codeql. is_installed ( ) . await {
4245 let codeql_version = action. codeql_version ( ) ;
4346 log:: info!( "CodeQL not installed, installing `{codeql_version}`..." ) ;
44- codeql
45- . install ( & octocrab, codeql_version)
46- . await
47- . context ( "Failed to install CodeQL" ) ?;
47+
48+ if let Err ( error) = codeql. install ( & octocrab, codeql_version) . await {
49+ log:: warn!( "Failed to install CodeQL: {error:?}" ) ;
50+ log:: info!( "Attempting to install CodeQL using GitHub CLI..." ) ;
51+
52+ let location = gh_codeql_download ( codeql_version)
53+ . await
54+ . context ( "Failed to download CodeQL using GitHub CLI" ) ?;
55+
56+ codeql = CodeQL :: init ( )
57+ . path ( location)
58+ . build ( )
59+ . await
60+ . context ( "Failed to create CodeQL instance after GitHub CLI installation" ) ?;
61+ }
62+
4863 log:: info!( "CodeQL installed" ) ;
4964 } else {
5065 log:: info!( "CodeQL already installed" ) ;
You can’t perform that action at this time.
0 commit comments