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

chore: move cargo fmt to pre-commit script #2163

Closed
wants to merge 3 commits into from

Conversation

SteveLauC
Copy link
Member

What does this PR do

  1. Move cargo fmt task to a pre-commit script, and add a doc for it in CONTRIBUTING.md
  2. Add a doc on how to skip the CI (Cirrus CI, will add the GitHub Action version when we finish our migration) in CONTRIBUTING.md

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

[skip ci]

@SteveLauC
Copy link
Member Author

Kinda weird, the Cirrus CI still runs even though I explicitly [skip ci]

@SteveLauC SteveLauC mentioned this pull request Oct 7, 2023
@Jan561
Copy link
Contributor

Jan561 commented Oct 7, 2023

It seems you have to include [skip ci] in the title of the PR.

If you open a PR, PR title will be checked for [skip ci] or [ci skip]
instead of the last commit message on the PR branch.

https://cirrus-ci.org/guide/writing-tasks/#conditional-task-execution

Still weird though as it worked in #2158.

@asomers
Copy link
Member

asomers commented Oct 7, 2023

I don't know about you, but personally I would find it surprising if the pre-commit script actually changed my code, as opposed to merely checking it. Also, I don't think that the addition of a pre-commit script absolves us from running rustfmt in CI. Because what if some contributor doesn't run the pre-commit script? We have no way to force them to.

@SteveLauC
Copy link
Member Author

Also, I don't think that the addition of a pre-commit script absolves us from running rustfmt in CI. Because what if some contributor doesn't run the pre-commit script? We have no way to force them to.

Then it seems that we have to add rustfmt to our CI, because AFAIK, there is no way to make this check compulsory with a pre-commit script

@SteveLauC
Copy link
Member Author

It seems you have to include [skip ci] in the title of the PR.

If you open a PR, PR title will be checked for [skip ci] or [ci skip]
instead of the last commit message on the PR branch.

https://cirrus-ci.org/guide/writing-tasks/#conditional-task-execution

Still weird though as it worked in #2158.

Yeah, it is indeed weird :<

@@ -0,0 +1,36 @@
#!/bin/sh

function red() {
Copy link
Member

Choose a reason for hiding this comment

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

The function is bash syntax, not sh.

Suggested change
function red() {
red() {


echo -e "$(green INFO): Checking code format..."

cargo fmt --all -q -- --check 2>/dev/null
Copy link
Member

Choose a reason for hiding this comment

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

This command doesn't actually work. I just tested it by screwing up the format in src/sys/aio.rs, and this command didn't complain. I think it's caused by this bug: rust-lang/rustfmt#3253 . That's why we need to do cargo fmt --all -- --check **/*.rs

@SteveLauC
Copy link
Member Author

For the format check, are we gonna use a pre-commit script or do it in CI?

#2166 has migrated it to GHA, so if we choose the latter, then we can simply close this PR

@asomers
Copy link
Member

asomers commented Nov 4, 2023

Yeah, I think we can close this PR if we merge the other one too. The pre-commit.sh script could be useful too, but maybe not useful enough to justify its ongoing maintenance.

@SteveLauC
Copy link
Member Author

Close this PR

@SteveLauC SteveLauC closed this Nov 5, 2023
@SteveLauC SteveLauC deleted the fmt-pre-commit-hook branch November 13, 2023 04:49
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