Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add json schema validation with ajv #1167

Merged
merged 9 commits into from
Apr 11, 2024
Merged

feat: add json schema validation with ajv #1167

merged 9 commits into from
Apr 11, 2024

Conversation

ANGkeith
Copy link
Collaborator

@ANGkeith ANGkeith commented Mar 31, 2024

fixes #859

Main motivation is that the ajv will make gitlab-ci-local less likely to produce false positive

@@ -0,0 +1,17 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
Copy link
Collaborator Author

@ANGkeith ANGkeith Mar 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know how to use import here

src/parser.ts Outdated
assert(valid,
chalk`
Invalid gitlab-ci configuration! It have failed the json schema validation. Dump the following to the pipeline editor to debug:
${yaml.dump(gitlabData)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently only dumping out the yaml...

can't really find a nice way to parse the validate.errors that catches all scenarios

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure I saw a way to pretty print AJV errors somewhere, let me dig around.

src/parser.ts Outdated Show resolved Hide resolved
src/job.ts Show resolved Hide resolved
@ANGkeith ANGkeith changed the title feat: add json schema validation with ajv wip feat: add json schema validation with ajv Apr 1, 2024
@firecow firecow marked this pull request as draft April 2, 2024 06:58
@firecow firecow changed the title wip feat: add json schema validation with ajv feat: add json schema validation with ajv Apr 2, 2024
@ANGkeith ANGkeith force-pushed the feat/ajv branch 2 times, most recently from 3cfb58d to b5f6e38 Compare April 4, 2024 13:52
@ANGkeith
Copy link
Collaborator Author

ANGkeith commented Apr 4, 2024

MR should be ready now. the ajv will be a second layer check...

Main motivation is that the ajv will make gitlab-ci-local less likely to produce false positive

Given the following gitlab-ci.yml input:

default:
  tags:
    - 1

foo:
  image: bash
  script:
    - echo
Using fallback branch data
parsing and downloads finished in 28 ms
Invalid gitlab-ci configuration! It have failed the json schema validation. Dump the following to the pipeline editor to debug:
    stages:
  - .pre
  - build
  - test
  - deploy
  - .post
default:
  tags:
    - 1
foo:
  image:
    name: bash
  script:
    - echo

NOTE: This is beta feature, which can be disabled with `gitlab-ci-local --enable-json-schema-validation=false`

@ANGkeith ANGkeith marked this pull request as ready for review April 4, 2024 14:00
src/parser.ts Show resolved Hide resolved
Copy link

sonarcloud bot commented Apr 10, 2024

@firecow
Copy link
Owner

firecow commented Apr 11, 2024

@ANGkeith I've approved, I'll test and publish a new version tomorrow, if you have merged this by then.

@ANGkeith ANGkeith merged commit d6ab549 into master Apr 11, 2024
10 checks passed
@ANGkeith ANGkeith deleted the feat/ajv branch April 11, 2024 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

validate that tags: value is in fact an array of strings
2 participants