Skip to content

Commit fff2c76

Browse files
authored
Line listeners from @actions/exec is broken (#3)
Line listeners from @actions/exec is broken
1 parent a46834a commit fff2c76

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
9+
## [1.0.1] - 2020-04-13
10+
11+
### Changed
12+
13+
- Fix #2: Line listeners from @actions/exec is broken

dist/index.js

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cargo.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export class Cargo {
3535

3636
///
3737
async runCommand(command: string, args: string[]): Promise<number> {
38+
let outBuffer = ''
39+
let errBuffer = ''
3840
const resultCode = await exec.exec(
3941
'cargo',
4042
[
@@ -48,8 +50,20 @@ export class Cargo {
4850
silent: true,
4951
ignoreReturnCode: true,
5052
listeners: {
51-
stdline: this.processOutputLine,
52-
errline: this.processErrorLine,
53+
stdout: (data: Buffer) => {
54+
outBuffer = Cargo.processLineBuffer(
55+
data,
56+
outBuffer,
57+
this.processOutputLine
58+
)
59+
},
60+
stderr: (data: Buffer) => {
61+
errBuffer = Cargo.processLineBuffer(
62+
data,
63+
errBuffer,
64+
this.processErrorLine
65+
)
66+
},
5367
debug: this.processOutputLine
5468
}
5569
}
@@ -90,4 +104,26 @@ export class Cargo {
90104
private isFormatterSupport(command: string): boolean {
91105
return command !== 'fmt' && command !== 'audit'
92106
}
107+
108+
private static processLineBuffer(
109+
data: Buffer,
110+
strBuffer: string,
111+
onLine: (line: string) => void
112+
): string {
113+
const EOL = '\n'
114+
115+
let s = strBuffer + data.toString()
116+
let n = s.indexOf(EOL)
117+
118+
while (n > -1) {
119+
const line = s.substring(0, n)
120+
onLine(line)
121+
122+
// the rest of the string ...
123+
s = s.substring(n + EOL.length)
124+
n = s.indexOf(EOL)
125+
}
126+
127+
return s
128+
}
93129
}

0 commit comments

Comments
 (0)