13
0
Fork 0
mirror of https://github.com/docker/metadata-action.git synced 2026-07-02 16:19:31 +00:00

report invalid global expressions clearly

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2026-05-22 14:41:37 +02:00
parent 530a407188
commit 7282ab7c69
No known key found for this signature in database
GPG key ID: ADE44D8C9D44FBE4
2 changed files with 35 additions and 2 deletions

View file

@ -400,7 +400,7 @@ export class Meta {
const context = this.context;
const currentDate = this.date;
const commitDate = this.context.commitDate;
return handlebars.compile(val)({
const globalExp = {
branch: function () {
if (!/^refs\/heads\//.test(context.ref)) {
return '';
@ -480,7 +480,19 @@ export class Meta {
});
return m.tz(tz).format(format);
}
});
};
const expressions = Object.keys(globalExp);
const template = handlebars.parseWithoutProcessing(val);
for (const node of template.body) {
const statement = node as {type: string; path?: {type: string; original: string}};
if (statement.type !== 'MustacheStatement' || statement.path?.type !== 'PathExpression') {
continue;
}
if (!expressions.includes(statement.path.original)) {
throw new Error(`{{${statement.path.original}}} is not a valid global expression`);
}
}
return handlebars.compile(val)(globalExp);
}
private getImageNames(): Array<string> {