Skip to content

Commit

Permalink
check environment before running autobuild or analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Brignull committed Aug 27, 2020
1 parent a542021 commit f80d660
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/runner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/runner.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import * as path from 'path';
import { runAnalyze } from './analyze';
import { determineAutobuildLanguage, runAutobuild } from './autobuild';
import { CodeQL, getCodeQL } from './codeql';
import { getConfig} from './config-utils';
import { Config, getConfig } from './config-utils';
import { initCodeQL, initConfig, runInit } from './init';
import { Language, parseLanguage } from './languages';
import { isTracedLanguage, Language, parseLanguage } from './languages';
import { getRunnerLogger } from './logging';
import { parseRepositoryNwo } from './repository';
import * as upload_lib from './upload-lib';
Expand Down Expand Up @@ -57,6 +57,14 @@ function getToolsDir(userInput: string | undefined): string {
return toolsDir;
}

function checkEnvironmentSetup(config: Config) {
if (config.languages.some(isTracedLanguage) && !('ODASA_TRACER_CONFIGURATION' in process.env)) {
throw new Error("Could not detect 'ODASA_TRACER_CONFIGURATION' in environment. " +
"Make sure that environment variables were correctly exported to future processes. " +
"See end out output from 'init' command for instructions.");
}
}

const logger = getRunnerLogger();

interface InitArgs {
Expand Down Expand Up @@ -176,6 +184,7 @@ program
.action(async (cmd: AutobuildArgs) => {
try {
const config = await getConfig(getTempDir(cmd.tempDir), logger);
checkEnvironmentSetup(config);
let language: Language | undefined = undefined;
if (cmd.language !== undefined) {
language = parseLanguage(cmd.language);
Expand Down Expand Up @@ -225,6 +234,7 @@ program
const tempDir = getTempDir(cmd.tempDir);
const outputDir = cmd.outputDir || path.join(tempDir, 'codeql-sarif');
const config = await getConfig(getTempDir(cmd.tempDir), logger);
checkEnvironmentSetup(config);
await runAnalyze(
parseRepositoryNwo(cmd.repository),
cmd.commit,
Expand Down

0 comments on commit f80d660

Please sign in to comment.