Skip to content

Commit

Permalink
Merge pull request #25 from GrantBirki/debug-improvements
Browse files Browse the repository at this point in the history
debug improvements
  • Loading branch information
GrantBirki authored Aug 10, 2023
2 parents 4dc9717 + 365fb47 commit 9dae423
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
1 change: 0 additions & 1 deletion __tests__/functions/exclude.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ test('does not exclude any files when no exclude file is used', () => {
process.env.INPUT_USE_GITIGNORE = 'false'
const exclude = new Exclude()
expect(exclude.isExcluded('exclude-me.json')).toBe(false)
expect(debugMock).not.toHaveBeenCalled()
})

test('excludes a file that is not tracked by git', () => {
Expand Down
31 changes: 23 additions & 8 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.

8 changes: 8 additions & 0 deletions src/functions/exclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ export class Exclude {

// read the exclude file if it was used
if (this.path && this.path !== '') {
core.debug(`loading exclude_file: ${this.path}`)

this.exclude = readFileSync(this.path, 'utf8')
// split the exclude file into an array of strings and trim each string
this.exclude = this.exclude.split('\n').map(item => item.trim())
// remove any empty strings
this.exclude = this.exclude.filter(item => item !== '')
// remove any comments
this.exclude = this.exclude.filter(item => !item.startsWith('#'))

core.debug(`loaded exclude patterns: ${this.exclude}`)
}

// if gitTrackOnly is true, add the git exclude patterns from the .gitignore file if it exists
if (this.gitTrackedOnly) {
core.debug(
`use_gitignore: ${this.gitTrackedOnly} - only using git tracked files`
)

const gitIgnorePath = core.getInput('git_ignore_path')
var gitIgnoreExclude = []
try {
Expand Down
5 changes: 4 additions & 1 deletion src/functions/json-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ export async function jsonValidator(exclude) {
? `**/*{${jsonExtension},${yamlGlob}}`
: `**/*${jsonExtension}`

core.debug(`using baseDir: ${baseDirSanitized}`)
core.debug(`using glob: ${glob}`)

const files = globSync(glob, {cwd: baseDirSanitized, dot: useDotMatch})
for (const file of files) {
// construct the full path to the file
const fullPath = `${baseDirSanitized}/${file}`
core.debug(`found file: ${fullPath}`)

if (jsonSchema !== '' && fullPath.includes(jsonSchema)) {
// skip the jsonSchema file and don't count it as a skipped file
Expand All @@ -103,7 +107,6 @@ export async function jsonValidator(exclude) {
}

var data

try {
// try to parse the file
if (fullPath.endsWith('.yaml')) {
Expand Down
18 changes: 11 additions & 7 deletions src/functions/yaml-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ export async function yamlValidator(exclude) {
skipped: 0,
violations: []
}
const files = globSync(
`**/*.{${yamlExtension.replace('.', '')},${yamlExtensionShort.replace(
'.',
''
)}}`,
{cwd: baseDirSanitized, dot: useDotMatch}
)

const glob = `**/*.{${yamlExtension.replace(
'.',
''
)},${yamlExtensionShort.replace('.', '')}}`

core.debug(`using baseDir: ${baseDirSanitized}`)
core.debug(`using glob: ${glob}`)

const files = globSync(glob, {cwd: baseDirSanitized, dot: useDotMatch})
for (const file of files) {
// construct the full path to the file
const fullPath = `${baseDirSanitized}/${file}`
core.debug(`found file: ${fullPath}`)

if (yamlSchema !== '' && fullPath.includes(yamlSchema)) {
core.debug(`skipping yaml schema file: ${fullPath}`)
Expand Down

0 comments on commit 9dae423

Please sign in to comment.