Skip to content

Commit e2699c3

Browse files
author
Alvaro Muñoz
committed
feat(action): clone and install local packs
1 parent 959a974 commit e2699c3

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

.github/action/dist/index.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28596,7 +28596,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
2859628596
return result;
2859728597
};
2859828598
Object.defineProperty(exports, "__esModule", ({ value: true }));
28599-
exports.codeqlDatabaseAnalyze = exports.codeqlDatabaseCreate = exports.downloadPack = exports.runCommandJson = exports.runCommand = exports.newCodeQL = void 0;
28599+
exports.codeqlDatabaseAnalyze = exports.codeqlDatabaseCreate = exports.installPack = exports.downloadPack = exports.runCommandJson = exports.runCommand = exports.newCodeQL = void 0;
2860028600
const fs = __importStar(__nccwpck_require__(7147));
2860128601
const path = __importStar(__nccwpck_require__(1017));
2860228602
const core = __importStar(__nccwpck_require__(2186));
@@ -28613,10 +28613,15 @@ async function newCodeQL() {
2861328613
};
2861428614
}
2861528615
exports.newCodeQL = newCodeQL;
28616-
async function runCommand(config, args) {
28616+
async function runCommand(config, args, cwd) {
2861728617
var bin = path.join(config.path, "codeql");
2861828618
let output = "";
28619+
var _cwd = process.cwd();
28620+
if (cwd) {
28621+
_cwd = cwd;
28622+
}
2861928623
var options = {
28624+
cwd: cwd,
2862028625
listeners: {
2862128626
stdout: (data) => {
2862228627
output += data.toString();
@@ -28669,6 +28674,19 @@ async function downloadPack(codeql) {
2866928674
return false;
2867028675
}
2867128676
exports.downloadPack = downloadPack;
28677+
async function installPack(codeql, path) {
28678+
try {
28679+
await runCommand(codeql, ["pack", "install"], path);
28680+
await runCommand(codeql, ["pack", "install"], path);
28681+
return true;
28682+
}
28683+
catch (error) {
28684+
core.warning("Failed to install local packs ...");
28685+
}
28686+
core.info("Installed local packs ...");
28687+
return false;
28688+
}
28689+
exports.installPack = installPack;
2867228690
async function codeqlDatabaseCreate(codeql) {
2867328691
// get runner temp directory for database
2867428692
var temp = process.env["RUNNER_TEMP"];
@@ -28776,9 +28794,14 @@ async function runCommandJson(config, args) {
2877628794
return JSON.parse(await runCommand(config, args));
2877728795
}
2877828796
exports.runCommandJson = runCommandJson;
28779-
async function clonePackRepo(gh) {
28797+
async function clonePackRepo(gh, path) {
2878028798
try {
28781-
await runCommand(gh, ["repo", "clone", "GitHubSecurityLab/codeql-actions"]);
28799+
await runCommand(gh, [
28800+
"repo",
28801+
"clone",
28802+
"GitHubSecurityLab/codeql-actions",
28803+
path,
28804+
]);
2878228805
return true;
2878328806
}
2878428807
catch (error) {
@@ -28853,7 +28876,9 @@ async function run() {
2885328876
// download pack
2885428877
core.info(`Downloading CodeQL Actions pack '${codeql.pack}'`);
2885528878
//var pack_downloaded = await cql.downloadPack(codeql);
28856-
var pack_downloaded = await gh.clonePackRepo(ghc);
28879+
let pack_path = "/tmp/codeql-actions";
28880+
var pack_downloaded = await gh.clonePackRepo(ghc, pack_path);
28881+
await cql.installPack(codeql, pack_path);
2885728882
if (pack_downloaded === false) {
2885828883
var action_path = path.resolve(path.join(__dirname, "..", "..", ".."));
2885928884
core.info(`Pack path: '${action_path}'`);

.github/action/src/codeql.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ export async function newCodeQL(): Promise<CodeQLConfig> {
3434
export async function runCommand(
3535
config: CodeQLConfig,
3636
args: string[],
37+
cwd?: string,
3738
): Promise<any> {
3839
var bin = path.join(config.path, "codeql");
3940
let output = "";
41+
var _cwd: string = process.cwd();
42+
if (cwd) {
43+
_cwd = cwd;
44+
}
4045
var options = {
46+
cwd: cwd,
4147
listeners: {
4248
stdout: (data: Buffer) => {
4349
output += data.toString();
@@ -99,6 +105,21 @@ export async function downloadPack(codeql: CodeQLConfig): Promise<boolean> {
99105
return false;
100106
}
101107

108+
export async function installPack(
109+
codeql: CodeQLConfig,
110+
path: string,
111+
): Promise<boolean> {
112+
try {
113+
await runCommand(codeql, ["pack", "install"], path);
114+
await runCommand(codeql, ["pack", "install"], path);
115+
return true;
116+
} catch (error) {
117+
core.warning("Failed to install local packs ...");
118+
}
119+
core.info("Installed local packs ...");
120+
return false;
121+
}
122+
102123
export async function codeqlDatabaseCreate(
103124
codeql: CodeQLConfig,
104125
): Promise<string> {

.github/action/src/gh.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,17 @@ export async function runCommandJson(
4343
return JSON.parse(await runCommand(config, args));
4444
}
4545

46-
export async function clonePackRepo(gh: GHConfig): Promise<boolean> {
46+
export async function clonePackRepo(
47+
gh: GHConfig,
48+
path: string,
49+
): Promise<boolean> {
4750
try {
48-
await runCommand(gh, ["repo", "clone", "GitHubSecurityLab/codeql-actions"]);
51+
await runCommand(gh, [
52+
"repo",
53+
"clone",
54+
"GitHubSecurityLab/codeql-actions",
55+
path,
56+
]);
4957
return true;
5058
} catch (error) {
5159
core.warning("Failed to clone pack from GitHub...");

.github/action/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export async function run(): Promise<void> {
3939
// download pack
4040
core.info(`Downloading CodeQL Actions pack '${codeql.pack}'`);
4141
//var pack_downloaded = await cql.downloadPack(codeql);
42-
var pack_downloaded = await gh.clonePackRepo(ghc);
42+
43+
let pack_path = "/tmp/codeql-actions";
44+
var pack_downloaded = await gh.clonePackRepo(ghc, pack_path);
45+
await cql.installPack(codeql, pack_path);
4346

4447
if (pack_downloaded === false) {
4548
var action_path = path.resolve(path.join(__dirname, "..", "..", ".."));

0 commit comments

Comments
 (0)