fix: suppress output for some git operations (#3776)
* fix: suppress output for some git operations * update dist
This commit is contained in:
parent
6f7efd1c24
commit
271a8d0340
39
dist/index.js
vendored
39
dist/index.js
vendored
@ -660,12 +660,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.GitCommandManager = void 0;
|
exports.GitCommandManager = void 0;
|
||||||
const exec = __importStar(__nccwpck_require__(5236));
|
const exec = __importStar(__nccwpck_require__(5236));
|
||||||
const io = __importStar(__nccwpck_require__(4994));
|
const io = __importStar(__nccwpck_require__(4994));
|
||||||
const utils = __importStar(__nccwpck_require__(9277));
|
const utils = __importStar(__nccwpck_require__(9277));
|
||||||
const path = __importStar(__nccwpck_require__(6928));
|
const path = __importStar(__nccwpck_require__(6928));
|
||||||
|
const stream_1 = __importDefault(__nccwpck_require__(2203));
|
||||||
const tagsRefSpec = '+refs/tags/*:refs/tags/*';
|
const tagsRefSpec = '+refs/tags/*:refs/tags/*';
|
||||||
class GitCommandManager {
|
class GitCommandManager {
|
||||||
constructor(workingDirectory, gitPath) {
|
constructor(workingDirectory, gitPath) {
|
||||||
@ -781,7 +785,7 @@ class GitCommandManager {
|
|||||||
'--no-abbrev',
|
'--no-abbrev',
|
||||||
`--format=%H%n%T%n%P%n%G?%n%s%n%b%n${endOfBody}`,
|
`--format=%H%n%T%n%P%n%G?%n%s%n%b%n${endOfBody}`,
|
||||||
ref
|
ref
|
||||||
]);
|
], { suppressGitCmdOutput: true });
|
||||||
const lines = output.stdout.split('\n');
|
const lines = output.stdout.split('\n');
|
||||||
const endOfBodyIndex = lines.lastIndexOf(endOfBody);
|
const endOfBodyIndex = lines.lastIndexOf(endOfBody);
|
||||||
const detailLines = lines.slice(0, endOfBodyIndex);
|
const detailLines = lines.slice(0, endOfBodyIndex);
|
||||||
@ -895,7 +899,10 @@ class GitCommandManager {
|
|||||||
showFileAtRefBase64(ref, path) {
|
showFileAtRefBase64(ref, path) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const args = ['show', `${ref}:${path}`];
|
const args = ['show', `${ref}:${path}`];
|
||||||
const output = yield this.exec(args, { encoding: 'base64' });
|
const output = yield this.exec(args, {
|
||||||
|
encoding: 'base64',
|
||||||
|
suppressGitCmdOutput: true
|
||||||
|
});
|
||||||
return output.stdout.trim();
|
return output.stdout.trim();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -964,8 +971,12 @@ class GitCommandManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exec(args_1) {
|
exec(args_1) {
|
||||||
return __awaiter(this, arguments, void 0, function* (args, { encoding = 'utf8', allowAllExitCodes = false } = {}) {
|
return __awaiter(this, arguments, void 0, function* (args, { encoding = 'utf8', allowAllExitCodes = false, suppressGitCmdOutput = false } = {}) {
|
||||||
const result = new GitOutput();
|
const result = new GitOutput();
|
||||||
|
if (process.env['CPR_SHOW_GIT_CMD_OUTPUT']) {
|
||||||
|
// debug mode overrides the suppressGitCmdOutput option
|
||||||
|
suppressGitCmdOutput = false;
|
||||||
|
}
|
||||||
const env = {};
|
const env = {};
|
||||||
for (const key of Object.keys(process.env)) {
|
for (const key of Object.keys(process.env)) {
|
||||||
env[key] = process.env[key];
|
env[key] = process.env[key];
|
||||||
@ -987,7 +998,9 @@ class GitCommandManager {
|
|||||||
stderr.push(data);
|
stderr.push(data);
|
||||||
stderrLength += data.length;
|
stderrLength += data.length;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
outStream: outStreamHandler(process.stdout, suppressGitCmdOutput),
|
||||||
|
errStream: outStreamHandler(process.stderr, suppressGitCmdOutput)
|
||||||
};
|
};
|
||||||
result.exitCode = yield exec.exec(`"${this.gitPath}"`, args, options);
|
result.exitCode = yield exec.exec(`"${this.gitPath}"`, args, options);
|
||||||
result.stdout = Buffer.concat(stdout, stdoutLength).toString(encoding);
|
result.stdout = Buffer.concat(stdout, stdoutLength).toString(encoding);
|
||||||
@ -1004,6 +1017,24 @@ class GitOutput {
|
|||||||
this.exitCode = 0;
|
this.exitCode = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const outStreamHandler = (outStream, suppressGitCmdOutput) => {
|
||||||
|
return new stream_1.default.Writable({
|
||||||
|
write(chunk, _, next) {
|
||||||
|
if (suppressGitCmdOutput) {
|
||||||
|
const lines = chunk.toString().trimEnd().split('\n');
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.startsWith('[command]')) {
|
||||||
|
outStream.write(`${line}\n`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outStream.write(chunk);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -2,6 +2,7 @@ import * as exec from '@actions/exec'
|
|||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import * as utils from './utils'
|
import * as utils from './utils'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
import stream, {Writable} from 'stream'
|
||||||
|
|
||||||
const tagsRefSpec = '+refs/tags/*:refs/tags/*'
|
const tagsRefSpec = '+refs/tags/*:refs/tags/*'
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ export type Commit = {
|
|||||||
export type ExecOpts = {
|
export type ExecOpts = {
|
||||||
allowAllExitCodes?: boolean
|
allowAllExitCodes?: boolean
|
||||||
encoding?: 'utf8' | 'base64'
|
encoding?: 'utf8' | 'base64'
|
||||||
|
suppressGitCmdOutput?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GitCommandManager {
|
export class GitCommandManager {
|
||||||
@ -161,17 +163,20 @@ export class GitCommandManager {
|
|||||||
|
|
||||||
async getCommit(ref: string): Promise<Commit> {
|
async getCommit(ref: string): Promise<Commit> {
|
||||||
const endOfBody = '###EOB###'
|
const endOfBody = '###EOB###'
|
||||||
const output = await this.exec([
|
const output = await this.exec(
|
||||||
'-c',
|
[
|
||||||
'core.quotePath=false',
|
'-c',
|
||||||
'show',
|
'core.quotePath=false',
|
||||||
'--raw',
|
'show',
|
||||||
'--cc',
|
'--raw',
|
||||||
'--no-renames',
|
'--cc',
|
||||||
'--no-abbrev',
|
'--no-renames',
|
||||||
`--format=%H%n%T%n%P%n%G?%n%s%n%b%n${endOfBody}`,
|
'--no-abbrev',
|
||||||
ref
|
`--format=%H%n%T%n%P%n%G?%n%s%n%b%n${endOfBody}`,
|
||||||
])
|
ref
|
||||||
|
],
|
||||||
|
{suppressGitCmdOutput: true}
|
||||||
|
)
|
||||||
const lines = output.stdout.split('\n')
|
const lines = output.stdout.split('\n')
|
||||||
const endOfBodyIndex = lines.lastIndexOf(endOfBody)
|
const endOfBodyIndex = lines.lastIndexOf(endOfBody)
|
||||||
const detailLines = lines.slice(0, endOfBodyIndex)
|
const detailLines = lines.slice(0, endOfBodyIndex)
|
||||||
@ -285,7 +290,10 @@ export class GitCommandManager {
|
|||||||
|
|
||||||
async showFileAtRefBase64(ref: string, path: string): Promise<string> {
|
async showFileAtRefBase64(ref: string, path: string): Promise<string> {
|
||||||
const args = ['show', `${ref}:${path}`]
|
const args = ['show', `${ref}:${path}`]
|
||||||
const output = await this.exec(args, {encoding: 'base64'})
|
const output = await this.exec(args, {
|
||||||
|
encoding: 'base64',
|
||||||
|
suppressGitCmdOutput: true
|
||||||
|
})
|
||||||
return output.stdout.trim()
|
return output.stdout.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,10 +370,19 @@ export class GitCommandManager {
|
|||||||
|
|
||||||
async exec(
|
async exec(
|
||||||
args: string[],
|
args: string[],
|
||||||
{encoding = 'utf8', allowAllExitCodes = false}: ExecOpts = {}
|
{
|
||||||
|
encoding = 'utf8',
|
||||||
|
allowAllExitCodes = false,
|
||||||
|
suppressGitCmdOutput = false
|
||||||
|
}: ExecOpts = {}
|
||||||
): Promise<GitOutput> {
|
): Promise<GitOutput> {
|
||||||
const result = new GitOutput()
|
const result = new GitOutput()
|
||||||
|
|
||||||
|
if (process.env['CPR_SHOW_GIT_CMD_OUTPUT']) {
|
||||||
|
// debug mode overrides the suppressGitCmdOutput option
|
||||||
|
suppressGitCmdOutput = false
|
||||||
|
}
|
||||||
|
|
||||||
const env = {}
|
const env = {}
|
||||||
for (const key of Object.keys(process.env)) {
|
for (const key of Object.keys(process.env)) {
|
||||||
env[key] = process.env[key]
|
env[key] = process.env[key]
|
||||||
@ -389,7 +406,9 @@ export class GitCommandManager {
|
|||||||
stderr.push(data)
|
stderr.push(data)
|
||||||
stderrLength += data.length
|
stderrLength += data.length
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
outStream: outStreamHandler(process.stdout, suppressGitCmdOutput),
|
||||||
|
errStream: outStreamHandler(process.stderr, suppressGitCmdOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.exitCode = await exec.exec(`"${this.gitPath}"`, args, options)
|
result.exitCode = await exec.exec(`"${this.gitPath}"`, args, options)
|
||||||
@ -404,3 +423,24 @@ class GitOutput {
|
|||||||
stderr = ''
|
stderr = ''
|
||||||
exitCode = 0
|
exitCode = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const outStreamHandler = (
|
||||||
|
outStream: Writable,
|
||||||
|
suppressGitCmdOutput: boolean
|
||||||
|
): Writable => {
|
||||||
|
return new stream.Writable({
|
||||||
|
write(chunk, _, next) {
|
||||||
|
if (suppressGitCmdOutput) {
|
||||||
|
const lines = chunk.toString().trimEnd().split('\n')
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.startsWith('[command]')) {
|
||||||
|
outStream.write(`${line}\n`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
outStream.write(chunk)
|
||||||
|
}
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user