mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-26 22:26:08 +08:00
Merge pull request #53 from crazy-max/docker-io
docker: check command using actions/io module
This commit is contained in:
commit
2e59ae7030
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
|
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import * as io from '@actions/io';
|
||||||
import osm = require('os');
|
import osm = require('os');
|
||||||
|
|
||||||
import {Docker} from '../src/docker';
|
import {Docker} from '../src/docker';
|
||||||
@ -49,13 +50,10 @@ describe('configDir', () => {
|
|||||||
|
|
||||||
describe('isAvailable', () => {
|
describe('isAvailable', () => {
|
||||||
it('cli', async () => {
|
it('cli', async () => {
|
||||||
const execSpy = jest.spyOn(Exec, 'getExecOutput');
|
const ioWhichSpy = jest.spyOn(io, 'which');
|
||||||
await Docker.isAvailable();
|
await Docker.isAvailable();
|
||||||
// eslint-disable-next-line jest/no-standalone-expect
|
expect(ioWhichSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(execSpy).toHaveBeenCalledWith(`docker`, [], {
|
expect(ioWhichSpy).toHaveBeenCalledWith('docker', true);
|
||||||
silent: true,
|
|
||||||
ignoreReturnCode: true
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/github": "^5.1.1",
|
"@actions/github": "^5.1.1",
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
|
"@actions/io": "^1.1.2",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"csv-parse": "^5.3.5",
|
"csv-parse": "^5.3.5",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import * as io from '@actions/io';
|
||||||
import {Exec} from './exec';
|
import {Exec} from './exec';
|
||||||
|
|
||||||
export class Docker {
|
export class Docker {
|
||||||
@ -25,24 +26,16 @@ export class Docker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async isAvailable(): Promise<boolean> {
|
public static async isAvailable(): Promise<boolean> {
|
||||||
const ok: boolean = await Exec.getExecOutput('docker', [], {
|
return await io
|
||||||
ignoreReturnCode: true,
|
.which('docker', true)
|
||||||
silent: true
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
core.debug(`Docker.isAvailable ok: ${res}`);
|
||||||
core.debug(`Docker.isAvailable cmd err: ${res.stderr}`);
|
return true;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return res.exitCode == 0;
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
core.debug(`Docker.isAvailable error: ${error}`);
|
core.debug(`Docker.isAvailable error: ${error}`);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
core.debug(`Docker.isAvailable: ${ok}`);
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async printVersion(): Promise<void> {
|
public static async printVersion(): Promise<void> {
|
||||||
|
@ -52,7 +52,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@actions/io@npm:^1.1.1":
|
"@actions/io@npm:^1.1.1, @actions/io@npm:^1.1.2":
|
||||||
version: 1.1.2
|
version: 1.1.2
|
||||||
resolution: "@actions/io@npm:1.1.2"
|
resolution: "@actions/io@npm:1.1.2"
|
||||||
checksum: 3c6583c4557abf6c95e9cfc9b6377045e65ba2c5dd4863f4feedd6be9daf4f6b60e588ab0151d5626b5f8320a37f05b8d44ab5c329b8c19f65be31b0616e1464
|
checksum: 3c6583c4557abf6c95e9cfc9b6377045e65ba2c5dd4863f4feedd6be9daf4f6b60e588ab0151d5626b5f8320a37f05b8d44ab5c329b8c19f65be31b0616e1464
|
||||||
@ -766,6 +766,7 @@ __metadata:
|
|||||||
"@actions/exec": ^1.1.1
|
"@actions/exec": ^1.1.1
|
||||||
"@actions/github": ^5.1.1
|
"@actions/github": ^5.1.1
|
||||||
"@actions/http-client": ^2.0.1
|
"@actions/http-client": ^2.0.1
|
||||||
|
"@actions/io": ^1.1.2
|
||||||
"@actions/tool-cache": ^2.0.1
|
"@actions/tool-cache": ^2.0.1
|
||||||
"@types/csv-parse": ^1.2.2
|
"@types/csv-parse": ^1.2.2
|
||||||
"@types/node": ^16.18.11
|
"@types/node": ^16.18.11
|
||||||
|
Loading…
Reference in New Issue
Block a user