fix: broken run command that was reading from input buffer
parent
45b043c5b9
commit
6ac9e78e60
|
|
@ -81,6 +81,8 @@
|
||||||
// Null is useful when explicit value is passed
|
// Null is useful when explicit value is passed
|
||||||
"unicorn/no-null": "off",
|
"unicorn/no-null": "off",
|
||||||
// (enable to add improvements)
|
// (enable to add improvements)
|
||||||
"unicorn/prefer-export-from": "off"
|
"unicorn/prefer-export-from": "off",
|
||||||
|
// Deno uses const a=new Buffer(new TextEncoder().encode('Hello World'));
|
||||||
|
"unicorn/no-new-buffer": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import * as http from 'https://deno.land/std@0.145.0/node/http.ts';
|
||||||
import * as string from 'https://deno.land/std@0.36.0/strings/mod.ts';
|
import * as string from 'https://deno.land/std@0.36.0/strings/mod.ts';
|
||||||
import { Command } from 'https://deno.land/x/cmd@v1.2.0/commander/index.ts';
|
import { Command } from 'https://deno.land/x/cmd@v1.2.0/commander/index.ts';
|
||||||
import { getUnityChangeset as getUnityChangeSet } from 'https://deno.land/x/unity_changeset@2.0.0/src/index.ts';
|
import { getUnityChangeset as getUnityChangeSet } from 'https://deno.land/x/unity_changeset@2.0.0/src/index.ts';
|
||||||
|
import { Buffer } from 'https://deno.land/std@0.151.0/io/buffer.ts';
|
||||||
|
|
||||||
// Internally managed
|
// Internally managed
|
||||||
import waitUntil from './modules/wait-until.ts';
|
import waitUntil from './modules/wait-until.ts';
|
||||||
|
|
@ -45,6 +46,7 @@ export {
|
||||||
assert,
|
assert,
|
||||||
aws,
|
aws,
|
||||||
base64,
|
base64,
|
||||||
|
Buffer,
|
||||||
Command,
|
Command,
|
||||||
compress,
|
compress,
|
||||||
core,
|
core,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ class Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
static get workspace() {
|
static get workspace() {
|
||||||
|
if (Action.isRunningLocally) return Deno.cwd();
|
||||||
|
|
||||||
return Deno.env.get('GITHUB_WORKSPACE');
|
return Deno.env.get('GITHUB_WORKSPACE');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,45 @@
|
||||||
import { core, exec } from '../dependencies.ts';
|
import { exec } from '../dependencies.ts';
|
||||||
|
|
||||||
class System {
|
class System {
|
||||||
|
static async shellRun(command) {
|
||||||
|
return System.newRun('sh', ['-c', command]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example:
|
||||||
|
* System.newRun(sh, ['-c', 'echo something'])
|
||||||
|
*
|
||||||
|
* private for now, but could become public if this happens to be a great replacement for the other run method.
|
||||||
|
*/
|
||||||
|
private static async newRun(command, args: string | string[] = []) {
|
||||||
|
if (!Array.isArray(args)) args = [args];
|
||||||
|
|
||||||
|
const argsString = args.join(' ');
|
||||||
|
const process = Deno.run({
|
||||||
|
cmd: [command, ...args],
|
||||||
|
stdout: 'piped',
|
||||||
|
stderr: 'piped',
|
||||||
|
});
|
||||||
|
|
||||||
|
const status = await process.status();
|
||||||
|
const outputBuffer = await process.output();
|
||||||
|
const errorBuffer = await process.stderrOutput();
|
||||||
|
|
||||||
|
process.close();
|
||||||
|
|
||||||
|
const output = new TextDecoder().decode(outputBuffer);
|
||||||
|
const error = new TextDecoder().decode(errorBuffer);
|
||||||
|
|
||||||
|
const result = { status, output };
|
||||||
|
const symbol = status.success ? '✅' : '❗';
|
||||||
|
|
||||||
|
log.debug('Command:', command, argsString, symbol, result);
|
||||||
|
|
||||||
|
if (error) throw new Error(error);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static async run(command, arguments_: any = [], options = {}, shouldLog = true) {
|
static async run(command, arguments_: any = [], options = {}, shouldLog = true) {
|
||||||
let result = '';
|
let result = '';
|
||||||
let error = '';
|
let error = '';
|
||||||
|
|
@ -48,17 +87,25 @@ class System {
|
||||||
throw new Error(`Failed to execute empty command`);
|
throw new Error(`Failed to execute empty command`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { exitCode } = await exec(command, arguments_, { silent: true, listeners, ...options });
|
const { exitCode, success, output } = await exec(command, arguments_, { silent: true, listeners, ...options });
|
||||||
showOutput();
|
showOutput();
|
||||||
if (exitCode !== 0) {
|
if (!success) {
|
||||||
throwContextualError(`Command returned non-zero exit code.\nError: ${error}`);
|
throwContextualError(`Command returned non-zero exit code (${exitCode}).\nError: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Todo - remove this after verifying it works as expected
|
||||||
|
const trimmedResult = result.replace(/\n+$/, '');
|
||||||
|
if (!output && trimmedResult) {
|
||||||
|
log.warning('returning result instead of output for backward compatibility');
|
||||||
|
|
||||||
|
return trimmedResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
} catch (inCommandError) {
|
} catch (inCommandError) {
|
||||||
showOutput();
|
showOutput();
|
||||||
throwContextualError(`In-command error caught: ${inCommandError}`);
|
throwContextualError(`In-command error caught: ${inCommandError}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.replace(/\n+$/, '');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { core } from '../dependencies.ts';
|
import { Buffer } from '../dependencies.ts';
|
||||||
import NotImplementedException from './error/not-implemented-exception.ts';
|
import NotImplementedException from './error/not-implemented-exception.ts';
|
||||||
import ValidationError from './error/validation-error.ts';
|
import ValidationError from './error/validation-error.ts';
|
||||||
import Input from './input.ts';
|
import Input from './input.ts';
|
||||||
|
|
@ -62,10 +62,9 @@ export default class Versioning {
|
||||||
*/
|
*/
|
||||||
static async logDiff() {
|
static async logDiff() {
|
||||||
const diffCommand = `git --no-pager diff | head -n ${this.maxDiffLines.toString()}`;
|
const diffCommand = `git --no-pager diff | head -n ${this.maxDiffLines.toString()}`;
|
||||||
await System.run('sh', undefined, {
|
const result = await System.shellRun(diffCommand);
|
||||||
input: Buffer.from(diffCommand),
|
|
||||||
silent: true,
|
log.debug(result.output);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -129,7 +128,7 @@ export default class Versioning {
|
||||||
await this.fetch();
|
await this.fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.logDiff();
|
await Versioning.logDiff();
|
||||||
|
|
||||||
if ((await this.isDirty()) && !this.isDirtyAllowed) {
|
if ((await this.isDirty()) && !this.isDirtyAllowed) {
|
||||||
throw new Error('Branch is dirty. Refusing to base semantic version on uncommitted changes');
|
throw new Error('Branch is dirty. Refusing to base semantic version on uncommitted changes');
|
||||||
|
|
@ -226,7 +225,7 @@ export default class Versioning {
|
||||||
static async isShallow() {
|
static async isShallow() {
|
||||||
const output = await this.git(['rev-parse', '--is-shallow-repository']);
|
const output = await this.git(['rev-parse', '--is-shallow-repository']);
|
||||||
|
|
||||||
return output !== 'false\n';
|
return output !== 'false';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -240,9 +239,7 @@ export default class Versioning {
|
||||||
try {
|
try {
|
||||||
await this.git(['fetch', '--unshallow']);
|
await this.git(['fetch', '--unshallow']);
|
||||||
} catch {
|
} catch {
|
||||||
log.warning(
|
log.warning(`fetch --unshallow did not work, falling back to regular fetch`);
|
||||||
`fetch --unshallow did not work, falling back to regular fetch (which probably just means it's not running on GH actions)`,
|
|
||||||
);
|
|
||||||
await this.git(['fetch']);
|
await this.git(['fetch']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -267,8 +264,10 @@ export default class Versioning {
|
||||||
const isDirty = output !== '';
|
const isDirty = output !== '';
|
||||||
|
|
||||||
if (isDirty) {
|
if (isDirty) {
|
||||||
log.warning('Changes were made to the following files and folders:\n');
|
log.warning(
|
||||||
log.warning(output);
|
`Changes were made to the following files and folders:\n\n A = addition, M = modification, D = deletion\n\n`,
|
||||||
|
output,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isDirty;
|
return isDirty;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ const exec = async (
|
||||||
continueOnError: false,
|
continueOnError: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// log.debug('Command:', command, args);
|
||||||
|
|
||||||
const { silent = false, ignoreReturnCode } = ghActionsOptions;
|
const { silent = false, ignoreReturnCode } = ghActionsOptions;
|
||||||
if (silent) options.output = OutputMode.Capture;
|
if (silent) options.output = OutputMode.Capture;
|
||||||
if (ignoreReturnCode) options.continueOnError = true;
|
if (ignoreReturnCode) options.continueOnError = true;
|
||||||
|
|
@ -53,7 +55,7 @@ const exec = async (
|
||||||
const symbol = success ? '✅' : '❗';
|
const symbol = success ? '✅' : '❗';
|
||||||
log.debug('Command:', command, argsString, symbol, result);
|
log.debug('Command:', command, argsString, symbol, result);
|
||||||
|
|
||||||
return { exitCode, success, output: output.trim() };
|
return { exitCode, success, output: output.replace(/\n+$/, '') };
|
||||||
};
|
};
|
||||||
|
|
||||||
export { exec };
|
export { exec };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue