2022-04-25 13:35:08 +02:00
|
|
|
import {parse} from 'csv-parse/sync';
|
2021-04-03 18:15:27 +02:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
|
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) {
|
2022-04-25 13:35:08 +02:00
|
|
|
const fields = parse(input, {
|
2021-07-05 20:37:02 +02:00
|
|
|
relaxColumnCount: true,
|
2022-04-25 13:35:08 +02:00
|
|
|
skipEmptyLines: true
|
2021-07-05 20:37:02 +02:00
|
|
|
})[0];
|
|
|
|
let onlatestfor = '';
|
|
|
|
for (const field of fields) {
|
2021-10-22 13:50:28 +02:00
|
|
|
const parts = field
|
|
|
|
.toString()
|
|
|
|
.split('=')
|
|
|
|
.map(item => item.trim());
|
2021-07-05 20:37:02 +02:00
|
|
|
if (parts.length == 1) {
|
|
|
|
throw new Error(`Invalid flavor entry: ${input}`);
|
2021-03-29 13:04:53 +02:00
|
|
|
}
|
2021-10-22 13:50:28 +02:00
|
|
|
const key = parts[0].toLowerCase();
|
|
|
|
const value = parts[1];
|
|
|
|
switch (key) {
|
2021-07-05 20:37:02 +02:00
|
|
|
case 'latest': {
|
2021-10-22 13:50:28 +02:00
|
|
|
flavor.latest = value;
|
2021-07-05 20:37:02 +02:00
|
|
|
if (!['auto', 'true', 'false'].includes(flavor.latest)) {
|
|
|
|
throw new Error(`Invalid latest flavor entry: ${input}`);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'prefix': {
|
2021-10-22 13:50:28 +02:00
|
|
|
flavor.prefix = value;
|
2021-07-05 20:37:02 +02:00
|
|
|
onlatestfor = 'prefix';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'suffix': {
|
2021-10-22 13:50:28 +02:00
|
|
|
flavor.suffix = value;
|
2021-07-05 20:37:02 +02:00
|
|
|
onlatestfor = 'suffix';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'onlatest': {
|
2021-10-22 13:50:28 +02:00
|
|
|
if (!['true', 'false'].includes(value)) {
|
|
|
|
throw new Error(`Invalid value for onlatest attribute: ${value}`);
|
2021-07-05 20:37:02 +02:00
|
|
|
}
|
|
|
|
switch (onlatestfor) {
|
|
|
|
case 'prefix': {
|
2021-10-22 13:50:28 +02:00
|
|
|
flavor.prefixLatest = /true/i.test(value);
|
2021-07-05 20:37:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'suffix': {
|
2021-10-22 13:50:28 +02:00
|
|
|
flavor.suffixLatest = /true/i.test(value);
|
2021-07-05 20:37:02 +02:00
|
|
|
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;
|
|
|
|
}
|