Skip to content

Commit 7c0f5ee

Browse files
committed
feat(action): Add codeql_version input and update CodeQL installation logic
1 parent 16c86c2 commit 7c0f5ee

6 files changed

Lines changed: 52 additions & 36 deletions

File tree

Cargo.lock

Lines changed: 20 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ anyhow = "1"
2020
thiserror = "2"
2121
dotenvy = "0.15"
2222
# Actions
23-
ghactions = { version = "^0.15", features = ["dotenvy", "log", "generate", "octocrab", "toolcache"] }
24-
ghactions-core = { version = "^0.15" }
25-
ghastoolkit = "^0.7.2"
23+
ghactions = { version = "^0.16", features = ["dotenvy", "log", "generate", "octocrab", "toolcache"] }
24+
ghastoolkit = { version = "^0.8", features = ["toolcache"] }
2625

2726
# GitHub API
2827
octocrab = "^0.44"
2928
openssl = { version = "0.10", features = ["vendored"] }
30-

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@ RUN apk update && \
2121
rm -rf /var/cache/apk/*
2222

2323
COPY --from=builder /app/target/codeql-extractor-action /usr/local/bin/codeql-extractor-action
24-
COPY --from=builder /app/entrypoint.sh /entrypoint.sh
25-
26-
ENTRYPOINT [ "sh", "/entrypoint.sh" ]
2724

25+
ENTRYPOINT [ "codeql-extractor-action" ]

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ inputs:
1515
language:
1616
description: Language(s) to use
1717
required: true
18+
codeql_version:
19+
description: CodeQL Version
20+
default: latest
1821
attestation:
1922
description: Attestation
2023
default: 'false'

src/action.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub struct Action {
3636
#[input(description = "Language(s) to use", split = ",", required = true)]
3737
language: Vec<String>,
3838

39+
/// CodeQL Version
40+
#[input(description = "CodeQL Version", default = "latest")]
41+
codeql_version: String,
42+
3943
/// Attestation
4044
#[input(description = "Attestation", default = "false")]
4145
attestation: bool,
@@ -96,6 +100,10 @@ impl Action {
96100
Ok(())
97101
}
98102

103+
pub fn codeql_version(&self) -> &str {
104+
&self.codeql_version
105+
}
106+
99107
pub fn attestation(&self) -> bool {
100108
self.attestation
101109
}

src/main.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use anyhow::{Context, Result};
4-
use ghactions::{ActionTrait, ToolCache, group, groupend};
4+
use ghactions::{ActionTrait, group, groupend};
55
use ghastoolkit::codeql::database::queries::CodeQLQueries;
66
use ghastoolkit::{CodeQL, CodeQLDatabase};
77
use log::{debug, info};
@@ -18,10 +18,23 @@ async fn main() -> Result<()> {
1818

1919
group!("Setting up Extractor");
2020

21-
let client = octocrab::instance();
21+
let client = action.octocrab()?;
2222

23-
let toolcache = ToolCache::new();
24-
debug!("ToolCache :: {:?}", toolcache);
23+
let mut codeql = CodeQL::init()
24+
.build()
25+
.await
26+
.context("Failed to create CodeQL instance")?;
27+
28+
if !codeql.is_installed().await {
29+
let codeql_version = action.codeql_version();
30+
log::info!("CodeQL not installed, installing {}...", codeql_version);
31+
codeql.install(&client, codeql_version).await?;
32+
log::info!("CodeQL installed");
33+
} else {
34+
log::info!("CodeQL already installed");
35+
}
36+
37+
log::info!("CodeQL :: {:?}", codeql);
2538

2639
// Extractor
2740
let extractor_repo = action.extractor_repository()?;
@@ -44,12 +57,7 @@ async fn main() -> Result<()> {
4457
.context("Failed to fetch extractor")?;
4558
log::info!("Extractor :: {:?}", extractor);
4659

47-
let codeql = CodeQL::init()
48-
.search_path(extractor)
49-
.build()
50-
.await
51-
.context("Failed to create CodeQL instance")?;
52-
log::info!("CodeQL :: {:?}", codeql);
60+
codeql.append_search_path(extractor.display().to_string());
5361

5462
let languages = codeql.get_languages().await?;
5563
log::info!("Languages :: {:#?}", languages);

0 commit comments

Comments
 (0)