Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[i14-15] Added options for output formatting #17

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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