1
0
Files
setup-buildx-action/src/context.ts
T

58 lines
1.6 KiB
TypeScript
Raw Normal View History

import * as os from 'os';
import * as core from '@actions/core';
2021-04-23 18:14:38 +02:00
import {issueCommand} from '@actions/core/lib/command';
export const osPlat: string = os.platform();
export const osArch: string = os.arch();
export interface Inputs {
version: string;
driver: string;
driverOpts: string[];
buildkitdFlags: string;
install: boolean;
use: boolean;
2020-09-08 15:52:09 +02:00
endpoint: string;
2021-04-21 18:37:54 +01:00
config: string;
}
export async function getInputs(): Promise<Inputs> {
return {
version: core.getInput('version'),
driver: core.getInput('driver') || 'docker-container',
driverOpts: await getInputList('driver-opts', true),
2020-09-03 20:38:04 +02:00
buildkitdFlags:
core.getInput('buildkitd-flags') ||
'--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
2021-06-23 15:43:25 +02:00
install: core.getBooleanInput('install'),
use: core.getBooleanInput('use'),
2021-04-21 18:37:54 +01:00
endpoint: core.getInput('endpoint'),
config: core.getInput('config')
};
}
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-12 23:34:53 +02:00
.filter(x => x)
.reduce<string[]>(
(acc, line) => acc.concat(!ignoreComma ? line.split(',').filter(x => x) : line).map(pat => pat.trim()),
[]
);
}
export const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};
2021-04-23 18:14:38 +02:00
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
export function setOutput(name: string, value: any): void {
issueCommand('set-output', {name}, value);
}