mirror of
https://github.com/docker/metadata-action.git
synced 2025-06-24 03:37:59 +02:00
Add format attribute for type=sha
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@ -224,7 +224,13 @@ export class Meta {
|
||||
if (!this.context.sha) {
|
||||
return version;
|
||||
}
|
||||
const vraw = this.setValue(this.context.sha.substr(0, 7), tag);
|
||||
|
||||
let val = this.context.sha;
|
||||
if (tag.attrs['format'] === tcl.ShaFormat.Short) {
|
||||
val = this.context.sha.substr(0, 7);
|
||||
}
|
||||
|
||||
const vraw = this.setValue(val, tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
|
15
src/tag.ts
15
src/tag.ts
@ -17,6 +17,11 @@ export enum RefEvent {
|
||||
PR = 'pr'
|
||||
}
|
||||
|
||||
export enum ShaFormat {
|
||||
Short = 'short',
|
||||
Long = 'long'
|
||||
}
|
||||
|
||||
export class Tag {
|
||||
public type?: Type;
|
||||
public attrs: Record<string, string>;
|
||||
@ -175,6 +180,16 @@ export function Parse(s: string): Tag {
|
||||
if (!tag.attrs.hasOwnProperty('prefix')) {
|
||||
tag.attrs['prefix'] = 'sha-';
|
||||
}
|
||||
if (!tag.attrs.hasOwnProperty('format')) {
|
||||
tag.attrs['format'] = ShaFormat.Short;
|
||||
}
|
||||
if (
|
||||
!Object.keys(ShaFormat)
|
||||
.map(k => ShaFormat[k])
|
||||
.includes(tag.attrs['format'])
|
||||
) {
|
||||
throw new Error(`Invalid format for ${s}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user