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

Regression in gitlab-ci: coverage regex not recognised #516

Closed
quentin-ag opened this issue Jan 14, 2025 · 2 comments · Fixed by #519
Closed

Regression in gitlab-ci: coverage regex not recognised #516

quentin-ag opened this issue Jan 14, 2025 · 2 comments · Fixed by #519
Labels
bug Something isn't working regular-expressions Related to the regex engines and modes

Comments

@quentin-ag
Copy link

Context

This follows from #436, about the wrong report 'coverage: [...] is not a regex' with the gitlab-ci schema. One solution was to use the following regex (minimal example of .gitlab-ci.yml file):

tests:
  coverage: /TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/

Problem

The solution from #436 worked until version 0.30.0 of check-jsonschema. This can be reproduced with the minimal example above. Assuming it is the content of the file min-gitlab-ci.yml:

python -m pip install --quiet 'check-jsonschema==0.30'
check-jsonschema --builtin-schema "gitlab-ci" min-gitlab-ci.yml

Result:

ok -- validation done

This now fails with version 0.31:

python -m pip install --quiet 'check-jsonschema==0.31'
check-jsonschema --builtin-schema "gitlab-ci" min-gitlab-ci.yml

Result:

Schema validation errors were encountered.
  min-gitlab-ci.yml::$.tests.coverage: '/TOTAL.*? (100(?:\\.0+)?\\%|[1-9]?\\d(?:\\.\\d+)?\\%)$/' is not a 'regex'

Is this a regression? Should the regex be changed?
Thanks in advance for any support on this.

Environment details

OS: Arch Linux
Python: 3.9.21

@sirosen
Copy link
Member

sirosen commented Jan 14, 2025

This is a regression, but it's not in the schema! Thanks for the MRE, it made it easy to confirm.

In v0.31.0 the default regex behavior became ECMAScript regexes in unicode mode. However, for GitLab specifically that's probably the wrong choice, since GitLab's regexes are in the ruby engine (which we cannot perfectly support).

I was able to get your example to work by adding --regex-variant nonunicode.
Can you let me know if that works for your full use-case? It should be a viable workaround for now, on v0.31.0.

I plan to include a switch to this for the pre-commit hook in the next release, but confirmation that the setting works well would be good.

@sirosen sirosen added the bug Something isn't working label Jan 14, 2025
@quentin-ag
Copy link
Author

Thanks for the quick reply 🙏

I can confirm that your workaround works for me on both the minimal example and on my full GitLab CI configuration 🎉

python -m pip install --quiet 'check-jsonschema==0.31'
check-jsonschema --builtin-schema --regex-variant nonunicode "gitlab-ci" min-gitlab-ci.yml
# ok -- validation done
check-jsonschema --builtin-schema --regex-variant nonunicode "gitlab-ci" .gitlab-ci.yml
# ok -- validation done

I'm happy with the workaround and I look forward to the switch in the next release. Feel free to close this ticket whenever you feel is appropriate. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regular-expressions Related to the regex engines and modes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants