mirror of
https://github.com/github/codeql-action.git
synced 2025-12-06 15:58:06 +08:00
Compare commits
5 Commits
v2.25.12
...
python-set
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f65b956f54 | ||
|
|
42f07e2f87 | ||
|
|
d190a018d6 | ||
|
|
4d4cc33d97 | ||
|
|
1c95faf847 |
@@ -16,6 +16,10 @@ inputs:
|
||||
config-file:
|
||||
description: Path of the config file to use
|
||||
required: false
|
||||
setup-python-dependencies:
|
||||
description: Try to auto-install your python dependencies
|
||||
required: true
|
||||
default: 'true'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: '../lib/setup-tracer.js'
|
||||
|
||||
26
lib/finalize-db.js
generated
26
lib/finalize-db.js
generated
@@ -8,6 +8,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const io = __importStar(require("@actions/io"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
@@ -16,12 +17,37 @@ const configUtils = __importStar(require("./config-utils"));
|
||||
const sharedEnv = __importStar(require("./shared-environment"));
|
||||
const upload_lib = __importStar(require("./upload-lib"));
|
||||
const util = __importStar(require("./util"));
|
||||
async function setupPythonExtractor() {
|
||||
const codeqlPython = process.env["CODEQL_PYTHON"];
|
||||
if (codeqlPython === undefined || codeqlPython.length === 0) {
|
||||
// If CODEQL_PYTHON is not set, no dependencies were installed, so we don't need to do anything
|
||||
return;
|
||||
}
|
||||
let output = '';
|
||||
const options = {
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
output += data.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
await exec.exec(codeqlPython, ['-c', 'import os; import pip; print(os.path.dirname(os.path.dirname(pip.__file__)))'], options);
|
||||
core.info('Setting LGTM_INDEX_IMPORT_PATH=' + output);
|
||||
process.env['LGTM_INDEX_IMPORT_PATH'] = output;
|
||||
output = '';
|
||||
await exec.exec(codeqlPython, ['-c', 'import sys; print(sys.version_info[0])'], options);
|
||||
core.info('Setting LGTM_PYTHON_SETUP_VERSION=' + output);
|
||||
process.env['LGTM_PYTHON_SETUP_VERSION'] = output;
|
||||
}
|
||||
async function createdDBForScannedLanguages(databaseFolder) {
|
||||
const scannedLanguages = process.env[sharedEnv.CODEQL_ACTION_SCANNED_LANGUAGES];
|
||||
if (scannedLanguages) {
|
||||
const codeql = codeql_1.getCodeQL();
|
||||
for (const language of scannedLanguages.split(',')) {
|
||||
core.startGroup('Extracting ' + language);
|
||||
if (language === 'python') {
|
||||
await setupPythonExtractor();
|
||||
}
|
||||
await codeql.extractScannedLanguage(path.join(databaseFolder, language), language);
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"finalize-db.js","sourceRoot":"","sources":["../src/finalize-db.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AACtC,gDAAkC;AAClC,uCAAyB;AACzB,2CAA6B;AAE7B,qCAAqC;AACrC,4DAA8C;AAC9C,gEAAkD;AAClD,yDAA2C;AAC3C,6CAA+B;AAE/B,KAAK,UAAU,4BAA4B,CAAC,cAAsB;IAChE,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,+BAA+B,CAAC,CAAC;IAChF,IAAI,gBAAgB,EAAE;QACpB,MAAM,MAAM,GAAG,kBAAS,EAAE,CAAC;QAC3B,KAAK,MAAM,QAAQ,IAAI,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;YAClD,IAAI,CAAC,UAAU,CAAC,aAAa,GAAG,QAAQ,CAAC,CAAC;YAC1C,MAAM,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;YACnF,IAAI,CAAC,QAAQ,EAAE,CAAC;SACjB;KACF;AACH,CAAC;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AAM,KAAK,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;YACtC,IAAI,CAAC,MAAM,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;gBACzC,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAClD,OAAO;aACR;SACF;KAEF;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACpE,OAAO;KACR;IAED,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACd,IAAI,CAAC,SAAS,CAAC,yBAAyB,GAAG,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
||||
40
lib/setup-tracer.js
generated
40
lib/setup-tracer.js
generated
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const io = __importStar(require("@actions/io"));
|
||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const analysisPaths = __importStar(require("./analysis-paths"));
|
||||
@@ -121,6 +122,41 @@ function concatTracerConfigs(configs) {
|
||||
fs.writeFileSync(envPath, buffer);
|
||||
return { env, spec };
|
||||
}
|
||||
async function installPythonDeps(codeql) {
|
||||
core.startGroup('Setup Python dependencies');
|
||||
let scriptsFolder = '';
|
||||
try {
|
||||
const repoPath = await toolcache.downloadTool('https://github.com/Daverlo/codeql-python-autobuild/archive/master.zip');
|
||||
const extracted = await toolcache.extractZip(repoPath);
|
||||
scriptsFolder = path.join(extracted, 'codeql-python-autobuild-master');
|
||||
}
|
||||
catch (e) {
|
||||
// The download should not fail, but in case it fails we just abort trying to setup the python deps
|
||||
core.warning('Unable to download and extract the scripts needed for installing the python dependecies');
|
||||
core.endGroup();
|
||||
return;
|
||||
}
|
||||
// Setup tools
|
||||
try {
|
||||
await exec.exec(path.join(scriptsFolder, 'install_tools.sh'));
|
||||
}
|
||||
catch (e) {
|
||||
// This script tries to install some needed tools in the runner. It should not fail, but if it does
|
||||
// we just abort the process without failing the action
|
||||
core.warning('Unable to download and extract the scripts needed for installing the python dependecies');
|
||||
core.endGroup();
|
||||
return;
|
||||
}
|
||||
// Install dependencies
|
||||
try {
|
||||
await exec.exec(path.join(scriptsFolder, 'auto_install_packages.py'), [codeql.getDir()]);
|
||||
}
|
||||
catch (e) {
|
||||
core.endGroup();
|
||||
throw new Error('We were unable to install your python dependencies. You can call this action with "setup-python-dependencies: false" to disable this process');
|
||||
}
|
||||
core.endGroup();
|
||||
}
|
||||
async function run() {
|
||||
let config;
|
||||
let codeql;
|
||||
@@ -150,6 +186,10 @@ async function run() {
|
||||
core.exportVariable('GOFLAGS', goFlags);
|
||||
core.warning("Passing the GOFLAGS env parameter to the init action is deprecated. Please move this to the analyze action.");
|
||||
}
|
||||
const setupPythonDependencies = core.getInput('setup-python-dependencies', { required: true });
|
||||
if (config.languages.includes('python') && setupPythonDependencies === 'true') {
|
||||
await installPythonDeps(codeql);
|
||||
}
|
||||
// Setup CODEQL_RAM flag (todo improve this https://github.com/github/dsp-code-scanning/issues/935)
|
||||
const codeqlRam = process.env['CODEQL_RAM'] || '6500';
|
||||
core.exportVariable('CODEQL_RAM', codeqlRam);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,5 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
@@ -9,12 +10,47 @@ import * as sharedEnv from './shared-environment';
|
||||
import * as upload_lib from './upload-lib';
|
||||
import * as util from './util';
|
||||
|
||||
|
||||
async function setupPythonExtractor() {
|
||||
const codeqlPython = process.env["CODEQL_PYTHON"];
|
||||
if (codeqlPython === undefined || codeqlPython.length === 0) {
|
||||
// If CODEQL_PYTHON is not set, no dependencies were installed, so we don't need to do anything
|
||||
return;
|
||||
}
|
||||
|
||||
let output = '';
|
||||
const options = {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
output += data.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await exec.exec(
|
||||
codeqlPython,
|
||||
['-c', 'import os; import pip; print(os.path.dirname(os.path.dirname(pip.__file__)))'],
|
||||
options);
|
||||
core.info('Setting LGTM_INDEX_IMPORT_PATH=' + output);
|
||||
process.env['LGTM_INDEX_IMPORT_PATH'] = output;
|
||||
|
||||
output = '';
|
||||
await exec.exec(codeqlPython, ['-c', 'import sys; print(sys.version_info[0])'], options);
|
||||
core.info('Setting LGTM_PYTHON_SETUP_VERSION=' + output);
|
||||
process.env['LGTM_PYTHON_SETUP_VERSION'] = output;
|
||||
}
|
||||
|
||||
async function createdDBForScannedLanguages(databaseFolder: string) {
|
||||
const scannedLanguages = process.env[sharedEnv.CODEQL_ACTION_SCANNED_LANGUAGES];
|
||||
if (scannedLanguages) {
|
||||
const codeql = getCodeQL();
|
||||
for (const language of scannedLanguages.split(',')) {
|
||||
core.startGroup('Extracting ' + language);
|
||||
|
||||
if (language === 'python') {
|
||||
await setupPythonExtractor();
|
||||
}
|
||||
|
||||
await codeql.extractScannedLanguage(path.join(databaseFolder, language), language);
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import * as toolcache from '@actions/tool-cache';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
@@ -131,6 +132,41 @@ function concatTracerConfigs(configs: { [lang: string]: TracerConfig }): TracerC
|
||||
return { env, spec };
|
||||
}
|
||||
|
||||
async function installPythonDeps(codeql: CodeQL) {
|
||||
core.startGroup('Setup Python dependencies');
|
||||
|
||||
let scriptsFolder = '';
|
||||
try {
|
||||
const repoPath = await toolcache.downloadTool('https://github.com/Daverlo/codeql-python-autobuild/archive/master.zip');
|
||||
const extracted = await toolcache.extractZip(repoPath);
|
||||
scriptsFolder = path.join(extracted, 'codeql-python-autobuild-master');
|
||||
} catch (e) {
|
||||
// The download should not fail, but in case it fails we just abort trying to setup the python deps
|
||||
core.warning('Unable to download and extract the scripts needed for installing the python dependecies');
|
||||
core.endGroup();
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup tools
|
||||
try {
|
||||
await exec.exec(path.join(scriptsFolder, 'install_tools.sh'));
|
||||
} catch (e) {
|
||||
// This script tries to install some needed tools in the runner. It should not fail, but if it does
|
||||
// we just abort the process without failing the action
|
||||
core.warning('Unable to download and extract the scripts needed for installing the python dependecies');
|
||||
core.endGroup();
|
||||
return;
|
||||
}
|
||||
// Install dependencies
|
||||
try {
|
||||
await exec.exec(path.join(scriptsFolder, 'auto_install_packages.py'), [codeql.getDir()]);
|
||||
} catch (e) {
|
||||
core.endGroup();
|
||||
throw new Error('We were unable to install your python dependencies. You can call this action with "setup-python-dependencies: false" to disable this process');
|
||||
}
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
async function run() {
|
||||
|
||||
let config: configUtils.Config;
|
||||
@@ -168,6 +204,11 @@ async function run() {
|
||||
core.warning("Passing the GOFLAGS env parameter to the init action is deprecated. Please move this to the analyze action.");
|
||||
}
|
||||
|
||||
const setupPythonDependencies = core.getInput('setup-python-dependencies', { required: true });
|
||||
if (config.languages.includes('python') && setupPythonDependencies === 'true') {
|
||||
await installPythonDeps(codeql);
|
||||
}
|
||||
|
||||
// Setup CODEQL_RAM flag (todo improve this https://github.com/github/dsp-code-scanning/issues/935)
|
||||
const codeqlRam = process.env['CODEQL_RAM'] || '6500';
|
||||
core.exportVariable('CODEQL_RAM', codeqlRam);
|
||||
|
||||
Reference in New Issue
Block a user