2021-04-03 18:15:27 +02:00
|
|
|
import * as core from '@actions/core';
|
2021-07-05 20:37:02 +02:00
|
|
|
import csvparse from 'csv-parse/lib/sync';
|
2021-04-03 18:15:27 +02:00
|
|
|
|
2021-03-29 13:04:53 +02:00
|
|
|
export interface Flavor {
|
|
|
|
latest: string;
|
|
|
|
prefix: string;
|
2021-07-05 20:37:02 +02:00
|
|
|
prefixLatest: boolean;
|
2021-03-29 13:04:53 +02:00
|
|
|
suffix: string;
|
2021-07-05 20:37:02 +02:00
|
|
|
suffixLatest: boolean;
|
2021-03-29 13:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function Transform(inputs: string[]): Flavor {
|
|
|
|
const flavor: Flavor = {
|
|
|
|
latest: 'auto',
|
|
|
|
prefix: '',
|
2021-07-05 20:37:02 +02:00
|
|
|
prefixLatest: false,
|
|
|
|
suffix: '',
|
|
|
|
suffixLatest: false
|
2021-03-29 13:04:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const input of inputs) {
|
2021-07-05 20:37:02 +02:00
|
|
|
const fields = csvparse(input, {
|
|
|
|
relaxColumnCount: true,
|
|
|
|
skipLinesWithEmptyValues: true
|
|
|
|
})[0];
|
|
|
|
let onlatestfor = '';
|
|
|
|
for (const field of fields) {
|
|
|
|
const parts = field.toString().split('=', 2);
|
|
|
|
if (parts.length == 1) {
|
|
|
|
throw new Error(`Invalid flavor entry: ${input}`);
|
2021-03-29 13:04:53 +02:00
|
|
|
}
|
2021-07-05 20:37:02 +02:00
|
|
|
switch (parts[0]) {
|
|
|
|
case 'latest': {
|
|
|
|
flavor.latest = parts[1];
|
|
|
|
if (!['auto', 'true', 'false'].includes(flavor.latest)) {
|
|
|
|
throw new Error(`Invalid latest flavor entry: ${input}`);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'prefix': {
|
|
|
|
flavor.prefix = parts[1];
|
|
|
|
onlatestfor = 'prefix';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'suffix': {
|
|
|
|
flavor.suffix = parts[1];
|
|
|
|
onlatestfor = 'suffix';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'onlatest': {
|
|
|
|
if (!['true', 'false'].includes(parts[1])) {
|
|
|
|
throw new Error(`Invalid value for onlatest attribute: ${parts[1]}`);
|
|
|
|
}
|
|
|
|
switch (onlatestfor) {
|
|
|
|
case 'prefix': {
|
|
|
|
flavor.prefixLatest = /true/i.test(parts[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'suffix': {
|
|
|
|
flavor.suffixLatest = /true/i.test(parts[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
throw new Error(`Unknown flavor entry: ${input}`);
|
|
|
|
}
|
2021-03-29 13:04:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 18:15:27 +02:00
|
|
|
core.startGroup(`Processing flavor input`);
|
|
|
|
core.info(`latest=${flavor.latest}`);
|
|
|
|
core.info(`prefix=${flavor.prefix}`);
|
2021-07-05 20:37:02 +02:00
|
|
|
core.info(`prefixLatest=${flavor.prefixLatest}`);
|
2021-04-03 18:15:27 +02:00
|
|
|
core.info(`suffix=${flavor.suffix}`);
|
2021-07-05 20:37:02 +02:00
|
|
|
core.info(`suffixLatest=${flavor.suffixLatest}`);
|
2021-04-03 18:15:27 +02:00
|
|
|
core.endGroup();
|
|
|
|
|
2021-03-29 13:04:53 +02:00
|
|
|
return flavor;
|
|
|
|
}
|