Skip to content

yamllint: cover all changed files ending in yaml, yml or fmf#14601

Merged
jan-cerny merged 9 commits intoComplianceAsCode:masterfrom
vojtapolasek:make_yamllint_filepaths_stricter
Apr 9, 2026
Merged

yamllint: cover all changed files ending in yaml, yml or fmf#14601
jan-cerny merged 9 commits intoComplianceAsCode:masterfrom
vojtapolasek:make_yamllint_filepaths_stricter

Conversation

@vojtapolasek
Copy link
Copy Markdown
Collaborator

@vojtapolasek vojtapolasek commented Mar 26, 2026

Description:

  • update the ci-lint workflow to utilize .yamllint config file present in the root of the project
  • update the .yamllint config file to implement some of project's style requirements
  • apply yamllint to all files which are being changed by a PR, let yamllint ignore files which are not matching yml, yaml or fmf extensions

Rationale:

  • The previous grep "controls/" pattern matched any file path containing controls/, which could include non-YAML files that yamllint cannot process. Restricting to controls/.*\.yml ensures only relevant YAML files are linted, avoiding spurious CI failures.

Review Hints:

  • Single-commit, single-line change in .github/workflows/ci_lint.yml (line 52).
  • No product builds are affected — this is a CI infrastructure change only.

if: ${{ env.CONTROLS_CHANGES == 'true' }}
run: |
for control_file in $(cat filenames.txt | grep "controls/"); do
for control_file in $(cat filenames.txt | grep "controls/.*\.yml"); do
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is a similar regex on line 32. Should that regex be changed as well?

@comps
Copy link
Copy Markdown
Collaborator

comps commented Mar 27, 2026

Are you sure you don't want to configure yamllint properly instead, as I suggested in #14529 (comment) ?

@vojtapolasek vojtapolasek force-pushed the make_yamllint_filepaths_stricter branch from 8ca69d6 to d48dd28 Compare March 27, 2026 11:48
Filter out files inside the .yamllint configuration
@vojtapolasek vojtapolasek force-pushed the make_yamllint_filepaths_stricter branch from d48dd28 to 975e2d6 Compare March 27, 2026 11:55
@vojtapolasek vojtapolasek force-pushed the make_yamllint_filepaths_stricter branch from b803433 to 02bffa8 Compare March 27, 2026 13:55
@vojtapolasek vojtapolasek changed the title yamllint: make control file path matching stricter in CI lint workflow yamllint: cover all changed files ending in yaml, yml or fmf Mar 27, 2026
Copy link
Copy Markdown
Collaborator

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

@vojtapolasek Do I understand it well that now the .profile files won't be checked?

@vojtapolasek
Copy link
Copy Markdown
Collaborator Author

@jan-cerny oops, correct, I have to fix this.

@jan-cerny
Copy link
Copy Markdown
Collaborator

/retest

yamllint "$profile_file"
for file in $(cat filenames.txt); do
echo "Running yamllint on $file..."
yamllint -c .yamllint "$file"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this will run yamllint on all files modified by the PR, think OVALs, Python files, ... It can slow the job down.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think it will not slow things down, the .yamllint config file explicitly specifies globs which will be actually scanned.

if grep -q "\.profile" filenames.txt; then
echo "PROFILES_CHANGES=true" >> $GITHUB_ENV
else
echo "PROFILES_CHANGES=false" >> $GITHUB_ENV
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You have removed this insertion of PROFILES_CHANGES and CONTROL_CHANGES environment variables to GITHUB_ENV. But, the "Install yamllint" phase still uses these environment variables. I suspect it doesn't work.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I removed the leftover conditional.

echo "Running yamllint on $profile_file..."
yamllint "$profile_file"
for file in $(cat filenames.txt); do
echo "Running yamllint on $file..."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Will this work on YAML files that contain Jinja macros?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In the last commit I added a script which strips Jinja and still allows us to lint files.

spaces: consistent
line-length: disable
line-length:
max: 99 # allow lines up to 99 chars
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do all our YAML files meet the line lenghth limit of 99 lines?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

They probably don't, but this should run only on newly modified files. At the same time, we impose this limit on our selves... so with this approach, it will be enforced gradually. Do you think it is a problem?

vojtapolasek and others added 2 commits April 2, 2026 10:28
Many YAML files in this project contain Jinja2 templating ({{% %}},
{{{ }}}, {{# #}}) which causes yamllint to report false syntax errors.

Add a helper script (utils/strip_jinja_for_yamllint.py) that removes
Jinja constructs while preserving line numbers, and update the CI
workflow to use it for files that contain Jinja. Files without Jinja
are linted directly as before. Warnings are reported but do not fail
the job.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---
extends: default
locale: en_US.UTF-8
yaml-files:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It looks like the yaml-files option is somehow ignored by yamllint.

In the CI run, we can see that the job failed on utils/strip_jinja_for_yamllint.py. Unfortunately, the CI output doesn't show any details.

When I try to reproduce it locally, I run yamllint -s -c .yamllint utils/strip_jinja_for_yamllint.py and from the output it looks like it tried to evaluate the Python file as YAML file.

jcerny@fedora:~/work/git/scap-security-guide (pr/14601)$ yamllint -s -c .yamllint  utils/strip_jinja_for_yamllint.py
utils/strip_jinja_for_yamllint.py
  2:3       error    syntax error: expected '<document start>', but found '<scalar>' (syntax)

Please check if the filtering by glob really works. Also, please investigate whether we can have a detailed output in the GitHub CI output.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ahaaa, I see what is the problem. The yaml-files block (according to man page) applies in case yamllint processes a directory. It does not apply when it is passed a particular file.
If we would like to stick with usage of this configuration option to limit set of analyzed files, we would need to somehow create directory structure containing only files changed in the analyzed PR... that seems actually quite strange to me. I think I will go back to some kind of parsing list of changed files and passing only those relevant files to yamllint. Do you agree?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Aha, thanks for discovering this. I agree with your proposal.

This needs to be done in addition to filter within the .yamllint file because CI runs yamllint on individual files and not directories.
The configuration within the .yamllint works when yamllint is given a directory.
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 8, 2026

@vojtapolasek: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-openshift-node-compliance daa564b link true /test e2e-aws-openshift-node-compliance
ci/prow/e2e-aws-openshift-platform-compliance daa564b link true /test e2e-aws-openshift-platform-compliance

Full PR test history. Your PR dashboard.

Details

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-sigs/prow repository. I understand the commands that are listed here.

@vojtapolasek vojtapolasek force-pushed the make_yamllint_filepaths_stricter branch from daa564b to 5fcf646 Compare April 9, 2026 08:08
Copy link
Copy Markdown
Collaborator

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

I have reviewed the code and the previous version of the PR confirmed that the job is able to identify and report issues in YAML formatting.

@jan-cerny jan-cerny merged commit 6c90337 into ComplianceAsCode:master Apr 9, 2026
94 of 98 checks passed
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.

3 participants