Skip to content

Commit

Permalink
Line listeners from @actions/exec is broken (#3)
Browse files Browse the repository at this point in the history
Line listeners from @actions/exec is broken
  • Loading branch information
qRoC authored Apr 13, 2021
1 parent a46834a commit fff2c76
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ All notable changes to this project will be documented in this file.
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).

## [Unreleased]

## [1.0.1] - 2020-04-13

### Changed

- Fix #2: Line listeners from @actions/exec is broken
23 changes: 21 additions & 2 deletions dist/index.js

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

40 changes: 38 additions & 2 deletions src/Cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class Cargo {

///
async runCommand(command: string, args: string[]): Promise<number> {
let outBuffer = ''
let errBuffer = ''
const resultCode = await exec.exec(
'cargo',
[
Expand All @@ -48,8 +50,20 @@ export class Cargo {
silent: true,
ignoreReturnCode: true,
listeners: {
stdline: this.processOutputLine,
errline: this.processErrorLine,
stdout: (data: Buffer) => {
outBuffer = Cargo.processLineBuffer(
data,
outBuffer,
this.processOutputLine
)
},
stderr: (data: Buffer) => {
errBuffer = Cargo.processLineBuffer(
data,
errBuffer,
this.processErrorLine
)
},
debug: this.processOutputLine
}
}
Expand Down Expand Up @@ -90,4 +104,26 @@ export class Cargo {
private isFormatterSupport(command: string): boolean {
return command !== 'fmt' && command !== 'audit'
}

private static processLineBuffer(
data: Buffer,
strBuffer: string,
onLine: (line: string) => void
): string {
const EOL = '\n'

let s = strBuffer + data.toString()
let n = s.indexOf(EOL)

while (n > -1) {
const line = s.substring(0, n)
onLine(line)

// the rest of the string ...
s = s.substring(n + EOL.length)
n = s.indexOf(EOL)
}

return s
}
}

0 comments on commit fff2c76

Please sign in to comment.