2020-12-23 21:09:38 +00:00
|
|
|
import csvparse from 'csv-parse/lib/sync';
|
2020-10-25 01:25:23 +00:00
|
|
|
import * as core from '@actions/core';
|
2020-12-24 03:13:41 +00:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as os from 'os';
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
let _tmpDir: string;
|
2020-10-25 01:25:23 +00:00
|
|
|
|
|
|
|
export interface Inputs {
|
|
|
|
images: string[];
|
|
|
|
tagSha: boolean;
|
2020-10-25 14:32:14 +00:00
|
|
|
tagEdge: boolean;
|
|
|
|
tagEdgeBranch: string;
|
2020-11-17 22:31:03 +00:00
|
|
|
tagSemver: string[];
|
2020-10-26 23:57:32 +00:00
|
|
|
tagMatch: string;
|
2020-10-27 01:32:26 +00:00
|
|
|
tagMatchGroup: number;
|
2020-12-01 05:29:34 +00:00
|
|
|
tagLatest: boolean;
|
2020-10-25 14:13:43 +00:00
|
|
|
tagSchedule: string;
|
2020-12-04 17:12:39 +00:00
|
|
|
tagCustom: string[];
|
|
|
|
tagCustomOnly: boolean;
|
2020-12-23 21:09:38 +00:00
|
|
|
labelCustom: string[];
|
2020-10-25 01:25:23 +00:00
|
|
|
sepTags: string;
|
|
|
|
sepLabels: string;
|
|
|
|
githubToken: string;
|
|
|
|
}
|
|
|
|
|
2020-12-24 03:13:41 +00:00
|
|
|
export function tmpDir(): string {
|
|
|
|
if (!_tmpDir) {
|
|
|
|
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-docker-meta-')).split(path.sep).join(path.posix.sep);
|
|
|
|
}
|
|
|
|
return _tmpDir;
|
|
|
|
}
|
|
|
|
|
2020-10-25 01:25:23 +00:00
|
|
|
export function getInputs(): Inputs {
|
|
|
|
return {
|
|
|
|
images: getInputList('images'),
|
2020-10-25 14:32:14 +00:00
|
|
|
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
|
|
|
|
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
|
|
|
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
2020-11-17 22:31:03 +00:00
|
|
|
tagSemver: getInputList('tag-semver'),
|
2020-10-26 23:57:32 +00:00
|
|
|
tagMatch: core.getInput('tag-match'),
|
2020-10-27 01:32:26 +00:00
|
|
|
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
2020-12-01 05:29:34 +00:00
|
|
|
tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
|
2020-10-25 14:13:43 +00:00
|
|
|
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
2020-12-04 17:12:39 +00:00
|
|
|
tagCustom: getInputList('tag-custom'),
|
|
|
|
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
|
2021-03-19 08:55:45 +00:00
|
|
|
labelCustom: getInputList('label-custom', true),
|
2020-10-25 01:25:23 +00:00
|
|
|
sepTags: core.getInput('sep-tags') || `\n`,
|
|
|
|
sepLabels: core.getInput('sep-labels') || `\n`,
|
|
|
|
githubToken: core.getInput('github-token')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-23 21:09:38 +00:00
|
|
|
export function getInputList(name: string, ignoreComma?: boolean): string[] {
|
|
|
|
let res: Array<string> = [];
|
|
|
|
|
2020-10-25 01:25:23 +00:00
|
|
|
const items = core.getInput(name);
|
|
|
|
if (items == '') {
|
2020-12-23 21:09:38 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let output of csvparse(items, {
|
|
|
|
columns: false,
|
|
|
|
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 01:25:23 +00:00
|
|
|
}
|
2020-12-23 21:09:38 +00:00
|
|
|
|
|
|
|
return res.filter(item => item).map(pat => pat.trim());
|
2020-10-25 01:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const asyncForEach = async (array, callback) => {
|
|
|
|
for (let index = 0; index < array.length; index++) {
|
|
|
|
await callback(array[index], index, array);
|
|
|
|
}
|
|
|
|
};
|