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/README.md b/README.md index e7ed2b7..d83076b 100644 --- a/README.md +++ b/README.md @@ -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. 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 2e2bfbc..11a1049 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,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