From 3f223f8104e1ce5278873eb9fe08be09c9139bba Mon Sep 17 00:00:00 2001 From: Ivan Litteri <67517699+ilitteri@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:58:15 -0300 Subject: [PATCH] feat(l1, l2, levm): improve loc reporter (#1326) - Improves slack message - Generate different messages for slack and for github - Ignore tests dir in loc counting --- .github/scripts/publish_loc.sh | 7 ++++-- .github/workflows/loc.yaml | 2 +- .gitignore | 4 +++- cmd/loc/src/main.rs | 43 +++++++++++++++++++++++++--------- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/.github/scripts/publish_loc.sh b/.github/scripts/publish_loc.sh index 4348fc335..3e57cfd6c 100644 --- a/.github/scripts/publish_loc.sh +++ b/.github/scripts/publish_loc.sh @@ -1,15 +1,18 @@ curl -X POST $url \ -H 'Content-Type: application/json; charset=utf-8' \ --data @- <> $GITHUB_STEP_SUMMARY - cat loc_report.md >> $GITHUB_STEP_SUMMARY + cat loc_report_github.txt >> $GITHUB_STEP_SUMMARY - name: Post results to ethrex L1 slack channel env: diff --git a/.gitignore b/.gitignore index 87bbcdadd..172ae1bd7 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,6 @@ levm_ef_tests_report.txt levm_ef_tests_summary_slack.txt levm_ef_tests_summary_github.txt levm_ef_tests_summary.txt -loc_report.md + +loc_report_slack.txt +loc_report_github.txt diff --git a/cmd/loc/src/main.rs b/cmd/loc/src/main.rs index 0b180b380..3eb15c074 100644 --- a/cmd/loc/src/main.rs +++ b/cmd/loc/src/main.rs @@ -11,18 +11,41 @@ fn main() { let config = Config::default(); let mut languages = Languages::new(); - languages.get_statistics(&[ethrex.clone()], &[], &config); + languages.get_statistics(&[ethrex.clone()], &["tests"], &config); let ethrex_loc = &languages.get(&LanguageType::Rust).unwrap(); let mut languages = Languages::new(); - languages.get_statistics(&[levm], &[], &config); + languages.get_statistics(&[levm], &["tests"], &config); let levm_loc = &languages.get(&LanguageType::Rust).unwrap(); let mut languages = Languages::new(); - languages.get_statistics(&[ethrex_l2], &[], &config); + languages.get_statistics(&[ethrex_l2], &["tests"], &config); let ethrex_l2_loc = &languages.get(&LanguageType::Rust).unwrap(); - let report = format!( + std::fs::write( + "loc_report_slack.txt", + slack_message(ethrex_loc.code, ethrex_l2_loc.code, levm_loc.code), + ) + .unwrap(); + std::fs::write( + "loc_report_github.txt", + github_step_summary(ethrex_loc.code, ethrex_l2_loc.code, levm_loc.code), + ) + .unwrap(); +} + +fn slack_message(ethrex_loc: usize, ethrex_l2_loc: usize, levm_loc: usize) -> String { + format!( + r#"*ethrex L1:* {}\n*ethrex L2:* {}\n*levm:* {}\n*ethrex (total):* {}"#, + ethrex_loc - ethrex_l2_loc - levm_loc, + ethrex_l2_loc, + levm_loc, + ethrex_loc, + ) +} + +fn github_step_summary(ethrex_loc: usize, ethrex_l2_loc: usize, levm_loc: usize) -> String { + format!( r#"``` ethrex loc summary ==================== @@ -31,11 +54,9 @@ ethrex L2: {} levm: {} ethrex (total): {} ```"#, - ethrex_loc.code - ethrex_l2_loc.code - levm_loc.code, - ethrex_l2_loc.code, - levm_loc.code, - ethrex_loc.code, - ); - - std::fs::write("loc_report.md", report).unwrap(); + ethrex_loc - ethrex_l2_loc - levm_loc, + ethrex_l2_loc, + levm_loc, + ethrex_loc, + ) }