Skip to content

Instantly share code, notes, and snippets.

@RobertoSchneiders
Last active June 15, 2018 22:26
Show Gist options
  • Save RobertoSchneiders/f8b319440accf3ad4da5 to your computer and use it in GitHub Desktop.
Save RobertoSchneiders/f8b319440accf3ad4da5 to your computer and use it in GitHub Desktop.
RubyCritic CI Script
#!/bin/sh
# Ruby Critic Threshold
threshold=99
# Run rubycritic analysis with json format
result="$(rubycritic app lib config -f json)"
exit_code=$?
if [ "$exit_code" != "0" ]; then
exit $exit_code
fi
# Parse the json result to obtain the score (ex: 96.6321545412)
score="$(echo $result | grep -oP '"score":([-1-9]{1,2}[.][0-9]*)}' | sed 's/[^0-9\.]*//g')"
# Format the score to 2 decimals (96.6321545412 -> 96.63)
score="$(printf "%.*f" 2 "$score")"
# Parse the score value into a integer (96.63 -> 96)
int_score="$(echo $score | cut -f1 -d".")"
if [ "$int_score" != "" ] && [ "$int_score" -gt "0" ]
then
if [ $int_score -lt $threshold ]
then
echo "Score ($score) is below the threshold ($threshold)\n"
exit 1
else
echo "Score: $score Threshold ($threshold)\n"
fi
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment