Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: check command using actions/io module #53

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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