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

pre-commit: make hooks self contained + ci config #11226

Merged
merged 11 commits into from
May 30, 2024

Conversation

VannTen
Copy link
Contributor

@VannTen VannTen commented May 21, 2024

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
This makes all the pre-commit hooks self contained (=no need for a venv) which should help their setup on CI (such as pre-commit CI)
Also disable the autofix feature of pre-commit.ci.
Even if we don't use pre-commit.ci in the end, this should make it easier to run it in Gitlab CI

Which issue(s) this PR fixes:

Fixes #11211

Special notes for your reviewer:
aab5cdc is a lot of changes, but it's mostly autofix from pre-commit.
08e2a82 contains the gitlab-ci pre-commit integration.
The rest is just pre-commit hooks fix and conversion of script to actual pre-commits hooks.

Does this PR introduce a user-facing change?:

NONE

/label tide/merge-method-merge

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesn't merit a release note. tide/merge-method-merge Denotes a PR that should use a standard merge by tide when it merges. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 21, 2024
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 21, 2024
@VannTen VannTen force-pushed the cleanup/pre-commit-hooks branch 5 times, most recently from 767b352 to 9ac1fc0 Compare May 22, 2024 14:07
@VannTen
Copy link
Contributor Author

VannTen commented May 22, 2024 via email

Copy link
Contributor

@ant31 ant31 left a comment

Choose a reason for hiding this comment

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

Co

@VannTen
Copy link
Contributor Author

VannTen commented May 23, 2024 via email

@VannTen VannTen force-pushed the cleanup/pre-commit-hooks branch 4 times, most recently from 1d8d09f to 5ffb242 Compare May 23, 2024 08:15
@VannTen VannTen requested a review from ant31 May 23, 2024 08:19
Comment on lines +2 to +21
generate-pre-commit:
image: 'mikefarah/yq@sha256:bcb889a1f9bdb0613c8a054542d02360c2b1b35521041be3e1bd8fbd0534d411'
stage: build
before_script: []
script:
- >
yq -r < .pre-commit-config.yaml '.repos[].hooks[].id' |
sed 's/^/ - /' |
cat .gitlab-ci/pre-commit-dynamic-stub.yml - > pre-commit-generated.yml
artifacts:
paths:
- pre-commit-generated.yml

run-pre-commit:
stage: unit-tests
trigger:
include:
- artifact: pre-commit-generated.yml
job: generate-pre-commit
strategy: depend
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, that's nice factoring and a way to keep the jobs running in parallel!

@ant31
Copy link
Contributor

ant31 commented May 23, 2024

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 23, 2024
@VannTen
Copy link
Contributor Author

VannTen commented May 26, 2024 via email

- yamllint --strict .
except: ['triggers', 'master']
generate-pre-commit:
image: 'mikefarah/yq@sha256:bcb889a1f9bdb0613c8a054542d02360c2b1b35521041be3e1bd8fbd0534d411'
Copy link
Member

Choose a reason for hiding this comment

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

HI @VannTen

To make the image more readable, is it ok to change the mikefarah/yq@sha256:bcb889a1f9bdb0613c8a054542d02360c2b1b35521041be3e1bd8fbd0534d411
to mikefarah/yq:4.44.1-githubaction

pre-commit:
tags:
- light
image: 'ghcr.io/pre-commit-ci/runner-image@sha256:aaf2c7b38b22286f2d381c11673bec571c28f61dd086d11b43a1c9444a813cef'
Copy link
Member

Choose a reason for hiding this comment

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

Is it more readable by changing the ghcr.io/pre-commit-ci/runner-image@sha256:aaf2c7b38b22286f2d381c11673bec571c28f61dd086d11b43a1c9444a813cef
to ghcr.io/pre-commit-ci/runner-image:2024-05-11-4bb81b2-full

@VannTen
Copy link
Contributor Author

VannTen commented May 27, 2024 via email

@ant31
Copy link
Contributor

ant31 commented May 27, 2024

Yes, using sha256 is a good practice.

VannTen added 11 commits May 28, 2024 13:26
This pre-commit does not require prerequisite on the host, making it
easier to run in CI workflows.
This way, the hook is self contained and does not depend on a previous
virtualenv installation.
- ansible-syntax-check
- tox-inventory-builder
- jinja-syntax-check
- Remove dependency of pydblite which fails to setup on recent pythons
- Discard shell script and put everything into pre-commit
- markdownlint (manual fix)
- end-of-file-fixer
- requirements-txt-fixer
- trailing-whitespace
client9/misspell is unmaintained, and has been forked by the golangci
team, see client9/misspell#197 (comment).

They haven't yet added a pre-commit config, so use my fork with the
pre-commit hook config until the pull request is merged.
Use gitlab dynamic child pipelines feature to have one source of truth
for the pre-commit jobs, the pre-commit config file.

Use one cache per pre-commit. This should reduce the "fetching cache"
time steps in gitlab-ci, since each job will have a separate cache with
only its hook installed.
Use a style file as recommended by upstream. This makes for only one
source of truth.
Conserve previous upstream default for MD007 (upstream default changed
here markdownlint/markdownlint#373)
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2024
@VannTen VannTen mentioned this pull request May 28, 2024
@ant31
Copy link
Contributor

ant31 commented May 29, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 29, 2024
@ant31
Copy link
Contributor

ant31 commented May 29, 2024

/approve

@yankay
Copy link
Member

yankay commented May 30, 2024

Thanks @VannTen
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ant31, VannTen, yankay

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 May 30, 2024
@k8s-ci-robot k8s-ci-robot merged commit af59346 into kubernetes-sigs:master May 30, 2024
77 checks passed
@tico88612
Copy link
Member

/cherrypick release-2.25

@k8s-infra-cherrypick-robot

@tico88612: new pull request created: #11359

In response to this:

/cherrypick release-2.25

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.

@tico88612
Copy link
Member

/cherrypick release-2.25

@k8s-infra-cherrypick-robot

@tico88612: new pull request could not be created: failed to create pull request against kubernetes-sigs/kubespray#release-2.25 from head k8s-infra-cherrypick-robot:cherry-pick-11226-to-release-2.25: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"A pull request already exists for k8s-infra-cherrypick-robot:cherry-pick-11226-to-release-2.25."}],"documentation_url":"https://docs.github.com/rest/pulls/pulls#create-a-pull-request","status":"422"}

In response to this:

/cherrypick release-2.25

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.

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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-merge Denotes a PR that should use a standard merge by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use pre-commit in CI as well to reduce deduplication
8 participants