Last active
August 29, 2015 14:17
-
-
Save lisotton/4374423e3dd5ee389cd5 to your computer and use it in GitHub Desktop.
Extract Flay, Flog and SimpleCov metrics from Ruby project and post a JSON with these metrics in some webservice.
This file contains 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
TOTAL_COVERAGE=$(grep -i covered_percent coverage/index.html | head -n 1 | sed -n 's/.*>\([0-9]\+\.[0-9]\+\).*/\1/p') | |
CONTROLLERS_COVERAGE=$(awk '/group_name.+Controllers/{getline; print}' coverage/index.html | sed -n 's/.*>\([0-9]\+\.[0-9]\+\).*/\1/p') | |
MODELS_COVERAGE=$(awk '/group_name.+Models/{getline; print}' coverage/index.html | sed -n 's/.*>\([0-9]\+\.[0-9]\+\).*/\1/p') | |
HELPERS_COVERAGE=$(awk '/group_name.+Helpers/{getline; print}' coverage/index.html | sed -n 's/.*>\([0-9]\+\.[0-9]\+\).*/\1/p') | |
UNGROUPED_COVERAGE=$(awk '/group_name.+Ungrouped/{getline; print}' coverage/index.html | sed -n 's/.*>\([0-9]\+\.[0-9]\+\).*/\1/p') | |
RELEVANT_LINES=$(grep -A3 "AllFiles" coverage/index.html | tail -1 | sed -n 's/.*>\([0-9]\+\).*/\1/p') | |
COVERED_LINES=$(grep -A4 "AllFiles" coverage/index.html | tail -1 | sed -n 's/.*>\([0-9]\+\).*/\1/p') | |
FLOG_OUTPUT=$(find app -name \*.rb | xargs bundle exec flog --score) | |
FLOG_TOTAL=$(echo "$FLOG_OUTPUT" | head -n 1 | sed -n 's/: flog total//p' | tr -d '[[:space:]]') | |
FLOG_METHOD_AVG=$(echo "$FLOG_OUTPUT" | head -n 2 | sed -n 's/: flog\/method average//p' | tr -d '[[:space:]]') | |
FLAY_SCORE=$(find app -name \*.rb | xargs bundle exec flay --summary | head -n 1 | sed -n 's/Total score (lower is better) =//p' | tr -d '[[:space:]]') | |
JSON_POST=$(echo "{'total_coverage':'$TOTAL_COVERAGE','controllers_coverage':'$CONTROLLERS_COVERAGE','models_coverage':'$TOTAL_COVERAGE','helpers_coverage':'$HELPERS_COVERAGE','ungrouped_coverage':'$UNGROUPED_COVERAGE','relevant_lines':'$RELEVANT_LINES','covered_lines':'$COVERED_LINES','flog_total':'$FLOG_TOTAL','flog_method_avg':'$FLOG_METHOD_AVG','flay_score':'$FLAY_SCORE','build_id':'$BUILD_NUMBER'}" | sed "s/'/\"/g") | |
curl -H "Content-Type: application/json" -H "key: YOUR_KEY" -d $JSON_POST http://example.com/metrics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment