2020-12-23 22:09:38 +01:00
|
|
|
import csvparse from 'csv-parse/lib/sync';
|
2020-10-25 02:25:23 +01:00
|
|
|
import * as core from '@actions/core';
|
2021-04-24 00:44:38 +02:00
|
|
|
import {issueCommand} from '@actions/core/lib/command';
|
2020-12-24 04:13:41 +01:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as os from 'os';
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
let _tmpDir: string;
|
2020-10-25 02:25:23 +01:00
|
|
|
|
|
|
|
export interface Inputs {
|
|
|
|
images: string[];
|
2021-03-29 13:04:53 +02:00
|
|
|
tags: string[];
|
|
|
|
flavor: string[];
|
|
|
|
labels: string[];
|
2020-10-25 02:25:23 +01:00
|
|
|
sepTags: string;
|
|
|
|
sepLabels: string;
|
2021-04-30 00:51:48 +02:00
|
|
|
bakeTarget: string;
|
2020-10-25 02:25:23 +01:00
|
|
|
githubToken: string;
|
|
|
|
}
|
|
|
|
|
2020-12-24 04:13:41 +01:00
|
|
|
export function tmpDir(): string {
|
|
|
|
if (!_tmpDir) {
|
2021-05-10 15:54:35 +02:00
|
|
|
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-')).split(path.sep).join(path.posix.sep);
|
2020-12-24 04:13:41 +01:00
|
|
|
}
|
|
|
|
return _tmpDir;
|
|
|
|
}
|
|
|
|
|
2020-10-25 02:25:23 +01:00
|
|
|
export function getInputs(): Inputs {
|
|
|
|
return {
|
|
|
|
images: getInputList('images'),
|
2021-03-29 13:04:53 +02:00
|
|
|
tags: getInputList('tags', true),
|
|
|
|
flavor: getInputList('flavor', true),
|
|
|
|
labels: getInputList('labels', true),
|
2020-10-25 02:25:23 +01:00
|
|
|
sepTags: core.getInput('sep-tags') || `\n`,
|
|
|
|
sepLabels: core.getInput('sep-labels') || `\n`,
|
2021-05-10 15:54:35 +02:00
|
|
|
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
|
2020-10-25 02:25:23 +01:00
|
|
|
githubToken: core.getInput('github-token')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-23 22:09:38 +01:00
|
|
|
export function getInputList(name: string, ignoreComma?: boolean): string[] {
|
|
|
|
let res: Array<string> = [];
|
|
|
|
|
2020-10-25 02:25:23 +01:00
|
|
|
const items = core.getInput(name);
|
|
|
|
if (items == '') {
|
2020-12-23 22:09:38 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let output of csvparse(items, {
|
|
|
|
columns: false,
|
2021-11-29 13:31:50 +01:00
|
|
|
relax: true,
|
2020-12-23 22:09:38 +01:00
|
|
|
relaxColumnCount: true,
|
|
|
|
skipLinesWithEmptyValues: true
|
|
|
|
}) as Array<string[]>) {
|
|
|
|
if (output.length == 1) {
|
|
|
|
res.push(output[0]);
|
|
|
|
continue;
|
|
|
|
} else if (!ignoreComma) {
|
|
|
|
res.push(...output);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
res.push(output.join(','));
|
2020-10-25 02:25:23 +01:00
|
|
|
}
|
2020-12-23 22:09:38 +01:00
|
|
|
|
|
|
|
return res.filter(item => item).map(pat => pat.trim());
|
2020-10-25 02:25:23 +01: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:44: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);
|
|
|
|
}
|