mirror of
https://github.com/opentofu/setup-opentofu.git
synced 2026-11-30 19:54:27 +01:00
Streaming when using tofu_wrapper (#75)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
This commit is contained in:
1 parent
04ba7507e2
commit
e95ccdd206
4 files changed
+20
-18
No files matched your search
Vendored
+7
-8
@@ -25899,7 +25899,8 @@ module.exports = {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Instantiate a new listener
|
* // Instantiate a new listener
|
||||||
* const listener = new OutputListener();
|
* // stream is used to write the data before waiting for the listener to complete
|
||||||
|
* const listener = new OutputListener(stream);
|
||||||
* // Register listener against STDOUT stream
|
* // Register listener against STDOUT stream
|
||||||
* await exec.exec('ls', ['-ltr'], {
|
* await exec.exec('ls', ['-ltr'], {
|
||||||
* listeners: {
|
* listeners: {
|
||||||
@@ -25910,12 +25911,14 @@ module.exports = {
|
|||||||
* console.log(listener.contents);
|
* console.log(listener.contents);
|
||||||
*/
|
*/
|
||||||
class OutputListener {
|
class OutputListener {
|
||||||
constructor () {
|
constructor (stream) {
|
||||||
this._buff = [];
|
this._buff = [];
|
||||||
|
this._stream = stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
get listener () {
|
get listener () {
|
||||||
const listen = function listen (data) {
|
const listen = function listen (data) {
|
||||||
|
this._stream.write(data);
|
||||||
this._buff.push(data);
|
this._buff.push(data);
|
||||||
};
|
};
|
||||||
return listen.bind(this);
|
return listen.bind(this);
|
||||||
@@ -27889,8 +27892,8 @@ async function checkTofu () {
|
|||||||
await checkTofu();
|
await checkTofu();
|
||||||
|
|
||||||
// Create listeners to receive output (in memory) as well
|
// Create listeners to receive output (in memory) as well
|
||||||
const stdout = new OutputListener();
|
const stdout = new OutputListener(process.stdout);
|
||||||
const stderr = new OutputListener();
|
const stderr = new OutputListener(process.stderr);
|
||||||
const listeners = {
|
const listeners = {
|
||||||
stdout: stdout.listener,
|
stdout: stdout.listener,
|
||||||
stderr: stderr.listener
|
stderr: stderr.listener
|
||||||
@@ -27905,10 +27908,6 @@ async function checkTofu () {
|
|||||||
};
|
};
|
||||||
const exitCode = await exec(pathToCLI, args, options);
|
const exitCode = await exec(pathToCLI, args, options);
|
||||||
|
|
||||||
// Pass-through stdout/err as `exec` won't due to `silent: true` option
|
|
||||||
process.stdout.write(stdout.contents);
|
|
||||||
process.stderr.write(stderr.contents);
|
|
||||||
|
|
||||||
// Set outputs, result, exitcode, and stderr
|
// Set outputs, result, exitcode, and stderr
|
||||||
core.setOutput('stdout', stdout.contents);
|
core.setOutput('stdout', stdout.contents);
|
||||||
core.setOutput('stderr', stderr.contents);
|
core.setOutput('stderr', stderr.contents);
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Instantiate a new listener
|
* // Instantiate a new listener
|
||||||
* const listener = new OutputListener();
|
* // stream is used to write the data before waiting for the listener to complete
|
||||||
|
* const listener = new OutputListener(stream);
|
||||||
* // Register listener against STDOUT stream
|
* // Register listener against STDOUT stream
|
||||||
* await exec.exec('ls', ['-ltr'], {
|
* await exec.exec('ls', ['-ltr'], {
|
||||||
* listeners: {
|
* listeners: {
|
||||||
@@ -20,12 +21,14 @@
|
|||||||
* console.log(listener.contents);
|
* console.log(listener.contents);
|
||||||
*/
|
*/
|
||||||
class OutputListener {
|
class OutputListener {
|
||||||
constructor () {
|
constructor (stream) {
|
||||||
this._buff = [];
|
this._buff = [];
|
||||||
|
this._stream = stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
get listener () {
|
get listener () {
|
||||||
const listen = function listen (data) {
|
const listen = function listen (data) {
|
||||||
|
this._stream.write(data);
|
||||||
this._buff.push(data);
|
this._buff.push(data);
|
||||||
};
|
};
|
||||||
return listen.bind(this);
|
return listen.bind(this);
|
||||||
|
|||||||
@@ -4,14 +4,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const OutputListener = require('../lib/output-listener');
|
const OutputListener = require('../lib/output-listener');
|
||||||
|
const { PassThrough } = require('stream');
|
||||||
describe('output-listener', () => {
|
describe('output-listener', () => {
|
||||||
it('receives and exposes data', () => {
|
it('receives and exposes data', () => {
|
||||||
const listener = new OutputListener();
|
const stream = new PassThrough();
|
||||||
|
const listener = new OutputListener(stream);
|
||||||
const listen = listener.listener;
|
const listen = listener.listener;
|
||||||
listen(Buffer.from('foo'));
|
listen(Buffer.from('foo'));
|
||||||
|
expect(stream.read()).toEqual(Buffer.from('foo'));
|
||||||
listen(Buffer.from('bar'));
|
listen(Buffer.from('bar'));
|
||||||
|
expect(stream.read()).toEqual(Buffer.from('bar'));
|
||||||
listen(Buffer.from('baz'));
|
listen(Buffer.from('baz'));
|
||||||
|
expect(stream.read()).toEqual(Buffer.from('baz'));
|
||||||
expect(listener.contents).toEqual('foobarbaz');
|
expect(listener.contents).toEqual('foobarbaz');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
+2
-6
@@ -22,8 +22,8 @@ async function checkTofu () {
|
|||||||
await checkTofu();
|
await checkTofu();
|
||||||
|
|
||||||
// Create listeners to receive output (in memory) as well
|
// Create listeners to receive output (in memory) as well
|
||||||
const stdout = new OutputListener();
|
const stdout = new OutputListener(process.stdout);
|
||||||
const stderr = new OutputListener();
|
const stderr = new OutputListener(process.stderr);
|
||||||
const listeners = {
|
const listeners = {
|
||||||
stdout: stdout.listener,
|
stdout: stdout.listener,
|
||||||
stderr: stderr.listener
|
stderr: stderr.listener
|
||||||
@@ -38,10 +38,6 @@ async function checkTofu () {
|
|||||||
};
|
};
|
||||||
const exitCode = await exec(pathToCLI, args, options);
|
const exitCode = await exec(pathToCLI, args, options);
|
||||||
|
|
||||||
// Pass-through stdout/err as `exec` won't due to `silent: true` option
|
|
||||||
process.stdout.write(stdout.contents);
|
|
||||||
process.stderr.write(stderr.contents);
|
|
||||||
|
|
||||||
// Set outputs, result, exitcode, and stderr
|
// Set outputs, result, exitcode, and stderr
|
||||||
core.setOutput('stdout', stdout.contents);
|
core.setOutput('stdout', stdout.contents);
|
||||||
core.setOutput('stderr', stderr.contents);
|
core.setOutput('stderr', stderr.contents);
|
||||||
|
|||||||
Reference in new issue
Block a user