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

Jinja syntax pre-commit validation #10667

Merged

Conversation

VannTen
Copy link
Contributor

@VannTen VannTen commented Nov 29, 2023

What type of PR is this?
/kind feature

What this PR does / why we need it:
Allow to fail early (pre-commit time) for jinja error, rather than
waiting until executing the playbook and the invalid template.
This catch simple syntax errors like missing endif/endfor.
-> save CI and dev time

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:
I could not find a simple jinja pre-commit hook in the wild.
dansabel tries to check filter names so it does not really work.

Does this PR introduce a user-facing change?:

Jinja syntax pre-commit validation

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 29, 2023
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 29, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @VannTen. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 29, 2023
@VannTen
Copy link
Contributor Author

VannTen commented Nov 29, 2023

Hum I was under the impression than pre-commit hooks and CI jobs were automatically synced. But they are not.
🤔

@VannTen VannTen force-pushed the feat/pre-commit-jinja-syntax branch from 4fa9909 to 44019b5 Compare November 29, 2023 12:01
@MrFreezeex
Copy link
Member

MrFreezeex commented Nov 29, 2023

HMmm isn't ansible-lint supposed to already check that: https://ansible.readthedocs.io/projects/lint/rules/jinja/? The precommit is probably nice though but not sure about the CI job as it exec ansible-lint in the same CI stage IIRC? If you have a case where ansible-lint was not able to catch something and your new check does, happy to go forward with this as is! 👍

@VannTen
Copy link
Contributor Author

VannTen commented Nov 29, 2023

Somehow ansible-lint does not catch that sort of thing (don't know why), see the test PR CI run.

Copy link
Member

@MrFreezeex MrFreezeex left a comment

Choose a reason for hiding this comment

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

Indeed 👌 let's go for this then :D
/lgtm
/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 29, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 29, 2023
@VannTen
Copy link
Contributor Author

VannTen commented Nov 29, 2023

/assign @liupeng0518
/retest

Copy link
Member

@floryut floryut left a comment

Choose a reason for hiding this comment

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

@VannTen All good thank you

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: floryut, MrFreezeex, VannTen

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 30, 2023
@VannTen
Copy link
Contributor Author

VannTen commented Nov 30, 2023

/retest

@VannTen VannTen force-pushed the feat/pre-commit-jinja-syntax branch from 44019b5 to f2d73a5 Compare November 30, 2023 15:12
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 30, 2023
@VannTen
Copy link
Contributor Author

VannTen commented Nov 30, 2023

New changes are detected. LGTM label has been removed.

But they're identical ! ^
Anyway, would you mind a new lgtm @MrFreezeex ?

Allow to fail early (pre-commit time) for jinja error, rather than
waiting until executing the playbook and the invalid template.

I could not find a simple jinja pre-commit hook in the wild.
@VannTen VannTen force-pushed the feat/pre-commit-jinja-syntax branch from f2d73a5 to 203e6eb Compare December 5, 2023 15:52
@VannTen VannTen requested a review from MrFreezeex December 5, 2023 16:12
@yankay
Copy link
Member

yankay commented Dec 6, 2023

Thanks @VannTen
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 6, 2023
@k8s-ci-robot k8s-ci-robot merged commit d2944d2 into kubernetes-sigs:master Dec 6, 2023
64 checks passed
@yankay yankay mentioned this pull request Dec 15, 2023
pedro-peter pushed a commit to pedro-peter/kubespray that referenced this pull request May 8, 2024
Allow to fail early (pre-commit time) for jinja error, rather than
waiting until executing the playbook and the invalid template.

I could not find a simple jinja pre-commit hook in the wild.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants