2022-04-25 11:35:08 +00:00
|
|
|
import {parse} from 'csv-parse/sync';
|
2020-10-25 01:25:23 +00:00
|
|
|
import * as core from '@actions/core';
|
2021-04-23 22:44:38 +00:00
|
|
|
import {issueCommand} from '@actions/core/lib/command';
|
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[];
|
2021-03-29 11:04:53 +00:00
|
|
|
tags: string[];
|
|
|
|
flavor: string[];
|
|
|
|
labels: string[];
|
2020-10-25 01:25:23 +00:00
|
|
|
sepTags: string;
|
|
|
|
sepLabels: string;
|
2021-04-29 22:51:48 +00:00
|
|
|
bakeTarget: string;
|
2020-10-25 01:25:23 +00:00
|
|
|
githubToken: string;
|
|
|
|
}
|
|
|
|
|
2020-12-24 03:13:41 +00:00
|
|
|
export function tmpDir(): string {
|
|
|
|
if (!_tmpDir) {
|
2021-05-10 13:54:35 +00:00
|
|
|
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-')).split(path.sep).join(path.posix.sep);
|
2020-12-24 03:13:41 +00:00
|
|
|
}
|
|
|
|
return _tmpDir;
|
|
|
|
}
|
|
|
|
|
2020-10-25 01:25:23 +00:00
|
|
|
export function getInputs(): Inputs {
|
|
|
|
return {
|
2022-04-28 07:08:21 +00:00
|
|
|
images: getInputList('images', true),
|
2021-03-29 11:04:53 +00:00
|
|
|
tags: getInputList('tags', true),
|
|
|
|
flavor: getInputList('flavor', true),
|
|
|
|
labels: getInputList('labels', true),
|
2022-10-07 20:45:46 +00:00
|
|
|
sepTags: core.getInput('sep-tags', {trimWhitespace: false}) || `\n`,
|
|
|
|
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
|
2021-05-10 13:54:35 +00:00
|
|
|
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
|
2020-10-25 01:25:23 +00:00
|
|
|
githubToken: core.getInput('github-token')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-23 21:09:38 +00:00
|
|
|
export function getInputList(name: string, ignoreComma?: boolean): string[] {
|
2022-03-22 20:09:00 +00:00
|
|
|
const res: Array<string> = [];
|
2020-12-23 21:09:38 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-25 11:35:08 +00:00
|
|
|
const records = parse(items, {
|
2020-12-23 21:09:38 +00:00
|
|
|
columns: false,
|
2022-04-25 11:35:08 +00:00
|
|
|
relaxQuotes: true,
|
2022-03-07 06:37:59 +00:00
|
|
|
comment: '#',
|
2020-12-23 21:09:38 +00:00
|
|
|
relaxColumnCount: true,
|
2022-04-25 11:35:08 +00:00
|
|
|
skipEmptyLines: true
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const record of records as Array<string[]>) {
|
|
|
|
if (record.length == 1) {
|
|
|
|
res.push(record[0]);
|
2020-12-23 21:09:38 +00:00
|
|
|
continue;
|
|
|
|
} else if (!ignoreComma) {
|
2022-04-25 11:35:08 +00:00
|
|
|
res.push(...record);
|
2020-12-23 21:09:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-04-25 11:35:08 +00:00
|
|
|
res.push(record.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);
|
|
|
|
}
|
|
|
|
};
|
2021-04-23 22:44:38 +00:00
|
|
|
|
|
|
|
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
|
2022-03-22 20:09:00 +00:00
|
|
|
export function setOutput(name: string, value: unknown): void {
|
2021-04-23 22:44:38 +00:00
|
|
|
issueCommand('set-output', {name}, value);
|
|
|
|
}
|