Skip to content

Commit

Permalink
refactor: change template var delimiters
Browse files Browse the repository at this point in the history
The current template var format `${{...}}` clashes with that used by
GitHub Actions, which makes usage unwieldy. Currently users need to
escape the `${{FILE_NAME}}` template in order to avoid it being
interpreted as a GHA template, so usage looks like:
```yaml
check_title_template: ${{ '${{FILE_NAME}}' }}
```

This commit changes the template format to `{{..}}`, so usage looks
like:
```yaml
check_title_template: '{{FILE_NAME}}'
```

This is a non-breaking change, as currently the input which makes use of
template vars isn't exposed via the action.yml file.
  • Loading branch information
MIJOTHY committed Apr 27, 2022
1 parent 0cbde44 commit 22870cf
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
| `fail_on_failure` | Optional. Fail the build in case of a test failure. |
| `require_tests` | Optional. Fail if no test are found.. |
| `check_retries` | Optional. If a testcase is retried, ignore the original failure. |
| `check_title_template` | Optional. Template to configure the title format. Placeholders: ${{FILE_NAME}}, ${{SUITE_NAME}}, ${{TEST_NAME}}. |
| `check_title_template` | Optional. Template to configure the title format. Placeholders: {{FILE_NAME}}, {{SUITE_NAME}}, {{TEST_NAME}}. |
| `summary` | Optional. Additional text to summary output |
| `update_check` | Optional. Uses an alternative API to update checks, use for cases with more than 50 annotations. |
| `annotate_only` | Optional. Will only annotate the results on the files, won't create a check run. |
Expand Down
2 changes: 1 addition & 1 deletion __tests__/testParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ action.surefire.report.email.InvalidEmailAddressException: Invalid email address
});

it('parse mocha test case, custom title template', async () => {
const { count, skipped, annotations } = await parseFile('test_results/mocha/mocha.xml', '*', true, false, ['/build/', '/__pycache__/'], '${{TEST_NAME}}');
const { count, skipped, annotations } = await parseFile('test_results/mocha/mocha.xml', '*', true, false, ['/build/', '/__pycache__/'], '{{TEST_NAME}}');

expect(count).toBe(1);
expect(skipped).toBe(0);
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inputs:
default: 'false'
check_title_template:
description: |-
Template to configure the title format. Placeholders: ${{ '${{FILE_NAME}}, ${{SUITE_NAME}}, ${{TEST_NAME}}' }}.
Template to configure the title format. Placeholders: {{FILE_NAME}}, {{SUITE_NAME}}, {{TEST_NAME}}.
required: false
summary:
description: 'Additional text to summary output'
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/testParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export async function parseFile(
)
}

function templateVar(varName: string): string {
return `{{${varName}}}`
}

async function parseSuite(
/* eslint-disable @typescript-eslint/no-explicit-any */
suite: any,
Expand Down Expand Up @@ -296,9 +300,9 @@ async function parseSuite(
const fileName =
pos.fileName !== testcase._attributes.name ? pos.fileName : ''
title = checkTitleTemplate
.replace('${{FILE_NAME}}', fileName)
.replace('${{SUITE_NAME}}', suiteName ?? '')
.replace('${{TEST_NAME}}', testcase._attributes.name)
.replace(templateVar('FILE_NAME'), fileName)
.replace(templateVar('SUITE_NAME'), suiteName ?? '')
.replace(templateVar('TEST_NAME'), testcase._attributes.name)
} else if (pos.fileName !== testcase._attributes.name) {
title = suiteName
? `${pos.fileName}.${suiteName}/${testcase._attributes.name}`
Expand Down

0 comments on commit 22870cf

Please sign in to comment.