Compare commits
4 Commits
v0.1.0-bet
...
v0.1.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e59ae7030 | ||
|
|
99487d6986 | ||
|
|
3d9ec9f02d | ||
|
|
f2b1224b00 |
@@ -39,7 +39,7 @@ $ npm install @docker/actions-toolkit
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { Toolkit } = require('@docker/actions-toolkit')
|
const { Toolkit } = require('@docker/actions-toolkit/lib/toolkit')
|
||||||
const toolkit = new Toolkit()
|
const toolkit = new Toolkit()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ module.exports = {
|
|||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
||||||
},
|
},
|
||||||
collectCoverageFrom: ['src/**/{!(toolkit.ts),}.ts'],
|
collectCoverageFrom: ['src/**/{!(index.ts),}.ts'],
|
||||||
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
|
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
|
||||||
verbose: true
|
verbose: true
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,8 +28,8 @@
|
|||||||
"author": "Docker Inc.",
|
"author": "Docker Inc.",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"packageManager": "yarn@3.3.1",
|
"packageManager": "yarn@3.3.1",
|
||||||
"main": "lib/toolkit.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/toolkit.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib",
|
"lib": "lib",
|
||||||
"test": "__tests__"
|
"test": "__tests__"
|
||||||
@@ -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> {
|
||||||
|
|||||||
42
src/index.ts
Normal file
42
src/index.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2023 actions-toolkit authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
|
const isPost = !!process.env['STATE_isPost'];
|
||||||
|
if (!isPost) {
|
||||||
|
core.saveState('isPost', 'true');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a GitHub Action.
|
||||||
|
* Output will be streamed to the live console.
|
||||||
|
*
|
||||||
|
* @param main runs the defined function.
|
||||||
|
* @param post runs the defined function at the end of the job if set.
|
||||||
|
* @returns Promise<void>
|
||||||
|
*/
|
||||||
|
export async function run(main: () => Promise<void>, post?: () => Promise<void>): Promise<void> {
|
||||||
|
if (!isPost) {
|
||||||
|
try {
|
||||||
|
await main();
|
||||||
|
} catch (e) {
|
||||||
|
core.setFailed(e.message);
|
||||||
|
}
|
||||||
|
} else if (post) {
|
||||||
|
await post();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user