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

Ci rustfmt v2 #9072

Closed
wants to merge 2 commits into from
Closed

Ci rustfmt v2 #9072

wants to merge 2 commits into from

Conversation

catenacyber
Copy link
Contributor

@catenacyber catenacyber commented Jun 26, 2023

Link to redmine ticket:
https://redmine.openinfosecfoundation.org/issues/3836

Describe changes:

  • GitHub action to check that rustfmt-ed files are still rustfmt-ed
  • rustfmt some more files which have a small diff

#9044 with review taken into account

@jasonish would you know if there is some Github CI way to have both master and PR branch tested : so that we can check rustfmt status of files between without keeping a list of known rustfmt-ed files ?

Good start. While I'd rather just format master and master-6.0.x in one go at the same time, this is probably more realistic approach to get to whats expected of Rust projects today.

I am happy with the one-go approach but I guess the incremental one has more chances of getting merged...

@catenacyber catenacyber requested review from jasonish and a team as code owners June 26, 2023 07:22
Files formatted need to remain formatted
@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Merging #9072 (2de5151) into master (643e674) will decrease coverage by 0.07%.
The diff coverage is 66.66%.

❗ Current head 2de5151 differs from pull request most recent head d19275a. Consider uploading reports for the commit d19275a to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9072      +/-   ##
==========================================
- Coverage   82.35%   82.28%   -0.07%     
==========================================
  Files         969      969              
  Lines      273655   273654       -1     
==========================================
- Hits       225359   225189     -170     
- Misses      48296    48465     +169     
Flag Coverage Δ
fuzzcorpus 64.54% <33.33%> (-0.04%) ⬇️
suricata-verify 60.63% <0.00%> (-0.02%) ⬇️
unittests 62.91% <33.33%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@victorjulien victorjulien mentioned this pull request Jun 26, 2023
@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 14828

@suricata-qa
Copy link

Information:

field baseline test %
TREX_GENERIC_stats_chk
.capture.kernel_drops 0 461 0.00

Pipeline 14830

@victorjulien victorjulien removed the request for review from a team June 26, 2023 18:01
@jasonish
Copy link
Member

@jasonish would you know if there is some Github CI way to have both master and PR branch tested : so that we can check rustfmt status of files between without keeping a list of known rustfmt-ed files ?

The commits.yml workflow does something like that.. But it'll just be easier if we can do it all at once.

cargo fmt $i;
# the file used to be formatted and is not anymore
if [ $(git diff -- $i | wc -l) -gt 0 ]; then
git diff;
Copy link
Contributor

Choose a reason for hiding this comment

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

This will print diffs of all files, not just the current file.

Probably meant git diff -- $i?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But cargo fmt $i only changed one file, right ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, looking at that at https://github.com/rust-lang/rustfmt#running

Seems cargo fmt does the whole crate/module. It might silently ignore the file?

You'd have to use rustfmt it seems with files. However, rustfmt might also check some included files if I got the description correct?! So that might check transiently included files multiple times? Ugh, that would open up "interesting behaviours"... Maybe worth trying it out?

If that is the case, it might be easier to run cargo fmt once and then git diff check for the list of files in rustfmt.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Roland for the tips, waiting for a decision wether this is the right approach before tuning this

cat qa/rustfmt.txt | while read i; do
cargo fmt $i;
# the file used to be formatted and is not anymore
if [ $(git diff -- $i | wc -l) -gt 0 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing wrong with this check, just FYI.

An alternative to check for differences would be git diff --quiet -- $i which makes git diff "exit with codes similar to diff". I.e. returns 1 if there are any differences, 0 otherwise. See git help diff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, looks nicer.

What is the exact bash syntax for the test ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Different ways to skin that cat.

You might have seen something like:

git diff --quiet -- $i
if [ $? -ne 0 ] ; then
   # multiple commands ...
fi

I'd probably would do (if you don't need the exit value of the command):

if ! git diff --quiet -- $i; then
   # multiple commands ...
fi

Note the inversion with ! ... as the then path is executed if the command returns 0. diff/git diff --quiet returns 1 (not 0 basically) if files are different.

Or you could short-circuit things

git diff --quiet -- $i || ( 
   # multiple commands ...
)

Or if you fancy one liners - not my personal preference if more than one command in failure path, but valid as well:

git diff --quiet -- $i || ( git diff -- $i; echo "$i needs formatting"; r=1 )

It's really your personal preference

@catenacyber catenacyber marked this pull request as draft July 6, 2023 11:33
@catenacyber
Copy link
Contributor Author

Should I close this, tracked by https://redmine.openinfosecfoundation.org/issues/3836 because the plan is to rustfmt all code when starting on 8 branch ?

@victorjulien
Copy link
Member

Should I close this, tracked by https://redmine.openinfosecfoundation.org/issues/3836 because the plan is to rustfmt all code when starting on 8 branch ?

Probably best, ya.

@catenacyber catenacyber closed this Jul 6, 2023
@catenacyber catenacyber mentioned this pull request Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants