Skip to content

Commit 959a974

Browse files
author
Alvaro Muñoz
committed
feat(action): clone pack (not use the registry)
1 parent 5d1264d commit 959a974

File tree

4 files changed

+148
-3
lines changed

4 files changed

+148
-3
lines changed

.github/action/dist/index.js

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28716,6 +28716,79 @@ async function codeqlDatabaseAnalyze(codeql, database_path) {
2871628716
exports.codeqlDatabaseAnalyze = codeqlDatabaseAnalyze;
2871728717

2871828718

28719+
/***/ }),
28720+
28721+
/***/ 1772:
28722+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
28723+
28724+
"use strict";
28725+
28726+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
28727+
if (k2 === undefined) k2 = k;
28728+
var desc = Object.getOwnPropertyDescriptor(m, k);
28729+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28730+
desc = { enumerable: true, get: function() { return m[k]; } };
28731+
}
28732+
Object.defineProperty(o, k2, desc);
28733+
}) : (function(o, m, k, k2) {
28734+
if (k2 === undefined) k2 = k;
28735+
o[k2] = m[k];
28736+
}));
28737+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28738+
Object.defineProperty(o, "default", { enumerable: true, value: v });
28739+
}) : function(o, v) {
28740+
o["default"] = v;
28741+
});
28742+
var __importStar = (this && this.__importStar) || function (mod) {
28743+
if (mod && mod.__esModule) return mod;
28744+
var result = {};
28745+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28746+
__setModuleDefault(result, mod);
28747+
return result;
28748+
};
28749+
Object.defineProperty(exports, "__esModule", ({ value: true }));
28750+
exports.clonePackRepo = exports.runCommandJson = exports.runCommand = exports.newGHConfig = void 0;
28751+
const path = __importStar(__nccwpck_require__(1017));
28752+
const core = __importStar(__nccwpck_require__(2186));
28753+
const toolrunner = __importStar(__nccwpck_require__(8159));
28754+
async function newGHConfig() {
28755+
return {
28756+
path: "",
28757+
};
28758+
}
28759+
exports.newGHConfig = newGHConfig;
28760+
async function runCommand(config, args) {
28761+
var bin = path.join(config.path, "gh");
28762+
let output = "";
28763+
var options = {
28764+
listeners: {
28765+
stdout: (data) => {
28766+
output += data.toString();
28767+
},
28768+
},
28769+
};
28770+
await new toolrunner.ToolRunner(bin, args, options).exec();
28771+
core.debug(`Finished running command :: ${bin} ${args.join(" ")}`);
28772+
return output.trim();
28773+
}
28774+
exports.runCommand = runCommand;
28775+
async function runCommandJson(config, args) {
28776+
return JSON.parse(await runCommand(config, args));
28777+
}
28778+
exports.runCommandJson = runCommandJson;
28779+
async function clonePackRepo(gh) {
28780+
try {
28781+
await runCommand(gh, ["repo", "clone", "GitHubSecurityLab/codeql-actions"]);
28782+
return true;
28783+
}
28784+
catch (error) {
28785+
core.warning("Failed to clone pack from GitHub...");
28786+
}
28787+
return false;
28788+
}
28789+
exports.clonePackRepo = clonePackRepo;
28790+
28791+
2871928792
/***/ }),
2872028793

2872128794
/***/ 6144:
@@ -28751,12 +28824,17 @@ exports.run = void 0;
2875128824
const path = __importStar(__nccwpck_require__(1017));
2875228825
const core = __importStar(__nccwpck_require__(2186));
2875328826
const cql = __importStar(__nccwpck_require__(950));
28827+
const gh = __importStar(__nccwpck_require__(1772));
2875428828
/**
2875528829
* The main function for the action.
2875628830
* @returns {Promise<void>} Resolves when the action is complete.
2875728831
*/
2875828832
async function run() {
2875928833
try {
28834+
// set up gh
28835+
var ghc = await gh.newGHConfig();
28836+
core.debug(`GH CLI found at '${ghc.path}'`);
28837+
await gh.runCommand(ghc, ["version"]);
2876028838
// set up codeql
2876128839
var codeql = await cql.newCodeQL();
2876228840
core.debug(`CodeQL CLI found at '${codeql.path}'`);
@@ -28774,10 +28852,13 @@ async function run() {
2877428852
}
2877528853
// download pack
2877628854
core.info(`Downloading CodeQL Actions pack '${codeql.pack}'`);
28777-
var pack_downloaded = await cql.downloadPack(codeql);
28855+
//var pack_downloaded = await cql.downloadPack(codeql);
28856+
var pack_downloaded = await gh.clonePackRepo(ghc);
2877828857
if (pack_downloaded === false) {
2877928858
var action_path = path.resolve(path.join(__dirname, "..", "..", ".."));
28859+
core.info(`Pack path: '${action_path}'`);
2878028860
codeql.pack = path.join(action_path, "ql", "src");
28861+
core.info(`Codeql pack path: '${codeql.path}'`);
2878128862
core.info(`Pack defaulting back to local pack: '${codeql.pack}'`);
2878228863
}
2878328864
else {

.github/action/src/codeql.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as path from "path";
33

44
import * as core from "@actions/core";
55
import * as toolcache from "@actions/tool-cache";
6-
import * as github from "@actions/github";
76
import * as toolrunner from "@actions/exec/lib/toolrunner";
87

98
export interface CodeQLConfig {

.github/action/src/gh.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
4+
import * as core from "@actions/core";
5+
import * as toolcache from "@actions/tool-cache";
6+
import * as toolrunner from "@actions/exec/lib/toolrunner";
7+
8+
export interface GHConfig {
9+
// The path to the codeql bundle.
10+
path: string;
11+
}
12+
13+
export async function newGHConfig(): Promise<GHConfig> {
14+
return {
15+
path: "",
16+
};
17+
}
18+
19+
export async function runCommand(
20+
config: GHConfig,
21+
args: string[],
22+
): Promise<any> {
23+
var bin = path.join(config.path, "gh");
24+
let output = "";
25+
var options = {
26+
listeners: {
27+
stdout: (data: Buffer) => {
28+
output += data.toString();
29+
},
30+
},
31+
};
32+
33+
await new toolrunner.ToolRunner(bin, args, options).exec();
34+
core.debug(`Finished running command :: ${bin} ${args.join(" ")}`);
35+
36+
return output.trim();
37+
}
38+
39+
export async function runCommandJson(
40+
config: GHConfig,
41+
args: string[],
42+
): Promise<object> {
43+
return JSON.parse(await runCommand(config, args));
44+
}
45+
46+
export async function clonePackRepo(gh: GHConfig): Promise<boolean> {
47+
try {
48+
await runCommand(gh, ["repo", "clone", "GitHubSecurityLab/codeql-actions"]);
49+
return true;
50+
} catch (error) {
51+
core.warning("Failed to clone pack from GitHub...");
52+
}
53+
return false;
54+
}

.github/action/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import * as path from "path";
22
import * as core from "@actions/core";
33
import * as cql from "./codeql";
4+
import * as gh from "./gh";
45

56
/**
67
* The main function for the action.
78
* @returns {Promise<void>} Resolves when the action is complete.
89
*/
910
export async function run(): Promise<void> {
1011
try {
12+
// set up gh
13+
var ghc = await gh.newGHConfig();
14+
15+
core.debug(`GH CLI found at '${ghc.path}'`);
16+
17+
await gh.runCommand(ghc, ["version"]);
18+
1119
// set up codeql
1220
var codeql = await cql.newCodeQL();
1321

@@ -30,11 +38,14 @@ export async function run(): Promise<void> {
3038

3139
// download pack
3240
core.info(`Downloading CodeQL Actions pack '${codeql.pack}'`);
33-
var pack_downloaded = await cql.downloadPack(codeql);
41+
//var pack_downloaded = await cql.downloadPack(codeql);
42+
var pack_downloaded = await gh.clonePackRepo(ghc);
3443

3544
if (pack_downloaded === false) {
3645
var action_path = path.resolve(path.join(__dirname, "..", "..", ".."));
46+
core.info(`Pack path: '${action_path}'`);
3747
codeql.pack = path.join(action_path, "ql", "src");
48+
core.info(`Codeql pack path: '${codeql.path}'`);
3849

3950
core.info(`Pack defaulting back to local pack: '${codeql.pack}'`);
4051
} else {

0 commit comments

Comments
 (0)