Create annotations where exceptions were thrown

This commit is contained in:
Michal Dorner 2020-11-28 21:24:57 +01:00
parent 6750c31e23
commit fc8cfe0f32
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
15 changed files with 1606 additions and 19 deletions

21
src/utils/exec.ts Normal file
View file

@ -0,0 +1,21 @@
import {exec as execImpl, ExecOptions} from '@actions/exec'
// Wraps original exec() function
// Returns exit code and whole stdout/stderr
export default async function exec(commandLine: string, args?: string[], options?: ExecOptions): Promise<ExecResult> {
options = options || {}
let stdout = ''
let stderr = ''
options.listeners = {
stdout: (data: Buffer) => (stdout += data.toString()),
stderr: (data: Buffer) => (stderr += data.toString())
}
const code = await execImpl(commandLine, args, options)
return {code, stdout, stderr}
}
export interface ExecResult {
code: number
stdout: string
stderr: string
}

View file

@ -11,3 +11,23 @@ export function getFileContent(path: string): string {
return fs.readFileSync(path, {encoding: 'utf8'})
}
export function normalizeDirPath(path: string, trailingSeparator: boolean): string {
if (!path) {
return path
}
path = normalizeFilePath(path)
if (trailingSeparator && !path.endsWith('/')) {
path += '/'
}
return path
}
export function normalizeFilePath(path: string): string {
if (!path) {
return path
}
return path.trim().replace(/\\/g, '/')
}

22
src/utils/git.ts Normal file
View file

@ -0,0 +1,22 @@
import * as core from '@actions/core'
import exec from './exec'
export async function listFiles(): Promise<string[]> {
core.startGroup('Listing all files tracked by git')
let output = ''
try {
output = (await exec('git', ['ls-files', '-z'])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
}
return output.split('\u0000').filter(s => s.length > 0)
}
function fixStdOutNullTermination(): void {
// Previous command uses NULL as delimiters and output is printed to stdout.
// We have to make sure next thing written to stdout will start on new line.
// Otherwise things like ::set-output wouldn't work.
core.info('')
}