2021-07-02 13:02:22 +08:00
|
|
|
import fs from 'fs';
|
2020-09-03 22:23:15 +08:00
|
|
|
import * as os from 'os';
|
2021-07-02 13:02:22 +08:00
|
|
|
import path from 'path';
|
2021-09-04 04:21:20 +08:00
|
|
|
import * as tmp from 'tmp';
|
2020-09-03 22:23:15 +08:00
|
|
|
import * as core from '@actions/core';
|
2021-04-24 00:14:38 +08:00
|
|
|
import {issueCommand} from '@actions/core/lib/command';
|
2020-09-03 22:23:15 +08:00
|
|
|
|
2021-07-02 13:02:22 +08:00
|
|
|
let _tmpDir: string;
|
2020-09-03 22:23:15 +08:00
|
|
|
export const osPlat: string = os.platform();
|
2020-09-05 22:30:41 +08:00
|
|
|
export const osArch: string = os.arch();
|
2020-09-03 22:23:15 +08:00
|
|
|
|
2021-07-02 13:02:22 +08:00
|
|
|
export function tmpDir(): string {
|
|
|
|
if (!_tmpDir) {
|
|
|
|
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-setup-buildx-')).split(path.sep).join(path.posix.sep);
|
|
|
|
}
|
|
|
|
return _tmpDir;
|
|
|
|
}
|
|
|
|
|
2021-09-04 04:21:20 +08:00
|
|
|
export function tmpNameSync(options?: tmp.TmpNameOptions): string {
|
|
|
|
return tmp.tmpNameSync(options);
|
|
|
|
}
|
|
|
|
|
2020-09-03 22:23:15 +08:00
|
|
|
export interface Inputs {
|
|
|
|
version: string;
|
|
|
|
driver: string;
|
|
|
|
driverOpts: string[];
|
|
|
|
buildkitdFlags: string;
|
|
|
|
install: boolean;
|
|
|
|
use: boolean;
|
2020-09-08 21:52:09 +08:00
|
|
|
endpoint: string;
|
2021-04-22 01:37:54 +08:00
|
|
|
config: string;
|
2021-09-04 04:21:20 +08:00
|
|
|
configInline: string;
|
2020-09-03 22:23:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getInputs(): Promise<Inputs> {
|
|
|
|
return {
|
|
|
|
version: core.getInput('version'),
|
|
|
|
driver: core.getInput('driver') || 'docker-container',
|
|
|
|
driverOpts: await getInputList('driver-opts', true),
|
2021-07-02 13:02:22 +08:00
|
|
|
buildkitdFlags: core.getInput('buildkitd-flags') || '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
|
2021-06-23 21:43:25 +08:00
|
|
|
install: core.getBooleanInput('install'),
|
|
|
|
use: core.getBooleanInput('use'),
|
2021-04-22 01:37:54 +08:00
|
|
|
endpoint: core.getInput('endpoint'),
|
2021-09-04 04:21:20 +08:00
|
|
|
config: core.getInput('config'),
|
|
|
|
configInline: core.getInput('config-inline')
|
2020-09-03 22:23:15 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getInputList(name: string, ignoreComma?: boolean): Promise<string[]> {
|
|
|
|
const items = core.getInput(name);
|
|
|
|
if (items == '') {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return items
|
|
|
|
.split(/\r?\n/)
|
2020-09-13 05:34:53 +08:00
|
|
|
.filter(x => x)
|
2021-07-02 13:02:22 +08:00
|
|
|
.reduce<string[]>((acc, line) => acc.concat(!ignoreComma ? line.split(',').filter(x => x) : line).map(pat => pat.trim()), []);
|
2020-09-03 22:23:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const asyncForEach = async (array, callback) => {
|
|
|
|
for (let index = 0; index < array.length; index++) {
|
|
|
|
await callback(array[index], index, array);
|
|
|
|
}
|
|
|
|
};
|
2021-04-24 00:14:38 +08:00
|
|
|
|
|
|
|
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
|
2022-03-21 20:43:41 +08:00
|
|
|
export function setOutput(name: string, value: unknown): void {
|
2021-04-24 00:14:38 +08:00
|
|
|
issueCommand('set-output', {name}, value);
|
|
|
|
}
|