3
0
Fork 0
mirror of https://gitea.com/docker/metadata-action.git synced 2024-11-25 13:39:33 +01:00

handle comments for multi-line inputs

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-03-07 07:37:59 +01:00
parent f3c886e26b
commit 1068b75f65
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
4 changed files with 25 additions and 17 deletions

View file

@ -359,7 +359,7 @@ tags: |
Will be used on [schedule event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule). Will be used on [schedule event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule).
`pattern` is a specially crafted attribute to support [Handlebars template](https://handlebarsjs.com/guide/) with `pattern` is a specially crafted attribute to support [Handlebars' template](https://handlebarsjs.com/guide/) with
the following expressions: the following expressions:
* `date 'format'` ; render date by its [moment format](https://momentjs.com/docs/#/displaying/format/) * `date 'format'` ; render date by its [moment format](https://momentjs.com/docs/#/displaying/format/)
@ -478,7 +478,7 @@ tags: |
``` ```
Can create a regular expression for matching Git tag with a pattern and capturing group. Will be used on a Can create a regular expression for matching Git tag with a pattern and capturing group. Will be used on a
[push tag event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push) but you can also use [push tag event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push) but, you can also use
a custom value through `value` attribute. a custom value through `value` attribute.
| Git tag | Pattern | Group | Output | | Git tag | Pattern | Group | Output |
@ -615,7 +615,7 @@ tags: |
### Global expressions ### Global expressions
The following [Handlebars template](https://handlebarsjs.com/guide/) expressions for `prefix`, `suffix` and `value` The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions for `prefix`, `suffix` and `value`
attributes are available: attributes are available:
| Expression | Output | | Expression | Output |
@ -679,7 +679,7 @@ workflow using the [`fromJSON` function](https://docs.github.com/en/actions/lear
### Overwrite labels ### Overwrite labels
If some of the [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md) If some [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)
labels generated are not suitable, you can overwrite them like this: labels generated are not suitable, you can overwrite them like this:
```yaml ```yaml

View file

@ -15,55 +15,61 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
describe('getInputList', () => { 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 = context.getInputList('foo');
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 = context.getInputList('foo');
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 = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']); expect(res).toEqual(['bar', 'baz']);
}); });
it('comment correctly', async () => {
setInput('foo', 'bar\n#com\n"#taken"\nhello#comment\nbaz');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', '#taken', 'hello', '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 = context.getInputList('foo');
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 = context.getInputList('foo');
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 = context.getInputList('foo');
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 = context.getInputList('foo');
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 = context.getInputList('cache-from', true);
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 = context.getInputList('cache-from', true);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']); expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
}); });
@ -76,7 +82,7 @@ bbbbbbb
ccccccccc" ccccccccc"
FOO=bar` FOO=bar`
); );
const res = await context.getInputList('secrets', true); const res = context.getInputList('secrets', true);
expect(res).toEqual([ expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa `MYSECRET=aaaaaaaa
@ -99,7 +105,7 @@ FOO=bar
bbbb bbbb
ccc"` ccc"`
); );
const res = await context.getInputList('secrets', true); const res = context.getInputList('secrets', true);
expect(res).toEqual([ expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa `MYSECRET=aaaaaaaa
@ -122,7 +128,7 @@ bbbbbbb
ccccccccc ccccccccc
FOO=bar` FOO=bar`
); );
const res = await context.getInputList('secrets', true); const res = context.getInputList('secrets', true);
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']);
}); });
@ -135,7 +141,7 @@ bbbb""bbb
ccccccccc" ccccccccc"
FOO=bar` FOO=bar`
); );
const res = await context.getInputList('secrets', true); const res = context.getInputList('secrets', true);
expect(res).toEqual([ expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa `MYSECRET=aaaaaaaa

1
dist/index.js generated vendored
View file

@ -75,6 +75,7 @@ function getInputList(name, ignoreComma) {
for (let output of sync_1.default(items, { for (let output of sync_1.default(items, {
columns: false, columns: false,
relax: true, relax: true,
comment: '#',
relaxColumnCount: true, relaxColumnCount: true,
skipLinesWithEmptyValues: true skipLinesWithEmptyValues: true
})) { })) {

View file

@ -49,6 +49,7 @@ export function getInputList(name: string, ignoreComma?: boolean): string[] {
for (let output of csvparse(items, { for (let output of csvparse(items, {
columns: false, columns: false,
relax: true, relax: true,
comment: '#',
relaxColumnCount: true, relaxColumnCount: true,
skipLinesWithEmptyValues: true skipLinesWithEmptyValues: true
}) as Array<string[]>) { }) as Array<string[]>) {