Skip to content

Commit

Permalink
Fix CodeQL fail tests (#1034)
Browse files Browse the repository at this point in the history
* Fix CodeQL fail tests

- Fixed error when the spawn method couldn't execute

* temporary enable codeql for all branches

* Revert "temporary enable codeql for all branches"

This reverts commit 057dfb6.

* Increase timeout for codeql
  • Loading branch information
DmitriiBobreshev committed Apr 11, 2024
1 parent ab88524 commit 70d4711
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 49 deletions.
2 changes: 1 addition & 1 deletion node/package-lock.json

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

2 changes: 1 addition & 1 deletion node/package.json
@@ -1,6 +1,6 @@
{
"name": "azure-pipelines-task-lib",
"version": "4.10.1",
"version": "4.11.0",
"description": "Azure Pipelines Task SDK",
"main": "./task.js",
"typings": "./task.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion node/test/toolrunnertests.ts
Expand Up @@ -608,7 +608,7 @@ describe('Toolrunner Tests', function () {
});
})
it('Exec pipe output to another tool, succeeds if both tools succeed', function (done) {
this.timeout(30000);
this.timeout(120000);

var _testExecOptions = <trm.IExecOptions>{
cwd: __dirname,
Expand Down
123 changes: 77 additions & 46 deletions node/toolrunner.ts
Expand Up @@ -1098,7 +1098,45 @@ export class ToolRunner extends events.EventEmitter {
this._debug(message);
});

let cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
var stdbuffer: string = '';
var errbuffer: string = '';
const emitDoneEvent = function (resolve, reject) {
state.on('done', (error: Error, exitCode: number) => {
if (stdbuffer.length > 0) {
this.emit('stdline', stdbuffer);
}

if (errbuffer.length > 0) {
this.emit('errline', errbuffer);
}

if (cp) {
cp.removeAllListeners();
}

if (error) {
reject(error);
}
else {
resolve(exitCode);
}
});
}

// Edge case when the node itself cant's spawn and emit event
let cp;
try {
cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
} catch (error) {
return new Promise((resolve, reject) => {
emitDoneEvent(resolve, reject);
state.processError = error.message;
state.processExited = true;
state.processClosed = true;
state.CheckComplete();
});
}

this.childProcess = cp;
// it is possible for the child process to end its last line without a new line.
// because stdout is buffered, this causes the last line to not get sent to the parent
Expand All @@ -1109,7 +1147,6 @@ export class ToolRunner extends events.EventEmitter {
}
});

var stdbuffer: string = '';
cp.stdout?.on('data', (data: Buffer) => {
this.emit('stdout', data);

Expand All @@ -1122,8 +1159,6 @@ export class ToolRunner extends events.EventEmitter {
});
});


var errbuffer: string = '';
cp.stderr?.on('data', (data: Buffer) => {
state.processStderr = true;
this.emit('stderr', data);
Expand Down Expand Up @@ -1160,26 +1195,7 @@ export class ToolRunner extends events.EventEmitter {
state.CheckComplete();
});

return new Promise((resolve, reject) => {
state.on('done', (error: Error, exitCode: number) => {
if (stdbuffer.length > 0) {
this.emit('stdline', stdbuffer);
}

if (errbuffer.length > 0) {
this.emit('errline', errbuffer);
}

cp.removeAllListeners();

if (error) {
reject(error);
}
else {
resolve(exitCode);
}
});
});
return new Promise(emitDoneEvent);
}

/**
Expand Down Expand Up @@ -1215,7 +1231,43 @@ export class ToolRunner extends events.EventEmitter {
this._debug(message);
});

let cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
var stdbuffer: string = '';
var errbuffer: string = '';
state.on('done', (error: Error, exitCode: number) => {
if (stdbuffer.length > 0) {
this.emit('stdline', stdbuffer);
}

if (errbuffer.length > 0) {
this.emit('errline', errbuffer);
}

if (cp) {
cp.removeAllListeners();
}

if (error) {
defer.reject(error);
}
else {
defer.resolve(exitCode);
}
});


// Edge case when the node itself cant's spawn and emit event
let cp;
try {
cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
} catch (error) {
state.processError = error.message;
state.processExited = true;
state.processClosed = true;
state.CheckComplete();

return defer.promise;
}

this.childProcess = cp;
// it is possible for the child process to end its last line without a new line.
// because stdout is buffered, this causes the last line to not get sent to the parent
Expand All @@ -1226,7 +1278,6 @@ export class ToolRunner extends events.EventEmitter {
}
});

var stdbuffer: string = '';
cp.stdout?.on('data', (data: Buffer) => {
this.emit('stdout', data);

Expand All @@ -1240,7 +1291,6 @@ export class ToolRunner extends events.EventEmitter {
});


var errbuffer: string = '';
cp.stderr?.on('data', (data: Buffer) => {
state.processStderr = true;
this.emit('stderr', data);
Expand Down Expand Up @@ -1277,25 +1327,6 @@ export class ToolRunner extends events.EventEmitter {
state.CheckComplete();
});

state.on('done', (error: Error, exitCode: number) => {
if (stdbuffer.length > 0) {
this.emit('stdline', stdbuffer);
}

if (errbuffer.length > 0) {
this.emit('errline', errbuffer);
}

cp.removeAllListeners();

if (error) {
defer.reject(error);
}
else {
defer.resolve(exitCode);
}
});

return defer.promise;
}

Expand Down

0 comments on commit 70d4711

Please sign in to comment.