Last active
February 2, 2021 18:08
-
-
Save NerOcrO/a61c4b46fadde2948c265bfa502cc13a to your computer and use it in GitHub Desktop.
metriques bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -z $1 ]]; then | |
chemin_de_base=. | |
else | |
chemin_de_base=$1 | |
fi | |
################################################################################ | |
# REPOSITORY # | |
################################################################################ | |
cherche() { | |
expression=$1 | |
xargs grep -E "$expression" | |
} | |
fichiers_sans_tests() { | |
expression=$1 | |
if [[ -z $expression ]]; then | |
expression="(.*)\.j(sx|s)" | |
fi | |
find "${chemin_de_base}/src" -regextype posix-extended -regex "$expression" -not -path "*/__specs__/*" | |
} | |
fichiers_de_test() { | |
repertoire=$1 | |
expression=$2 | |
find "${chemin_de_base}/$repertoire" -regextype posix-extended -regex "$expression" | |
} | |
transforme_en_nombre_de_ligne() { | |
wc -l | |
} | |
suppression_espaces() { | |
xargs | |
} | |
derniere_ligne() { | |
tail -n1 | |
} | |
premieres_lignes() { | |
head -n$1 | tail -n $(($1-1)) | |
} | |
trier_par_ordre_croissant() { | |
sort -nr | |
} | |
premiere_element_de_la_ligne() { | |
cut -d ' ' -f1 | |
} | |
################################################################################ | |
# DOMAIN # | |
################################################################################ | |
# Global | |
nombre_de_fichier=$(fichiers_sans_tests | transforme_en_nombre_de_ligne) | |
nombre_de_lignes=$(wc -l `fichiers_sans_tests` | derniere_ligne | suppression_espaces | premiere_element_de_la_ligne) | |
poids_totale_des_fichiers=$(wc -c `fichiers_sans_tests` | derniere_ligne | premiere_element_de_la_ligne) | |
top_des_fichiers_avec_le_plus_de_lignes=$(wc -l `fichiers_sans_tests` | trier_par_ordre_croissant | premieres_lignes 15) | |
# Tests | |
nombre_de_test_unitaire=$(fichiers_de_test "src" "(.*)\.spec\.(.*)" | cherche " it\(" | transforme_en_nombre_de_ligne) | |
nombre_de_fichier_test_unitaire=$(fichiers_de_test "src" "(.*)\.spec\.(.*)" | transforme_en_nombre_de_ligne) | |
nombre_de_mock=$(fichiers_de_test "src" "(.*)\.spec\.(.*)" | cherche "toHaveBeenCalled" | transforme_en_nombre_de_ligne) | |
nombre_de_test_end2end=$(fichiers_de_test "testcafe" "(.*)\.js" | cherche "test\(" | transforme_en_nombre_de_ligne) | |
nombre_de_fichier_de_test_end2end=$(fichiers_de_test "testcafe" "(.*)\.js" | transforme_en_nombre_de_ligne) | |
# SonarQube | |
nombre_de_function=$(fichiers_sans_tests | cherche "function " | transforme_en_nombre_de_ligne) | |
nombre_de_arrow_function=$(fichiers_sans_tests | cherche "const (.*) = [a-zA-Z0-9 \(\),_]+ => " | transforme_en_nombre_de_ligne) | |
nombre_de_fonction=$((nombre_de_function + nombre_de_arrow_function)) | |
nombre_de_classe=$(fichiers_sans_tests | cherche "class " | transforme_en_nombre_de_ligne) | |
nombre_de_composant=$(fichiers_sans_tests "(.*)\.jsx" | transforme_en_nombre_de_ligne) | |
################################################################################ | |
# APPLICATION # | |
################################################################################ | |
highlight="\e[0;32m" | |
information="\e[0;36m" | |
reset="\e[0m" | |
# Il peut y avoir un delta en fonction de la regex. | |
printf " | |
${information}Global${reset} | |
${highlight}${nombre_de_fichier}${reset} fichiers dont ${highlight}$(printf "%'d" ${nombre_de_lignes})${reset} lignes pour ${highlight}$(printf "%'d" ${poids_totale_des_fichiers})${reset} octets au total | |
Un fichier fait en moyenne ${highlight}$(printf "%'d" $((poids_totale_des_fichiers / nombre_de_lignes)))${reset} lignes | |
Un fichier fait en moyenne ${highlight}$(printf "%'d" $((poids_totale_des_fichiers / nombre_de_fichier)))${reset} octets | |
Top 15 des fichiers avec le plus de lignes | |
${top_des_fichiers_avec_le_plus_de_lignes} | |
${information}Tests${reset} | |
${highlight}$(printf "%'d" ${nombre_de_test_unitaire})${reset} tests unitaires dans ${highlight}${nombre_de_fichier_test_unitaire}${reset} fichiers | |
Moyenne de ${highlight}$((nombre_de_test_unitaire / nombre_de_fichier_test_unitaire))${reset} tests unitaires par fichier | |
Dont ${highlight}${nombre_de_mock}${reset} mocks (${information}essayer de les réduire car couplage fort avec l'implémentation${reset}) | |
${highlight}${nombre_de_test_end2end}${reset} tests end2end dans ${highlight}${nombre_de_fichier_de_test_end2end}${reset} fichiers | |
Moyenne de ${highlight}$((nombre_de_test_end2end / nombre_de_fichier_de_test_end2end))${reset} tests end2end par fichier | |
${information}SonarQube${reset} | |
${highlight}${nombre_de_fonction}${reset} fonctions | |
${highlight}${nombre_de_classe}${reset} classes | |
${highlight}${nombre_de_composant}${reset} composants | |
" | |
# Mediane : Classer par ordre croissant et prendre celui du milieu | |
# echo -e '1\n2\n4\n3\n1\9' | sort -n | awk '{arr[NR]=$1} END { if (NR%2==1) print arr[(NR+1)/2]; else print (arr[NR/2]+arr[NR/2+1])/2}' | |
# top 10 de fichier avec le plus de dépendance => new ou import | |
# hotspot : https://docs.enterprise.codescene.io/versions/4.3.3/guides/technical/hotspots.html | |
# Datastudio | |
# Pourquoi ? Risquée: tests, commiters (turnover), taille des fichiers, distribué (couplage entre repo - comparaison des fréquences de changement de plusieurs repos), et (a venir couplage d’un fichier avec un fan-in fan-out) | |
# Par quoi on commence? Les hotspots sont des bons candidats | |
# L’utilisation se fait surtout en mode présentation avec l’équipe concernée pour avoir des échanges: « alors ici j’ai mesuré ça. Ça vous parle? » | |
# cat yarn.lock | awk 'BEGIN {} /^[^ ](.*)@/ {cpt++; print $1} END {print cpt" modules"}' | |
# 2047 modules | |
# cat yarn.lock | grep -Eo "^[^ ][a-z0-9_/@\"\.\-]*@" | |
# 2047 modules | |
# Détecter le nombre de module identique dans yarn.lock | |
# Taille PR | |
# Moyenne de commentaire par PR | |
# Taille commit | |
# Taille fonction/classe | |
# awk - pattern scanning and text processing language | |
# cut - print selected parts of lines from each FILE to standard output | |
# head - output the first part of files | |
# sed - | |
# seq - print numbers from FIRST to LAST, in steps of INCREMENT | |
# shuf - write a random permutation of the input lines to standard output | |
# sort - write sorted concatenation of all FILE(s) to standard output | |
# tail - output the last part of files | |
# tr - translate, squeeze, and/or delete characters from standard input, writing to standard output | |
# wc - print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified | |
# trim => "| xargs" | |
# nombre_de_tests_python=$(find "pass-culture-main/api/tests/" -type f | xargs grep -E "def test_|def should_|def when_|def expect_" | wc -l) | |
# nombre_de_fichier_python1=$(find "pass-culture-main/api/tests/" -name "*_test.py" | wc -l) | |
# nombre_de_fichier_python2=$(find "pass-culture-main/api/tests/" -name "test_*.py" | wc -l) | |
# nombre_de_fichier_python=$((nombre_de_fichier_python1 + nombre_de_fichier_python2)) | |
# echo "${nombre_de_tests_python} tests Python" | |
# c'est à cause de pytest.mark.parametrize qui est lancé plusieurs fois si pas le même nombre | |
# echo "${nombre_de_fichier_python} fichiers de test Python" | |
# echo "Il y a donc une moyenne de $((nombre_de_tests_python / nombre_de_fichier_python)) tests par fichier de test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment