Skip to content

Commit 68cf30e

Browse files
committed
Introduce globbing for the JSONS input
Implemented globbing resolution based on @actions/glob [1]. Added test to validate globs are being read. Fixes OrRosenblatt#19. 1: https://github.com/actions/toolkit/tree/main/packages/glob
1 parent a477333 commit 68cf30e

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

__tests__/main.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ describe('Github action results', () => {
3737
expect(result.toString()).toContain(`::set-output name=INVALID,::${os.EOL}`);
3838
});
3939

40+
test('JSONS argument accepts globs', () => {
41+
// Arrange
42+
mockedConfig.mockValue('SCHEMA', './mocks/schema/valid.json');
43+
mockedConfig.mockValue('JSONS', './mocks/tested-*/valid.json');
44+
45+
mockedConfig.set();
46+
47+
const options: cp.ExecOptions = {
48+
env: process.env,
49+
};
50+
51+
// Act
52+
const result = cp.execSync(`node ${ip}`, options);
53+
54+
// Assert
55+
expect(result.toString()).toContain(`::set-output name=INVALID,::${os.EOL}`);
56+
});
57+
4058
test('Error is thrown when GITHUB_WORKSPACE environment variable is not set', () => {
4159
// Arrange
4260
mockedConfig.resetAll();

package-lock.json

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"license": "MIT",
2424
"dependencies": {
2525
"@actions/core": "^1.0.0",
26+
"@actions/glob": "^0.1.1",
2627
"@types/jest": "^24.0.22",
2728
"ajv": "^6.10.2",
2829
"better-ajv-errors": "^0.6.7",

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from '@actions/core';
2+
import * as glob from '@actions/glob';
23
import { getConfig, verifyConfigValues } from './configuration';
34
import { validateJsons } from './json-validator';
45

@@ -12,7 +13,9 @@ async function run() {
1213
return;
1314
}
1415

15-
const jsonRelativePaths = configuration.JSONS.split(',');
16+
const patterns = configuration.JSONS.split(',');
17+
const globber = await glob.create(patterns.join('\n'));
18+
const jsonRelativePaths = await globber.glob();
1619

1720
const validationResults = await validateJsons(
1821
configuration.GITHUB_WORKSPACE,

0 commit comments

Comments
 (0)