Skip to content

Commit

Permalink
Merge pull request #53 from crazy-max/docker-io
Browse files Browse the repository at this point in the history
docker: check command using actions/io module
  • Loading branch information
crazy-max committed Feb 21, 2023
2 parents 3d9ec9f + 99487d6 commit 2e59ae7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
10 changes: 4 additions & 6 deletions __tests__/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
});
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 5 additions & 12 deletions src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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> {
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e59ae7

Please sign in to comment.