Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Dec 29, 2023
1 parent ebb8d2b commit ab5e90c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
2 changes: 2 additions & 0 deletions __tests__/functions/json-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ test('successfully validates a yaml file with a schema when yaml_as_json is true

test('successfully validates a json file and skips over the yaml one in the json processor', async () => {
process.env.INPUT_YAML_AS_JSON = 'false'
process.env.INPUT_BASE_DIR = '.'
process.env.INPUT_JSON_SCHEMA = ''
process.env.INPUT_FILES = `
__tests__/fixtures/json/with_yaml/**/test1.yml,
__tests__/fixtures/json/with_yaml/**/test*.json
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 15 additions & 12 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.

27 changes: 15 additions & 12 deletions src/functions/json-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,31 @@ export async function jsonValidator(exclude) {
continue
}

// if the file is a yaml file but it should not be treated as json
// skipped++ does not need to be called here as the file should be validated later...
// ...on as yaml with the yaml-validator
if (
yamlAsJson === false &&
(fullPath.endsWith(yamlExtension) ||
fullPath.endsWith(yamlExtensionShort))
) {
core.debug(
`the json-validator found a yaml file so it will be skipped here: '${fullPath}'`
)
continue
}

var data
try {
// if the file is a yaml file but being treated as json and yamlAsJson is true
if (
yamlAsJson &&
yamlAsJson === true &&
(fullPath.endsWith(yamlExtension) ||
fullPath.endsWith(yamlExtensionShort))
) {
core.debug(`attempting to process yaml file: '${fullPath}' as json`)
data = parse(readFileSync(fullPath, 'utf8'))

// if the file is a yaml file but it should not be treated as json
// } else if (
// yamlAsJson === false &&
// (fullPath.endsWith(yamlExtension) ||
// fullPath.endsWith(yamlExtensionShort))
// ) {
// core.debug(
// `the json-validator found a yaml file so it will be skipped here: '${fullPath}'`
// )
// continue

// if the file is a json file
} else {
data = JSON.parse(readFileSync(fullPath, 'utf8'))
Expand Down

0 comments on commit ab5e90c

Please sign in to comment.