mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-23 03:16:09 +08:00
undock: run
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
735c66bebf
commit
0a09638c5b
@ -14,12 +14,33 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
import {describe, expect, it, jest, test} from '@jest/globals';
|
import {describe, expect, it, jest, test} from '@jest/globals';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
|
||||||
import {Exec} from '../../src/exec';
|
import {Exec} from '../../src/exec';
|
||||||
import {Undock} from '../../src/undock/undock';
|
import {Undock} from '../../src/undock/undock';
|
||||||
|
|
||||||
|
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'undock-undock-'));
|
||||||
|
|
||||||
|
describe('run', () => {
|
||||||
|
it('extracts moby/moby-bin:26.1.5', async () => {
|
||||||
|
const undock = new Undock();
|
||||||
|
await expect(
|
||||||
|
(async () => {
|
||||||
|
// prettier-ignore
|
||||||
|
await undock.run({
|
||||||
|
source: 'moby/moby-bin:26.1.5',
|
||||||
|
dist: tmpDir,
|
||||||
|
all: true
|
||||||
|
});
|
||||||
|
})()
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
}, 100000);
|
||||||
|
});
|
||||||
|
|
||||||
describe('isAvailable', () => {
|
describe('isAvailable', () => {
|
||||||
it('checks undock is available', async () => {
|
it('checks undock is available', async () => {
|
||||||
const execSpy = jest.spyOn(Exec, 'getExecOutput');
|
const execSpy = jest.spyOn(Exec, 'getExecOutput');
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import os from 'os';
|
|
||||||
import path from 'path';
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
|
||||||
@ -25,6 +23,20 @@ export interface UndockOpts {
|
|||||||
binPath?: string;
|
binPath?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UndockRunOpts {
|
||||||
|
source: string;
|
||||||
|
dist: string;
|
||||||
|
logLevel?: string;
|
||||||
|
logCaller?: boolean;
|
||||||
|
cacheDir?: string;
|
||||||
|
platform?: string;
|
||||||
|
all?: boolean;
|
||||||
|
include?: Array<string>;
|
||||||
|
insecure?: boolean;
|
||||||
|
rmDist?: boolean;
|
||||||
|
wrap?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export class Undock {
|
export class Undock {
|
||||||
private readonly binPath: string;
|
private readonly binPath: string;
|
||||||
private _version: string;
|
private _version: string;
|
||||||
@ -36,8 +48,47 @@ export class Undock {
|
|||||||
this._versionOnce = false;
|
this._versionOnce = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get cacheDir(): string {
|
public async run(opts: UndockRunOpts): Promise<void> {
|
||||||
return process.env.UNDOCK_CACHE_DIR || path.join(os.homedir(), '.local', 'share', 'undock', 'cache');
|
if (!opts.source) {
|
||||||
|
throw new Error('source is required');
|
||||||
|
}
|
||||||
|
if (!opts.dist) {
|
||||||
|
throw new Error('dist is required');
|
||||||
|
}
|
||||||
|
const args: Array<string> = [];
|
||||||
|
if (opts.logLevel) {
|
||||||
|
args.push(`--log-level=${opts.logLevel}`);
|
||||||
|
}
|
||||||
|
if (opts.logCaller) {
|
||||||
|
args.push('--log-caller');
|
||||||
|
}
|
||||||
|
if (opts.cacheDir) {
|
||||||
|
args.push(`--cachedir=${opts.cacheDir}`);
|
||||||
|
}
|
||||||
|
if (opts.platform) {
|
||||||
|
args.push(`--platform=${opts.platform}`);
|
||||||
|
}
|
||||||
|
if (opts.all) {
|
||||||
|
args.push('--all');
|
||||||
|
}
|
||||||
|
if (opts.include) {
|
||||||
|
opts.include.forEach(i => {
|
||||||
|
args.push(`--include=${i}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (opts.insecure) {
|
||||||
|
args.push('--insecure');
|
||||||
|
}
|
||||||
|
if (opts.rmDist) {
|
||||||
|
args.push('--rm-dist');
|
||||||
|
}
|
||||||
|
if (opts.wrap) {
|
||||||
|
args.push('--wrap');
|
||||||
|
}
|
||||||
|
args.push(opts.source, opts.dist);
|
||||||
|
await Exec.exec(this.binPath, args, {
|
||||||
|
failOnStdErr: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async isAvailable(): Promise<boolean> {
|
public async isAvailable(): Promise<boolean> {
|
||||||
|
Loading…
Reference in New Issue
Block a user