docker: check command using actions/io module

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-02-21 08:40:27 +01:00
parent 3d9ec9f02d
commit 99487d6986
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
4 changed files with 12 additions and 19 deletions

View File

@ -16,6 +16,7 @@
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
import path from 'path';
import * as io from '@actions/io';
import osm = require('os');
import {Docker} from '../src/docker';
@ -49,13 +50,10 @@ describe('configDir', () => {
describe('isAvailable', () => {
it('cli', async () => {
const execSpy = jest.spyOn(Exec, 'getExecOutput');
const ioWhichSpy = jest.spyOn(io, 'which');
await Docker.isAvailable();
// eslint-disable-next-line jest/no-standalone-expect
expect(execSpy).toHaveBeenCalledWith(`docker`, [], {
silent: true,
ignoreReturnCode: true
});
expect(ioWhichSpy).toHaveBeenCalledTimes(1);
expect(ioWhichSpy).toHaveBeenCalledWith('docker', true);
});
});

View File

@ -46,6 +46,7 @@
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@actions/http-client": "^2.0.1",
"@actions/io": "^1.1.2",
"@actions/tool-cache": "^2.0.1",
"csv-parse": "^5.3.5",
"jwt-decode": "^3.1.2",

View File

@ -17,6 +17,7 @@
import os from 'os';
import path from 'path';
import * as core from '@actions/core';
import * as io from '@actions/io';
import {Exec} from './exec';
export class Docker {
@ -25,24 +26,16 @@ export class Docker {
}
public static async isAvailable(): Promise<boolean> {
const ok: boolean = await Exec.getExecOutput('docker', [], {
ignoreReturnCode: true,
silent: true
})
return await io
.which('docker', true)
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.debug(`Docker.isAvailable cmd err: ${res.stderr}`);
return false;
}
return res.exitCode == 0;
core.debug(`Docker.isAvailable ok: ${res}`);
return true;
})
.catch(error => {
core.debug(`Docker.isAvailable error: ${error}`);
return false;
});
core.debug(`Docker.isAvailable: ${ok}`);
return ok;
}
public static async printVersion(): Promise<void> {

View File

@ -52,7 +52,7 @@ __metadata:
languageName: node
linkType: hard
"@actions/io@npm:^1.1.1":
"@actions/io@npm:^1.1.1, @actions/io@npm:^1.1.2":
version: 1.1.2
resolution: "@actions/io@npm:1.1.2"
checksum: 3c6583c4557abf6c95e9cfc9b6377045e65ba2c5dd4863f4feedd6be9daf4f6b60e588ab0151d5626b5f8320a37f05b8d44ab5c329b8c19f65be31b0616e1464
@ -766,6 +766,7 @@ __metadata:
"@actions/exec": ^1.1.1
"@actions/github": ^5.1.1
"@actions/http-client": ^2.0.1
"@actions/io": ^1.1.2
"@actions/tool-cache": ^2.0.1
"@types/csv-parse": ^1.2.2
"@types/node": ^16.18.11