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

github: formatting: add check on push and pull-request #810

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kkanas
Copy link
Contributor

@kkanas kkanas commented Nov 15, 2024

Add pre-commit to allow local check before commit. This requires installing pre-commit on local machine. Flow to install and check/debug:

pip install pre-commit
pre-commit install
# run pre-commit on single file file_to_check.txt pre-commit run --verbose --files file_to_check.txt # run pre-commit on all files
pre-commit run --verbose --all-files

Rules for pre-commit are in .pre-commit-config.yaml: Currently rules are:

check-added-large-files:
Will stop commit if large files to the repo
mixed-line-ending:
args: ['--fix', 'no']
Reports rule and stops on when file has mixed line endings
will run on all files in repository excluding files ending with .cmd
mixed-line-ending:
args: ['--fix', 'crlf']
files: '.cmd$'
Will automatically correct lf to crlf on files ending with .cmd

To uphold rules on server new github workflow is added that will execute pre-commit run --all-files

Lastly I changed .gitattributes to also force crlf in cmd files.

Description

Describe your changes in as much detail as possible. Provide a link/reference to the issue solved with this request if any.

Checklist

  • I have read the contribution guidelines.
  • All unit tests are passing.
  • I have merged the latest main branch prior to this PR submission.
  • I submitted this PR against the main branch.

Add pre-commit to allow local check before commit.
This requires installing pre-commit on local machine.
Flow to install and check/debug:

pip install pre-commit
pre-commit install
\# run pre-commit on single file file_to_check.txt
pre-commit run --verbose --files file_to_check.txt
\#  run pre-commit on all files
pre-commit run --verbose --all-files

Rules for pre-commit are in .pre-commit-config.yaml:
Currently rules are:

check-added-large-files:
    Will stop commit if large files to the repo
mixed-line-ending:
    args: ['--fix', 'no']
    Reports rule and stops on when file has mixed line endings
    will run on all files in repository excluding files ending with .cmd
mixed-line-ending:
      args: ['--fix', 'crlf']
      files: '\.cmd$'
      Will *automatically* correct lf to crlf on files ending with .cmd

To uphold rules on server new github workflow is added that will execute
pre-commit run --all-files

Lastly I changed .gitattributes to also force crlf in cmd files.

Signed-off-by: Krzysztof Kanas <[email protected]>
@kkanas kkanas requested a review from a team as a code owner November 15, 2024 19:59
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@MariusNi MariusNi self-requested a review November 18, 2024 05:25
@AhmedBM
Copy link
Contributor

AhmedBM commented Nov 18, 2024

@kkanas will this pre-commit hook make git fail when committing anything that invalidates the rules? Sorry im new to these hooks and trying to see the differences/advantages in them.

@kkanas
Copy link
Contributor Author

kkanas commented Nov 19, 2024

@kkanas will this pre-commit hook make git fail when committing anything that invalidates the rules? Sorry im new to these hooks and trying to see the differences/advantages in them.

Hi Yes this should fail when you commit anything that invalidates the rules.
I try to summarise:

  1. The .pre-commit-config.yaml consist of rules that will be run by pre-commit run (options)
  2. To run pre-commit locally (on your workstation) you need to install that python package and can either run it:
  • manually by using command pre-commit run --all-files
  • locally as pre-commit hook the command pre-commit install install script invocation in .git/hooks/pre-commit
  • on server when you can run pre-commit as I did in the workflow file

So if we ran this on server we should have build failures when pull request is filed when those rules are not uphold.

Now the how we want to run pre-commit, either in way of showing violation args: ['--fix', 'no'], then locally script will fail on pre-commit.
If you don't add args: ['--fix', 'no'] then pre commit automatically fix violations for you as part of pre commit, you will be stoped before commit with code modified but not committed.

I added .gitattributes and .pre-commit-config.yaml to enforce line
endings.

Line endings were fixed by running
`pre-commit run --all-files`

Signed-off-by: Krzysztof Kanas <[email protected]>
…cific

Formatting done by running:
    pre-commit run --all-files

Signed-off-by: Krzysztof Kanas <[email protected]>
Formatting done by running:
    pre-commit run --all-files

Signed-off-by: Krzysztof Kanas <[email protected]>
Corupus files are exclude due them beeing binary files and new line
would construct new corpus with empty line

Signed-off-by: Krzysztof Kanas <[email protected]>
Formatting done using:
pre-commit run --all-files

Signed-off-by: Krzysztof Kanas <[email protected]>
@kkanas
Copy link
Contributor Author

kkanas commented Nov 19, 2024

@kkanas will this pre-commit hook make git fail when committing anything that invalidates the rules? Sorry im new to these hooks and trying to see the differences/advantages in them.

AhmedBM
Also look on comments #810 (comment)
and separate commits - hope that helps

Copy link
Contributor

@AhmedBM AhmedBM left a comment

Choose a reason for hiding this comment

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

👌

@@ -27,4 +27,4 @@ The OSConfig Core team will respond to a PR that passes all checks in 3 business

# Contact

You may contact the OSConfig Core team at [[email protected]](mailto:[email protected]) to ask questions about OSConfig, to report bugs, to suggest new features, or inquire about any other OSConfig related topic.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not remove this

Copy link
Contributor

Choose a reason for hiding this comment

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

We need CONTRIBUTING.md restored. It appears it was deleted? (at least on my side). Also, it appears lots of files gained a new EOL at the last line, adding one blank line at the end. Can we remove that? Thanks

@MariusNi
Copy link
Contributor

Here and in few more file, it appears that a blank line is added at the end. Can you please check and fix if needed?


Refers to: LICENSE.md:24 in 7dbba03. [](commit_id = 7dbba03, deletion_comment = False)

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