Skip to content

Commit

Permalink
Merge pull request #172 from crazy-max/comments
Browse files Browse the repository at this point in the history
handle comments for multi-line inputs
  • Loading branch information
crazy-max committed Mar 8, 2022
2 parents f3476d2 + 1068b75 commit 47c3651
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -359,7 +359,7 @@ tags: |
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:
* `date 'format'` ; render date by its [moment format](https://momentjs.com/docs/#/displaying/format/)
Expand Down Expand Up @@ -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
[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.
| Git tag | Pattern | Group | Output |
Expand Down Expand Up @@ -615,7 +615,7 @@ tags: |
### 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:
| Expression | Output |
Expand Down Expand Up @@ -679,7 +679,7 @@ workflow using the [`fromJSON` function](https://docs.github.com/en/actions/lear
### 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:
```yaml
Expand Down
32 changes: 19 additions & 13 deletions __tests__/context.test.ts
Expand Up @@ -15,55 +15,61 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
describe('getInputList', () => {
it('single line correctly', async () => {
await setInput('foo', 'bar');
const res = await context.getInputList('foo');
const res = context.getInputList('foo');
expect(res).toEqual(['bar']);
});

it('multiline correctly', async () => {
setInput('foo', 'bar\nbaz');
const res = await context.getInputList('foo');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('empty lines correctly', async () => {
setInput('foo', 'bar\n\nbaz');
const res = await context.getInputList('foo');
const res = context.getInputList('foo');
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 () => {
setInput('foo', 'bar,baz');
const res = await context.getInputList('foo');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('empty result correctly', async () => {
setInput('foo', 'bar,baz,');
const res = await context.getInputList('foo');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('different new lines correctly', async () => {
setInput('foo', 'bar\r\nbaz');
const res = await context.getInputList('foo');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('different new lines and comma correctly', async () => {
setInput('foo', 'bar\r\nbaz,bat');
const res = await context.getInputList('foo');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz', 'bat']);
});

it('multiline and ignoring comma correctly', async () => {
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']);
});

it('different new lines and ignoring comma correctly', async () => {
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']);
});

Expand All @@ -76,7 +82,7 @@ bbbbbbb
ccccccccc"
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
Expand All @@ -99,7 +105,7 @@ FOO=bar
bbbb
ccc"`
);
const res = await context.getInputList('secrets', true);
const res = context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
Expand All @@ -122,7 +128,7 @@ bbbbbbb
ccccccccc
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']);
});

Expand All @@ -135,7 +141,7 @@ bbbb""bbb
ccccccccc"
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
Expand Down
1 change: 1 addition & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/context.ts
Expand Up @@ -49,6 +49,7 @@ export function getInputList(name: string, ignoreComma?: boolean): string[] {
for (let output of csvparse(items, {
columns: false,
relax: true,
comment: '#',
relaxColumnCount: true,
skipLinesWithEmptyValues: true
}) as Array<string[]>) {
Expand Down

0 comments on commit 47c3651

Please sign in to comment.