1- #! /bin/bash
2- # Runs `pana . --no-warning` and verifies that the package score
3- # is greater or equal to the desired score. By default the desired score is
4- # a perfect score but it can be overridden by passing the desired score as an argument.
5- #
6- # Ensure the package has a score of at least a 100
7- # `./verify_pub_score.sh 100`
8- #
9- # Ensure the package has a perfect score
10- # `./verify_pub_score.sh`
11-
12- PANA=$( pana . --no-warning) ; PANA_SCORE=$( echo $PANA | sed -n " s/.*Points: \([0-9]*\)\/\([0-9]*\)./\1\/\2/p" )
13- echo " score: $PANA_SCORE "
14- IFS=' /' ; read -a SCORE_ARR <<< " $PANA_SCORE" ; SCORE=SCORE_ARR[0]; TOTAL=SCORE_ARR[1]
15- if [ -z " $1 " ]; then MINIMUM_SCORE=TOTAL; else MINIMUM_SCORE=$1 ; fi
16- if (( $SCORE < $MINIMUM_SCORE )) ; then echo " minimum score $MINIMUM_SCORE was not met!" ; exit 1; fi
1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ # Runs `pana . --no-warning` and verifies the package score is >= desired score.
5+ # Usage:
6+ # ./verify_pub_score.sh # require perfect score
7+ # ./verify_pub_score.sh 100 # require at least 100 points
8+
9+ if ! PANA_OUTPUT=" $( pana . --no-warning) " ; then
10+ echo " pana failed (non-zero exit). Make sure 'pana' is installed and runs successfully." >&2
11+ exit 1
12+ fi
13+ readonly PANA_OUTPUT
14+
15+ if [[ ! $PANA_OUTPUT =~ Points:\ ([0-9]+)\/ ([0-9]+) ]]; then
16+ echo " Failed to parse pana output for Points: X/Y." >&2
17+ echo " pana output was:" >&2
18+ printf ' %s\n' " $PANA_OUTPUT " >&2
19+ exit 1
20+ fi
21+
22+ readonly SCORE=" ${BASH_REMATCH[1]} "
23+ readonly TOTAL=" ${BASH_REMATCH[2]} "
24+ readonly MINIMUM_SCORE=" ${1:- $TOTAL } "
25+
26+ if [[ ! " $MINIMUM_SCORE " =~ ^[0-9]+$ ]]; then
27+ echo " Minimum score must be a non-negative integer. Got: '$MINIMUM_SCORE '." >&2
28+ exit 1
29+ fi
30+
31+ if (( MINIMUM_SCORE > TOTAL )) ; then
32+ echo " Warning: requested minimum (${MINIMUM_SCORE} ) is greater than maximum possible (${TOTAL} )." >&2
33+ fi
34+
35+ echo " score: ${SCORE} /${TOTAL} "
36+
37+ if (( SCORE < MINIMUM_SCORE )) ; then
38+ echo " Minimum score ${MINIMUM_SCORE} was not met (actual ${SCORE} )." >&2
39+ exit 1
40+ fi
0 commit comments