builder: exists method

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-03-03 14:48:12 +01:00
parent 2090433c0d
commit 32af66cb28
3 changed files with 40 additions and 1 deletions

View File

@@ -14,6 +14,8 @@
* limitations under the License.
*/
import * as core from '@actions/core';
import {Buildx} from './buildx';
import {Exec} from '../exec';
@@ -30,6 +32,29 @@ export class Builder {
this.buildx = opts?.buildx || new Buildx();
}
public async exists(name: string): Promise<boolean> {
const cmd = await this.buildx.getCommand(['inspect', name]);
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(`Builder.exists cmd err: ${res.stderr.trim()}`);
return false;
}
return res.exitCode == 0;
})
.catch(error => {
core.debug(`Builder.exists error: ${error}`);
return false;
});
core.debug(`Builder.exists: ${ok}`);
return ok;
}
public async inspect(name: string): Promise<BuilderInfo> {
const cmd = await this.buildx.getCommand(['inspect', name]);
return await Exec.getExecOutput(cmd.command, cmd.args, {

View File

@@ -76,7 +76,7 @@ export class Buildx {
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.debug(`Buildx.isAvailable cmd err: ${res.stderr}`);
core.debug(`Buildx.isAvailable cmd err: ${res.stderr.trim()}`);
return false;
}
return res.exitCode == 0;