Skip to content

Commit 3f652e7

Browse files
test
1 parent d5fcada commit 3f652e7

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

lib/utils/command.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ const signale_1 = __importDefault(require("signale"));
1515
const child_process_1 = require("child_process");
1616
const misc_1 = require("./misc");
1717
exports.clone = (context) => __awaiter(this, void 0, void 0, function* () {
18-
yield spawnAsync('ls -lat');
18+
yield execAsync('ls -lat');
1919
if (misc_1.isGitCloned())
2020
return;
2121
const workspace = misc_1.getWorkspace();
2222
const url = misc_1.getGitUrl(context);
23-
yield spawnAsync(`git -C ${workspace} clone --depth=1 --branch=master ${url} .`);
24-
yield spawnAsync(`git -C ${workspace} checkout -qf ${context.sha}`);
23+
yield execAsync(`git -C ${workspace} clone --depth=1 --branch=master ${url} .`);
24+
yield execAsync(`git -C ${workspace} checkout -qf ${context.sha}`);
2525
});
2626
exports.runBuild = () => __awaiter(this, void 0, void 0, function* () {
2727
const commands = misc_1.getBuildCommands();
@@ -31,29 +31,23 @@ exports.runBuild = () => __awaiter(this, void 0, void 0, function* () {
3131
const current = process.cwd();
3232
signale_1.default.info('workspace=%s', workspace);
3333
signale_1.default.info('current=%s', current);
34-
yield spawnAsync(`cd ${workspace}`);
34+
yield execAsync(`cd ${workspace}`);
3535
for (const command of commands) {
36-
yield spawnAsync(command);
36+
yield execAsync(command);
3737
}
38-
yield spawnAsync(`cd ${current}`);
38+
yield execAsync(`cd ${current}`);
3939
});
4040
exports.getDiffFiles = () => __awaiter(this, void 0, void 0, function* () {
4141
const workspace = misc_1.getWorkspace();
42-
yield spawnAsync(`git -C ${workspace} add --all`);
43-
yield spawnAsync(`git -C ${workspace} status --short -uno`);
44-
return (yield spawnAsync(`git -C ${workspace} status --short -uno`)).split(/\r\n|\n/).filter(line => line.match(/^[MDA]\s+/)).map(line => line.replace(/^[MDA]\s+/, ''));
42+
yield execAsync(`git -C ${workspace} add --all`);
43+
yield execAsync(`git -C ${workspace} status --short -uno`);
44+
return (yield execAsync(`git -C ${workspace} status --short -uno`)).split(/\r\n|\n/).filter(line => line.match(/^[MDA]\s+/)).map(line => line.replace(/^[MDA]\s+/, ''));
4545
});
46-
const spawnAsync = (command) => new Promise((resolve, reject) => {
46+
const execAsync = (command) => new Promise((resolve, reject) => {
4747
signale_1.default.info(`Run command: ${command}`);
48-
const process = child_process_1.spawn(command);
49-
let output = '';
50-
process.stdout.on('data', data => {
51-
console.log(data);
52-
output += data;
53-
});
54-
process.on('close', code => {
55-
if (code !== 0)
56-
reject(new Error(`command ${command} exited with code ${code}.`));
57-
resolve(output);
48+
child_process_1.exec(command, (error, stdout) => {
49+
if (error)
50+
reject(new Error(`command ${command} exited with code ${error}.`));
51+
resolve(stdout);
5852
});
5953
});

src/utils/command.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import signale from 'signale';
2-
import {spawn} from 'child_process';
2+
import {exec} from 'child_process';
33
import {Context} from '@actions/github/lib/context';
44
import {isGitCloned, getWorkspace, getGitUrl, getBuildCommands} from './misc';
55

66
export const clone = async (context: Context) => {
77
if (isGitCloned()) return;
88
const workspace = getWorkspace();
99
const url = getGitUrl(context);
10-
await spawnAsync(`git -C ${workspace} clone --depth=1 --branch=master ${url} .`);
11-
await spawnAsync(`git -C ${workspace} checkout -qf ${context.sha}`);
10+
await execAsync(`git -C ${workspace} clone --depth=1 --branch=master ${url} .`);
11+
await execAsync(`git -C ${workspace} checkout -qf ${context.sha}`);
1212
};
1313

1414
export const runBuild = async () => {
@@ -19,32 +19,25 @@ export const runBuild = async () => {
1919
const current = process.cwd();
2020
signale.info('workspace=%s', workspace);
2121
signale.info('current=%s', current);
22-
await spawnAsync(`cd ${workspace}`);
22+
await execAsync(`cd ${workspace}`);
2323
for (const command of commands) {
24-
await spawnAsync(command);
24+
await execAsync(command);
2525
}
26-
await spawnAsync(`cd ${current}`);
26+
await execAsync(`cd ${current}`);
2727
};
2828

2929
export const getDiffFiles = async () => {
3030
const workspace = getWorkspace();
31-
await spawnAsync(`git -C ${workspace} add --all`);
32-
await spawnAsync(`git -C ${workspace} status --short -uno`);
33-
return (await spawnAsync(`git -C ${workspace} status --short -uno`)).split(/\r\n|\n/).filter(line => line.match(/^[MDA]\s+/)).map(line => line.replace(/^[MDA]\s+/, ''));
31+
await execAsync(`git -C ${workspace} add --all`);
32+
await execAsync(`git -C ${workspace} status --short -uno`);
33+
return (await execAsync(`git -C ${workspace} status --short -uno`)).split(/\r\n|\n/).filter(line => line.match(/^[MDA]\s+/)).map(line => line.replace(/^[MDA]\s+/, ''));
3434
};
3535

36-
const spawnAsync = (command: string) => new Promise<string>((resolve, reject) => {
36+
const execAsync = (command: string) => new Promise<string>((resolve, reject) => {
3737
signale.info(`Run command: ${command}`);
3838

39-
const process = spawn(command);
40-
let output = '';
41-
process.stdout.on('data', data => {
42-
console.log(data);
43-
output += data;
44-
});
45-
46-
process.on('close', code => {
47-
if (code !== 0) reject(new Error(`command ${command} exited with code ${code}.`));
48-
resolve(output);
39+
exec(command, (error, stdout) => {
40+
if (error) reject(new Error(`command ${command} exited with code ${error}.`));
41+
resolve(stdout);
4942
});
5043
});

0 commit comments

Comments
 (0)