Skip to content

Commit

Permalink
feat(l1, l2, levm): improve loc reporter (#1326)
Browse files Browse the repository at this point in the history
- Improves slack message
- Generate different messages for slack and for github
- Ignore tests dir in loc counting
  • Loading branch information
ilitteri authored Nov 28, 2024
1 parent f6d9f83 commit 3f223f8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .github/scripts/publish_loc.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
curl -X POST $url \
-H 'Content-Type: application/json; charset=utf-8' \
--data @- <<EOF
$(jq -n --arg text "$(cat loc_report.md)" '{
$(jq -n --arg text "$(cat loc_report_slack.txt)" '{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Weekly ethrex lines of code report"
"text": "Lines of Code Report"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/loc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Post results in summary
run: |
echo "# `ethrex` lines of code report" >> $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:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 32 additions & 11 deletions cmd/loc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
====================
Expand All @@ -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,
)
}

0 comments on commit 3f223f8

Please sign in to comment.