Skip to content

Commit

Permalink
Add code to output required env to files
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Brignull committed Aug 26, 2020
1 parent 217483d commit 3ffe4b7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
31 changes: 30 additions & 1 deletion 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.

34 changes: 33 additions & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,39 @@ program
parseGithubUrl(cmd.githubUrl),
logger);

await runInit(codeql, config);
const tracerConfig = await runInit(codeql, config);
if (tracerConfig !== undefined) {
if (process.platform === 'win32') {
const batEnvFile = path.join(config.tempDir, 'codeql-env.bat');
const batEnvFileContents = Object.entries(tracerConfig.env)
.map(([key, value]) => `Set ${key}=${value}`)
.join('\n');
fs.writeFileSync(batEnvFile, batEnvFileContents);

const powershellEnvFile = path.join(config.tempDir, 'codeql-env.sh');
const powershellEnvFileContents = Object.entries(tracerConfig.env)
.map(([key, value]) => `$env:${key}="${value}"`)
.join('\n');
fs.writeFileSync(powershellEnvFile, powershellEnvFileContents);

logger.info(`CodeQL environment outputted to "${batEnvFileContents}" and "${powershellEnvFile}". ` +
`Please export these variables to future processes so the build can tbe traced. ` +
`If using cmd/batch run "call ${batEnvFileContents}" ` +
`or if using PowerShell run "cat ${powershellEnvFile} | Invoke-Expression".`);

} else {
// Assume that anything that's not windows is using a unix-style shell
const envFile = path.join(config.tempDir, 'codeql-env.sh');
const envFileContents = Object.entries(tracerConfig.env)
.map(([key, value]) => `${key}="${value}"`)
.join('\n');
fs.writeFileSync(envFile, envFileContents);

logger.info(`CodeQL environment outputted to "${envFile}". ` +
`Please export these variables to future processes so the build can tbe traced, ` +
`for example by running "source ${envFile}".`);
}
}

} catch (e) {
logger.error('Init failed');
Expand Down

0 comments on commit 3ffe4b7

Please sign in to comment.