From 99487d69868c42e793d583352f3b7033fe3a2fd6 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 21 Feb 2023 08:40:27 +0100 Subject: [PATCH] docker: check command using actions/io module Signed-off-by: CrazyMax --- __tests__/docker.test.ts | 10 ++++------ package.json | 1 + src/docker.ts | 17 +++++------------ yarn.lock | 3 ++- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/__tests__/docker.test.ts b/__tests__/docker.test.ts index 416f1a4..81e1ef0 100644 --- a/__tests__/docker.test.ts +++ b/__tests__/docker.test.ts @@ -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); }); }); diff --git a/package.json b/package.json index ceb4e3d..ab40ec6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/docker.ts b/src/docker.ts index 3760735..7faa8e2 100644 --- a/src/docker.ts +++ b/src/docker.ts @@ -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 { - 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 { diff --git a/yarn.lock b/yarn.lock index 3a7ad78..2e18697 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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