firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.03k stars 115 forks source link

Improve validation #1263 #1255 #1266

Closed hverlin closed 1 week ago

hverlin commented 2 weeks ago

Fix #1263 #1255

Given

test:
  needs: [types]
  when: 'manual2'
  artifacts:
    reports:
      junit: 3
  script: ''
  data: "test"
Invalid .gitlab-ci.yml configuration
        • 'data' property is not expected to be here at test
        • property 'script' must not have fewer than 1 characters at test.script
        • 'when' property must be one of [on_success, on_failure, always, never, manual, delayed] (found manual2) at test.when
        • 'junit' property type must be string at test.artifacts.reports.junit

image

hverlin commented 2 weeks ago

@firecow @ANGkeith Let me know if these changes are ok. I will then add tests.

ANGkeith commented 2 weeks ago

looks and sounds good to me, but lets see what firecow has to say

Regarding schema validation, output was done directly using console/assert before. Should I switch to writeStreams?

In general, i think we use assert/writeStreams, most of the console's be introduced by me 😅

hverlin commented 1 week ago

@firecow Anything you would change here before I add tests?

firecow commented 1 week ago

@hverlin Nah, nothing much. All looks good.

Validation errors:
        test must NOT have additional properties

Is it possible to print exactly what properties are additional?

hverlin commented 1 week ago

I reused code from https://github.com/apideck-libraries/better-ajv-errors, and I am now getting better error message.

Given

test:
  needs: [types]
  when: 'manual2'
  artifacts:
    reports:
      junit: 3
  script: ''
  data: "test"
Invalid .gitlab-ci.yml configuration
        • 'data' property is not expected to be here at test
        • property 'script' must not have fewer than 1 characters at test.script
        • 'when' property must be one of [on_success, on_failure, always, never, manual, delayed] (found manual2) at test.when
        • 'junit' property type must be string at test.artifacts.reports.junit

image

firecow commented 1 week ago

@ANGkeith I'll let you review this as well, before I'm merging.

ANGkeith commented 1 week ago

very nice

sonarcloud[bot] commented 1 week ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
83.9% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud