mirror of
https://github.com/docker/metadata-action.git
synced 2026-06-28 14:50:44 +00:00
Merge 96d23fc579 into 020b7354dd
This commit is contained in:
commit
dd5113dd5f
4 changed files with 88 additions and 55 deletions
|
|
@ -76,6 +76,27 @@ describe('isRawStatement', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('global expressions', () => {
|
||||
test('throws for unknown global expression', async () => {
|
||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', 'event_push_master.env')));
|
||||
const toolkit = new Toolkit();
|
||||
const repo = await toolkit.github.repoData();
|
||||
const context = await getContext(ContextSource.workflow, toolkit);
|
||||
|
||||
expect(() => {
|
||||
new Meta(
|
||||
{
|
||||
...getInputs(),
|
||||
images: ['user/app'],
|
||||
tags: [`type=raw,value=latest,enable={{is_prerelease}}`]
|
||||
},
|
||||
context,
|
||||
repo
|
||||
);
|
||||
}).toThrow('{{is_prerelease}} is not a valid global expression');
|
||||
});
|
||||
});
|
||||
|
||||
const tagsLabelsTest = async (name: string, envFile: string, inputs: Inputs, exVersion: Version, exTags: Array<string>, exLabels: Array<string>, exAnnotations: Array<string> | undefined) => {
|
||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||
const toolkit = new Toolkit();
|
||||
|
|
|
|||
100
dist/index.cjs
generated
vendored
100
dist/index.cjs
generated
vendored
File diff suppressed because one or more lines are too long
6
dist/index.cjs.map
generated
vendored
6
dist/index.cjs.map
generated
vendored
File diff suppressed because one or more lines are too long
16
src/meta.ts
16
src/meta.ts
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue