Skip to content

Commit

Permalink
[i14-15] Added options: decimal separator and rounding mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Epatko committed Mar 24, 2024
1 parent 118c2c4 commit 6e5516b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Expand Up @@ -20,6 +20,7 @@ jobs:
dir: .
since: 2000-01-01
output_dir: output-dir
rounding: K
- uses: peaceiris/actions-gh-pages@v3.9.3
with:
publish_dir: output-dir
Expand Down
17 changes: 13 additions & 4 deletions README.md
Expand Up @@ -34,11 +34,20 @@ jobs:
# In this case it's an important detail that we used '|' or '|-' in the YAML.
# There is no default value for exclude option.
exclude: |
dir1/**
dir2/**/*
dir3/file.txt
dir1/**
dir2/**/*
dir3/file.txt
output_dir: ./output # Default value: './output'.
filename: hoc-badge.svg # Default value: 'hoc-badge.svg'.
filename: hoc-badge.svg # Default value: 'hoc-badge.svg'
# Rounding mode:
# I - integers (default)
# K - up to thousands
# M - up to millions
# G - up to billions
rounding:
description: 'Rounding mode. Default: I'
required: false
default: 'I'
```

The badge will be generated into the file ./output/hoc-badge.svg by default.
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Expand Up @@ -25,6 +25,10 @@ inputs:
description: 'Output filename. Default: hoc-badge.svg'
required: false
default: 'hoc-badge.svg'
rounding:
description: 'Rounding mode. Default: I'
required: false
default: 'I'

runs:
using: "composite"
Expand All @@ -45,7 +49,8 @@ runs:
-s "$SINCE" \
-o "$OUTPUT_DIR" \
-f "$FILENAME" \
-e "$EXCLUDE"
-e "$EXCLUDE" \
-r "$ROUNDING"
shell: bash
env:
BEFORE: ${{ inputs.before }}
Expand All @@ -54,4 +59,5 @@ runs:
SINCE: ${{ inputs.since }}
OUTPUT_DIR: ${{ inputs.output_dir }}
FILENAME: ${{ inputs.filename }}
ROUNDING: ${{ inputs.rounding }}

17 changes: 11 additions & 6 deletions generate-badge.sh
@@ -1,6 +1,6 @@
#!/bin/bash

while getopts 'b:d:e:f:o:s:' opt; do
while getopts 'b:d:e:f:o:s:r:' opt; do
case "$opt" in
b)
Before="$OPTARG"
Expand All @@ -21,6 +21,9 @@ while getopts 'b:d:e:f:o:s:' opt; do
s)
Since="$OPTARG"
;;
r)
Rounding="$OPTARG"
;;
:)
echo "Usage: $(basename "$0") [-b Before] [-d Dir] [-e Exclude] [-f Filename] [-o OutputDir] [-s Since]"
exit 1
Expand All @@ -39,13 +42,15 @@ if [ "$Excld" != '[]' ]; then
done
fi

mkdir -p "$OutDir"

Count=$(hoc -d "$Dir" ${Exclude:+${Exclude[@]}} -s "$Since" -b "$Before" -f "int")

export LC_NUMERIC="en_US"
Count=$(printf "%'d" "$Count")
if [ "$Rounding" == "K" ]; then Count="$(python -c "print(round($Count/1000, 1))")K"
elif [ "$Rounding" == "M" ]; then Count="$(python -c "print(round($Count/1000000, 1))")M"
elif [ "$Rounding" == "G" ]; then Count="$(python -c "print(round($Count/1000000000, 1))")G"
else Count=$(python -c "print(format($Count, ',d'))")
fi

echo "Hits of code: $Count"

#anybadge -l "Hits of Code" -v "$Count" -f "$OutDir/$Filename" -c royalblue
mkdir -p "$OutDir"
anybadge -l "Hits of Code" -v "$Count" -f "$OutDir/$Filename" -o -c royalblue

0 comments on commit 6e5516b

Please sign in to comment.