Exec class

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-02-20 09:01:01 +01:00
parent 2915834633
commit 35a8193474
10 changed files with 171 additions and 104 deletions

View File

@@ -14,9 +14,8 @@
* limitations under the License.
*/
import * as exec from '@actions/exec';
import {Buildx} from './buildx';
import {Exec} from '../exec';
import {BuilderInfo, NodeInfo} from '../types/builder';
@@ -33,17 +32,15 @@ export class Builder {
public async inspect(name: string): Promise<BuilderInfo> {
const cmd = await this.buildx.getCommand(['inspect', name]);
return await exec
.getExecOutput(cmd.command, cmd.args, {
ignoreReturnCode: true,
silent: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.trim());
}
return Builder.parseInspect(res.stdout);
});
return await Exec.getExecOutput(cmd.command, cmd.args, {
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.trim());
}
return Builder.parseInspect(res.stdout);
});
}
public static parseInspect(data: string): BuilderInfo {

View File

@@ -17,10 +17,10 @@
import fs from 'fs';
import path from 'path';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as semver from 'semver';
import {Docker} from '../docker';
import {Exec} from '../exec';
import {Inputs} from './inputs';
import {Cert} from '../types/buildx';
@@ -67,11 +67,10 @@ export class Buildx {
public async isAvailable(): Promise<boolean> {
const cmd = await this.getCommand([]);
const ok: boolean = await exec
.getExecOutput(cmd.command, cmd.args, {
ignoreReturnCode: true,
silent: true
})
const ok: boolean = await Exec.getExecOutput(cmd.command, cmd.args, {
ignoreReturnCode: true,
silent: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.debug(`Buildx.isAvailable cmd err: ${res.stderr}`);
@@ -90,7 +89,7 @@ export class Buildx {
public async printInspect(name: string): Promise<void> {
const cmd = await this.getCommand(['inspect', name]);
await exec.exec(cmd.command, cmd.args, {
await Exec.exec(cmd.command, cmd.args, {
failOnStdErr: false
});
}
@@ -99,17 +98,15 @@ export class Buildx {
return (async () => {
if (!this._version) {
const cmd = await this.getCommand(['version']);
this._version = await exec
.getExecOutput(cmd.command, cmd.args, {
ignoreReturnCode: true,
silent: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.trim());
}
return Buildx.parseVersion(res.stdout.trim());
});
this._version = await Exec.getExecOutput(cmd.command, cmd.args, {
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.trim());
}
return Buildx.parseVersion(res.stdout.trim());
});
}
return this._version;
})();
@@ -117,7 +114,7 @@ export class Buildx {
public async printVersion() {
const cmd = await this.getCommand(['version']);
await exec.exec(cmd.command, cmd.args, {
await Exec.exec(cmd.command, cmd.args, {
failOnStdErr: false
});
}

View File

@@ -18,7 +18,6 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as httpm from '@actions/http-client';
import * as tc from '@actions/tool-cache';
import * as semver from 'semver';
@@ -26,6 +25,7 @@ import * as util from 'util';
import {Buildx} from './buildx';
import {Context} from '../context';
import {Exec} from '../exec';
import {Docker} from '../docker';
import {Git} from '../git';
@@ -82,16 +82,14 @@ export class Install {
if (!toolPath) {
const outputDir = path.join(Context.tmpDir(), 'build-cache');
const buildCmd = await this.buildCommand(gitContext, outputDir);
toolPath = await exec
.getExecOutput(buildCmd.command, buildCmd.args, {
ignoreReturnCode: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.warning(res.stderr.trim());
}
return tc.cacheFile(`${outputDir}/buildx`, os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx', 'buildx', vspec);
});
toolPath = await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.warning(res.stderr.trim());
}
return tc.cacheFile(`${outputDir}/buildx`, os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx', 'buildx', vspec);
});
}
return toolPath;