Add label-custom input (#35)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2020-12-23 22:09:38 +01:00
committed by GitHub
parent c48ac80f46
commit 3479bd5aaa
11 changed files with 1671 additions and 68 deletions

View File

@ -1,3 +1,4 @@
import csvparse from 'csv-parse/lib/sync';
import * as core from '@actions/core';
export interface Inputs {
@ -12,6 +13,7 @@ export interface Inputs {
tagSchedule: string;
tagCustom: string[];
tagCustomOnly: boolean;
labelCustom: string[];
sepTags: string;
sepLabels: string;
githubToken: string;
@ -30,21 +32,37 @@ export function getInputs(): Inputs {
tagSchedule: core.getInput('tag-schedule') || 'nightly',
tagCustom: getInputList('tag-custom'),
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
labelCustom: getInputList('label-custom'),
sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`,
githubToken: core.getInput('github-token')
};
}
export function getInputList(name: string): string[] {
export function getInputList(name: string, ignoreComma?: boolean): string[] {
let res: Array<string> = [];
const items = core.getInput(name);
if (items == '') {
return [];
return res;
}
return items
.split(/\r?\n/)
.filter(x => x)
.reduce<string[]>((acc, line) => acc.concat(line.split(',').filter(x => x)).map(pat => pat.trim()), []);
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(','));
}
return res.filter(item => item).map(pat => pat.trim());
}
export const asyncForEach = async (array, callback) => {

View File

@ -1,5 +1,5 @@
import * as handlebars from 'handlebars';
import * as moment from 'moment';
import moment from 'moment';
import * as semver from 'semver';
import {Inputs} from './context';
import * as core from '@actions/core';
@ -130,7 +130,7 @@ export class Meta {
}
public labels(): Array<string> {
return [
let labels: Array<string> = [
`org.opencontainers.image.title=${this.repo.name || ''}`,
`org.opencontainers.image.description=${this.repo.description || ''}`,
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
@ -140,5 +140,7 @@ export class Meta {
`org.opencontainers.image.revision=${this.context.sha || ''}`,
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
];
labels.push(...this.inputs.labelCustom);
return labels;
}
}