diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 803476d..01f25b8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/action.yml b/action.yml index e1df65e..1281922 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -45,7 +49,8 @@ runs: -s "$SINCE" \ -o "$OUTPUT_DIR" \ -f "$FILENAME" \ - -e "$EXCLUDE" + -e "$EXCLUDE" \ + -r "$ROUNDING" shell: bash env: BEFORE: ${{ inputs.before }} @@ -54,4 +59,5 @@ runs: SINCE: ${{ inputs.since }} OUTPUT_DIR: ${{ inputs.output_dir }} FILENAME: ${{ inputs.filename }} + ROUNDING: ${{ inputs.rounding }} diff --git a/generate-badge.sh b/generate-badge.sh index c0866e7..594390d 100755 --- a/generate-badge.sh +++ b/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" @@ -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 @@ -39,9 +42,16 @@ if [ "$Excld" != '[]' ]; then done fi -mkdir -p "$OutDir" - Count=$(hoc -d "$Dir" ${Exclude:+${Exclude[@]}} -s "$Since" -b "$Before" -f "int") echo "Hits of code: $Count" -anybadge -l "Hits of Code" -v "$Count" -f "$OutDir/$Filename" -c royalblue +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" + +mkdir -p "$OutDir" +anybadge -l "Hits of Code" -v "$Count" -f "$OutDir/$Filename" -o -c royalblue