Skip to content

Commit 6614ecb

Browse files
committed
feat: Implement CodeQL CLI download and installation via GitHub CLI
1 parent 3b497e6 commit 6614ecb

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

action.Dockerfile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
FROM 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-
83
ENTRYPOINT [ "codeql-extractor-action" ]

src/codeql.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ use ghastoolkit::prelude::*;
66
use log::{debug, info};
77

88
mod action;
9+
mod codeql;
910
mod extractors;
1011

1112
use action::{AUTHORS, Action, BANNER, VERSION};
1213

14+
use crate::codeql::gh_codeql_download;
15+
1316
#[tokio::main]
1417
async 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");

0 commit comments

Comments
 (0)