Skip to content

Commit

Permalink
[i14-15] Added options for output formatting (#17)
Browse files Browse the repository at this point in the history
#14 #15

Co-authored-by: Mikhail Epatko <m.epatko@jsa-group.ru>
  • Loading branch information
MikhailEpatko and Mikhail Epatko committed Mar 24, 2024
1 parent c4be3fd commit 1b4bf08
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 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
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 }}

18 changes: 14 additions & 4 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,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

0 comments on commit 1b4bf08

Please sign in to comment.