Skip to content

Commit

Permalink
Proper number formatting (2factorauth#4442)
Browse files Browse the repository at this point in the history
  • Loading branch information
phallobst authored and kmpoppe committed Dec 17, 2019
1 parent 522df4d commit e17bb3f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions .tests/alexa.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/bin/bash

export LC_NUMERIC=en_US.UTF-8
format_number () {
numfmt --grouping "$@"
}

# Max allowed Alexa ranking
max_ranking=200000

formated_max_ranking="$( echo ${max_ranking} | sed -re 's/([0-9])([0-9]{3})($|[^0-9])/\1,\2\3/')"
formated_max_ranking="$(format_number ${max_ranking})"

# Check Alexa rank
check_rank () {
urls="$(git --no-pager diff origin/master..HEAD ../_data| grep ^+[[:space:]] | grep url | cut -c11-)"
urls="$(git --no-pager diff origin/master..HEAD ../_data| grep ^+[[:space:]] | grep url | cut -c11-)"

if [ -z "$urls" ]; then
echo "No URLs found."
Expand All @@ -24,7 +29,7 @@ check_rank () {
alexa_rank="$(ruby alexa.rb ${domain})"

# Format ranking with thousands separator
formated_rank="$(echo ${alexa_rank} | sed -re 's/([0-9])([0-9]{3})($|[^0-9])/\1,\2\3/')"
formated_rank="$(format_number ${alexa_rank})"

# Check if the site is unranked
if [ -z "$alexa_rank" ]; then
Expand All @@ -33,14 +38,14 @@ check_rank () {
fi

# Check if the rank is at or below 200K
if [ "$alexa_rank" -gt "$max_ranking" ]; then
echo "::error:: ${domain} has an Alexa ranking above ${formated_max_ranking}. (${formated_rank})"
exit 1
else
echo "${domain} has an Alexa ranking of ${formated_rank}."
fi

done
if [ "$alexa_rank" -gt "$max_ranking" ]; then
echo "::error:: ${domain} has an Alexa ranking above ${formated_max_ranking}. (${formated_rank})"
exit 1
else
echo "${domain} has an Alexa ranking of ${formated_rank}."
fi

done
}

check_rank

0 comments on commit e17bb3f

Please sign in to comment.