mirror of
https://github.com/docker/metadata-action.git
synced 2026-01-22 06:28:56 +08:00
Rework latest behavior and handle flavor
This commit is contained in:
parent
63a49e1ec3
commit
e2af761bf7
10 changed files with 366 additions and 87 deletions
24
src/tag.ts
24
src/tag.ts
|
|
@ -1,27 +1,25 @@
|
|||
import csvparse from 'csv-parse/lib/sync';
|
||||
|
||||
export enum Type {
|
||||
Raw = 'raw',
|
||||
Schedule = 'schedule',
|
||||
Semver = 'semver',
|
||||
Match = 'match',
|
||||
Edge = 'edge',
|
||||
Ref = 'ref',
|
||||
Raw = 'raw',
|
||||
Sha = 'sha'
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
type: Type;
|
||||
attrs: Record<string, string>;
|
||||
}
|
||||
|
||||
export enum RefEvent {
|
||||
Branch = 'branch',
|
||||
Tag = 'tag',
|
||||
PR = 'pr'
|
||||
}
|
||||
|
||||
export const RefEvents = Object.keys(RefEvent).map(key => RefEvent[key]);
|
||||
export interface Tag {
|
||||
type: Type;
|
||||
attrs: Record<string, string>;
|
||||
}
|
||||
|
||||
export const DefaultPriorities: Record<Type, string> = {
|
||||
[Type.Schedule]: '1000',
|
||||
|
|
@ -132,7 +130,11 @@ export function Parse(s: string): Tag {
|
|||
if (!tag.attrs.hasOwnProperty('event')) {
|
||||
throw new Error(`Missing event attribute for ${s}`);
|
||||
}
|
||||
if (!RefEvents.includes(tag.attrs['event'])) {
|
||||
if (
|
||||
!Object.keys(RefEvent)
|
||||
.map(k => RefEvent[k])
|
||||
.includes(tag.attrs['event'])
|
||||
) {
|
||||
throw new Error(`Invalid event for ${s}`);
|
||||
}
|
||||
if (tag.attrs['event'] == RefEvent.PR && !tag.attrs.hasOwnProperty('prefix')) {
|
||||
|
|
@ -160,9 +162,6 @@ export function Parse(s: string): Tag {
|
|||
if (!tag.attrs.hasOwnProperty('priority')) {
|
||||
tag.attrs['priority'] = DefaultPriorities[tag.type];
|
||||
}
|
||||
if (!tag.attrs.hasOwnProperty('latest')) {
|
||||
tag.attrs['latest'] = 'auto';
|
||||
}
|
||||
if (!tag.attrs.hasOwnProperty('prefix')) {
|
||||
tag.attrs['prefix'] = '';
|
||||
}
|
||||
|
|
@ -172,9 +171,6 @@ export function Parse(s: string): Tag {
|
|||
if (!['true', 'false'].includes(tag.attrs['enable'])) {
|
||||
throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`);
|
||||
}
|
||||
if (!['auto', 'true', 'false'].includes(tag.attrs['latest'])) {
|
||||
throw new Error(`Invalid value for latest attribute: ${tag.attrs['latest']}`);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue