mirror of
https://gitea.com/docker/metadata-action.git
synced 2024-11-25 21:49:33 +01:00
Merge pull request #155 from crazy-max/prerelease-raw
fix: handle raw statement for semver pre-release
This commit is contained in:
commit
6d7c94a41e
7 changed files with 77 additions and 27 deletions
|
@ -16,63 +16,54 @@ describe('getInputList', () => {
|
||||||
it('single line correctly', async () => {
|
it('single line correctly', async () => {
|
||||||
await setInput('foo', 'bar');
|
await setInput('foo', 'bar');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar']);
|
expect(res).toEqual(['bar']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('multiline correctly', async () => {
|
it('multiline correctly', async () => {
|
||||||
setInput('foo', 'bar\nbaz');
|
setInput('foo', 'bar\nbaz');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('empty lines correctly', async () => {
|
it('empty lines correctly', async () => {
|
||||||
setInput('foo', 'bar\n\nbaz');
|
setInput('foo', 'bar\n\nbaz');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('comma correctly', async () => {
|
it('comma correctly', async () => {
|
||||||
setInput('foo', 'bar,baz');
|
setInput('foo', 'bar,baz');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('empty result correctly', async () => {
|
it('empty result correctly', async () => {
|
||||||
setInput('foo', 'bar,baz,');
|
setInput('foo', 'bar,baz,');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('different new lines correctly', async () => {
|
it('different new lines correctly', async () => {
|
||||||
setInput('foo', 'bar\r\nbaz');
|
setInput('foo', 'bar\r\nbaz');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('different new lines and comma correctly', async () => {
|
it('different new lines and comma correctly', async () => {
|
||||||
setInput('foo', 'bar\r\nbaz,bat');
|
setInput('foo', 'bar\r\nbaz,bat');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz', 'bat']);
|
expect(res).toEqual(['bar', 'baz', 'bat']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('multiline and ignoring comma correctly', async () => {
|
it('multiline and ignoring comma correctly', async () => {
|
||||||
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
|
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
|
||||||
const res = await context.getInputList('cache-from', true);
|
const res = await context.getInputList('cache-from', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('different new lines and ignoring comma correctly', async () => {
|
it('different new lines and ignoring comma correctly', async () => {
|
||||||
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
|
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
|
||||||
const res = await context.getInputList('cache-from', true);
|
const res = await context.getInputList('cache-from', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -86,7 +77,6 @@ ccccccccc"
|
||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
|
@ -110,7 +100,6 @@ bbbb
|
||||||
ccc"`
|
ccc"`
|
||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
|
@ -134,7 +123,6 @@ ccccccccc
|
||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -148,7 +136,6 @@ ccccccccc"
|
||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
|
|
|
@ -168,7 +168,6 @@ describe('transform', () => {
|
||||||
])('given %p attributes ', async (inputs: string[], expected: Flavor, invalid: boolean) => {
|
])('given %p attributes ', async (inputs: string[], expected: Flavor, invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
const flavor = Transform(inputs);
|
const flavor = Transform(inputs);
|
||||||
console.log(flavor);
|
|
||||||
expect(flavor).toEqual(expected);
|
expect(flavor).toEqual(expected);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
|
|
|
@ -8,7 +8,6 @@ jest.spyOn(github, 'repo').mockImplementation((): Promise<github.ReposGetRespons
|
||||||
describe('repo', () => {
|
describe('repo', () => {
|
||||||
it('returns GitHub repository', async () => {
|
it('returns GitHub repository', async () => {
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
console.log(repo);
|
|
||||||
expect(repo.name).not.toBeNull();
|
expect(repo.name).not.toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,24 +31,33 @@ beforeEach(() => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isRawStatement', () => {
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
['{{ raw }}.{{ version }}', false],
|
||||||
|
['{{ version }},{{raw }.', false],
|
||||||
|
['{{ raw }}', true],
|
||||||
|
['{{ raw}}', true],
|
||||||
|
['{{raw}}', true],
|
||||||
|
])('given %p pattern ', async (pattern: string, expected: boolean) => {
|
||||||
|
expect(Meta.isRawStatement(pattern)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const tagsLabelsTest = async (name: string, envFile: string, inputs: Inputs, exVersion: Version, exTags: Array<string>, exLabels: Array<string>) => {
|
const tagsLabelsTest = async (name: string, envFile: string, inputs: Inputs, exVersion: Version, exTags: Array<string>, exLabels: Array<string>) => {
|
||||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
const context = github.context();
|
const context = github.context();
|
||||||
console.log(process.env, context);
|
|
||||||
|
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||||
|
|
||||||
const version = meta.version;
|
const version = meta.version;
|
||||||
console.log('version', version);
|
|
||||||
expect(version).toEqual(exVersion);
|
expect(version).toEqual(exVersion);
|
||||||
|
|
||||||
const tags = meta.getTags();
|
const tags = meta.getTags();
|
||||||
console.log('tags', tags);
|
|
||||||
expect(tags).toEqual(exTags);
|
expect(tags).toEqual(exTags);
|
||||||
|
|
||||||
const labels = meta.getLabels();
|
const labels = meta.getLabels();
|
||||||
console.log('labels', labels);
|
|
||||||
expect(labels).toEqual(exLabels);
|
expect(labels).toEqual(exLabels);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1662,6 +1671,35 @@ describe('tag', () => {
|
||||||
"org.opencontainers.image.licenses=MIT"
|
"org.opencontainers.image.licenses=MIT"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'tag31',
|
||||||
|
'event_tag_v2.0.8-beta.67.env',
|
||||||
|
{
|
||||||
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
tags: [
|
||||||
|
`type=semver,pattern={{raw}}`
|
||||||
|
]
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
main: 'v2.0.8-beta.67',
|
||||||
|
partial: [],
|
||||||
|
latest: false
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'org/app:v2.0.8-beta.67',
|
||||||
|
'ghcr.io/user/app:v2.0.8-beta.67'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.title=Hello-World",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.version=v2.0.8-beta.67",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
])('given %p with %p event', tagsLabelsTest);
|
])('given %p with %p event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3152,13 +3190,11 @@ describe('json', () => {
|
||||||
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exJSON: {}) => {
|
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exJSON: {}) => {
|
||||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
const context = github.context();
|
const context = github.context();
|
||||||
console.log(process.env, context);
|
|
||||||
|
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||||
|
|
||||||
const jsonOutput = meta.getJSON();
|
const jsonOutput = meta.getJSON();
|
||||||
console.log('json', jsonOutput);
|
|
||||||
expect(jsonOutput).toEqual(exJSON);
|
expect(jsonOutput).toEqual(exJSON);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3459,13 +3495,11 @@ describe('bake', () => {
|
||||||
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exBakeDefinition: {}) => {
|
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exBakeDefinition: {}) => {
|
||||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
const context = github.context();
|
const context = github.context();
|
||||||
console.log(process.env, context);
|
|
||||||
|
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||||
|
|
||||||
const bakeFile = meta.getBakeFile();
|
const bakeFile = meta.getBakeFile();
|
||||||
console.log('bakeFile', bakeFile, fs.readFileSync(bakeFile, 'utf8'));
|
|
||||||
expect(JSON.parse(fs.readFileSync(bakeFile, 'utf8'))).toEqual(exBakeDefinition);
|
expect(JSON.parse(fs.readFileSync(bakeFile, 'utf8'))).toEqual(exBakeDefinition);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -99,7 +99,6 @@ describe('transform', () => {
|
||||||
])('given %p', async (l: string[], expected: Tag[], invalid: boolean) => {
|
])('given %p', async (l: string[], expected: Tag[], invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
const tags = Transform(l);
|
const tags = Transform(l);
|
||||||
console.log(tags);
|
|
||||||
expect(tags).toEqual(expected);
|
expect(tags).toEqual(expected);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
|
@ -429,7 +428,6 @@ describe('parse', () => {
|
||||||
])('given %p event ', async (s: string, expected: Tag, invalid: boolean) => {
|
])('given %p event ', async (s: string, expected: Tag, invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
const tag = Parse(s);
|
const tag = Parse(s);
|
||||||
console.log(tag);
|
|
||||||
expect(tag).toEqual(expected);
|
expect(tag).toEqual(expected);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
|
|
19
dist/index.js
generated
vendored
19
dist/index.js
generated
vendored
|
@ -526,7 +526,12 @@ class Meta {
|
||||||
includePrerelease: true
|
includePrerelease: true
|
||||||
});
|
});
|
||||||
if (semver.prerelease(vraw)) {
|
if (semver.prerelease(vraw)) {
|
||||||
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
||||||
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||||
|
@ -671,6 +676,18 @@ class Meta {
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
static isRawStatement(pattern) {
|
||||||
|
try {
|
||||||
|
const hp = handlebars.parseWithoutProcessing(pattern);
|
||||||
|
if (hp.body.length == 1 && hp.body[0].type == 'MustacheStatement') {
|
||||||
|
return hp.body[0]['path']['parts'].length == 1 && hp.body[0]['path']['parts'][0] == 'raw';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
setValue(val, tag) {
|
setValue(val, tag) {
|
||||||
if (tag.attrs.hasOwnProperty('prefix')) {
|
if (tag.attrs.hasOwnProperty('prefix')) {
|
||||||
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
||||||
|
|
18
src/meta.ts
18
src/meta.ts
|
@ -143,7 +143,11 @@ export class Meta {
|
||||||
includePrerelease: true
|
includePrerelease: true
|
||||||
});
|
});
|
||||||
if (semver.prerelease(vraw)) {
|
if (semver.prerelease(vraw)) {
|
||||||
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
||||||
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||||
|
} else {
|
||||||
|
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||||
latest = true;
|
latest = true;
|
||||||
|
@ -307,6 +311,18 @@ export class Meta {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static isRawStatement(pattern: string): boolean {
|
||||||
|
try {
|
||||||
|
const hp = handlebars.parseWithoutProcessing(pattern);
|
||||||
|
if (hp.body.length == 1 && hp.body[0].type == 'MustacheStatement') {
|
||||||
|
return hp.body[0]['path']['parts'].length == 1 && hp.body[0]['path']['parts'][0] == 'raw';
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private setValue(val: string, tag: tcl.Tag): string {
|
private setValue(val: string, tag: tcl.Tag): string {
|
||||||
if (tag.attrs.hasOwnProperty('prefix')) {
|
if (tag.attrs.hasOwnProperty('prefix')) {
|
||||||
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
||||||
|
|
Loading…
Reference in a new issue