Skip to content

Commit

Permalink
Showing 9 changed files with 113 additions and 53 deletions.
2 changes: 1 addition & 1 deletion lib/init-action.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/init-action.js.map

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

74 changes: 52 additions & 22 deletions lib/init.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/init.js.map

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

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/init-action.ts
@@ -99,7 +99,7 @@ async function run() {
const codeqlRam = process.env['CODEQL_RAM'] || '6500';
core.exportVariable('CODEQL_RAM', codeqlRam);

const tracerConfig = await runInit(codeql, config);
const tracerConfig = await runInit(codeql, config, 'actions');
if (tracerConfig !== undefined) {
Object.entries(tracerConfig.env).forEach(([key, value]) => core.exportVariable(key, value));
}
78 changes: 54 additions & 24 deletions src/init.ts
@@ -66,7 +66,8 @@ export async function initConfig(

export async function runInit(
codeql: CodeQL,
config: configUtils.Config): Promise<TracerConfig | undefined> {
config: configUtils.Config,
mode: util.Mode): Promise<TracerConfig | undefined> {

const sourceRoot = path.resolve();

@@ -81,31 +82,60 @@ export async function runInit(
const tracerConfig = await getCombinedTracerConfig(config, codeql);
if (tracerConfig !== undefined && process.platform === 'win32') {
const injectTracerPath = path.join(config.tempDir, 'inject-tracer.ps1');
fs.writeFileSync(injectTracerPath, `
Param(
[Parameter(Position=0)]
[String]
$tracer
)
# Go up the process tree until finding an ancestor called "Runner.Worker.exe"
# A new Runner.Worker is spawned for each job. It is spawned by a process
# called Runner.Listener that persists for the life of the worker.
$id = $PID
while ($true) {
$p = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id"
Write-Host "Found process: $p"
if ($p -eq $null) {
throw "Could not determine Runner.Worker.exe process"
}
if ($p[0].Name -eq "Runner.Worker.exe") {
Break
} else {
$id = $p[0].ParentProcessId
if (mode === 'actions') {
fs.writeFileSync(injectTracerPath, `
Param(
[Parameter(Position=0)]
[String]
$tracer
)
# Go up the process tree until finding an ancestor called "Runner.Worker.exe"
# A new Runner.Worker is spawned for each job. It is spawned by a process
# called Runner.Listener that persists for the life of the worker.
$id = $PID
while ($true) {
$p = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id"
Write-Host "Found process: $p"
if ($p -eq $null) {
throw "Could not determine Runner.Worker.exe process"
}
if ($p[0].Name -eq "Runner.Worker.exe") {
Break
} else {
$id = $p[0].ParentProcessId
}
}
}
Invoke-Expression "&$tracer --inject=$id"`);
Invoke-Expression "&$tracer --inject=$id"`);
} else {
fs.writeFileSync(injectTracerPath, `
Param(
[Parameter(Position=0)]
[String]
$tracer
)
# The current process.
$id0 = $PID
$p0 = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id0"
Write-Host "Found process: $p0"
# The 1st parent process will be the runner proces.
$id1 = $p0[0].ParentProcessId
$p1 = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id1"
Write-Host "Found process: $p1"
# The 2nd parent process (i.e. the parent of the runner process)
$id2 = $p1[0].ParentProcessId
$p2 = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id2"
Write-Host "Found process: $p2"
# Assume the second parent will persist and later also spawn the build process.
# This is a total guess but is the best we can do in the absence of any
# information about what system is invoking us.
Invoke-Expression "&$tracer --inject=$id"`);
}

await new toolrunnner.ToolRunner(
'powershell',
2 changes: 1 addition & 1 deletion src/runner.ts
@@ -132,7 +132,7 @@ program
parseGithubUrl(cmd.githubUrl),
logger);

const tracerConfig = await runInit(codeql, config);
const tracerConfig = await runInit(codeql, config, 'runner');
if (tracerConfig === undefined) {
return;
}

0 comments on commit 48df013

Please sign in to comment.