Skip to content

Commit

Permalink
#9 Added multiline values into exclude option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Epatko committed Mar 10, 2024
1 parent 666394a commit 0d536bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 10 additions & 7 deletions README.md
Expand Up @@ -25,14 +25,17 @@ jobs:
steps:
- uses: actions/checkout@v4
- id: badge-generator
uses: ./ # write the action name instead
uses: ./ # Write the action name instead.
with:
before: 2024-03-03' # default value - now day
dir: . # default value - include all files
exclude: vendor/** # no default value
since: 2000-01-01 # default value - '2000-01-01'
output_dir: ./output # default value - 'output'
filename: hoc-badge.svg # default value - 'hoc-badge.svg'
since: 2000-01-01 # Default value: '2000-01-01'.
before: 2024-03-03' # Default value: now day.
dir: . # Default value: include all files in the current directory.
exclude: |- # We can use multiline strings if we want something close to multiline values.
dir1/** ## It's an important detail that we used '|-' in the YAML and not '|'.
dir2/**/* ## There is no default value for exclude option.
dir3/file.txt
output_dir: ./output # Default value: './output'.
filename: hoc-badge.svg # Default value: 'hoc-badge.svg'.
```

The badge will be generated into the file ./output/hoc-badge.svg by default.
Expand Down
9 changes: 7 additions & 2 deletions generate-badge.sh
Expand Up @@ -33,13 +33,18 @@ while getopts 'b:d:e:f:o:s:' opt; do
done

if [ "$Before" == '[]' ]; then Before="$(date +%F)"; fi
if [ "$Excld" != '[]' ]; then Exclude="$Excld"; fi
if [ "$Excld" != '[]' ]; then
IFS=$'\n' read -rd '' -a array <<< "$Excld"
for word in "${array[@]}"; do
Exclude="${Exclude} -e $word"
done
fi

echo "$Dir ${Exclude[*]} $Since $Before"

mkdir -p "$OutDir"

Count=$(hoc -d "$Dir" ${Exclude:+"-e ${Exclude[@]}"} -e "${Exclude[@]}" -s "$Since" -b "$Before" -f "int")
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

0 comments on commit 0d536bd

Please sign in to comment.