Skip to content

Commit

Permalink
Introduce globbing for the JSONS input
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kiriakos committed Mar 18, 2021
1 parent a477333 commit 68cf30e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
18 changes: 18 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ describe('Github action results', () => {
expect(result.toString()).toContain(`::set-output name=INVALID,::${os.EOL}`);
});

test('JSONS argument accepts globs', () => {
// Arrange
mockedConfig.mockValue('SCHEMA', './mocks/schema/valid.json');
mockedConfig.mockValue('JSONS', './mocks/tested-*/valid.json');

mockedConfig.set();

const options: cp.ExecOptions = {
env: process.env,
};

// Act
const result = cp.execSync(`node ${ip}`, options);

// Assert
expect(result.toString()).toContain(`::set-output name=INVALID,::${os.EOL}`);
});

test('Error is thrown when GITHUB_WORKSPACE environment variable is not set', () => {
// Arrange
mockedConfig.resetAll();
Expand Down
24 changes: 18 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.0.0",
"@actions/glob": "^0.1.1",
"@types/jest": "^24.0.22",
"ajv": "^6.10.2",
"better-ajv-errors": "^0.6.7",
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core';
import * as glob from '@actions/glob';
import { getConfig, verifyConfigValues } from './configuration';
import { validateJsons } from './json-validator';

Expand All @@ -12,7 +13,9 @@ async function run() {
return;
}

const jsonRelativePaths = configuration.JSONS.split(',');
const patterns = configuration.JSONS.split(',');
const globber = await glob.create(patterns.join('\n'));
const jsonRelativePaths = await globber.glob();

const validationResults = await validateJsons(
configuration.GITHUB_WORKSPACE,
Expand Down

0 comments on commit 68cf30e

Please sign in to comment.