Skip to content

Commit

Permalink
i9 provide many exclude options (#13)
Browse files Browse the repository at this point in the history
* #9 Added multiline values into exclude option

* #9 test multiline values

* #9 test multiline values

* #9 test multiline values

* #9 test multiline values

* #9 test multiline values

* #9 Added multiline values into exclude option

* #9 Added multiline values into exclude option

* #9 Added multiline values into exclude option

* #9 Added multiline values into exclude option

---------

Co-authored-by: Mikhail Epatko <m.epatko@jsa-group.ru>
  • Loading branch information
MikhailEpatko and Mikhail Epatko committed Mar 10, 2024
1 parent 666394a commit eb9a2b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -25,14 +25,20 @@ 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.
# For exclude option we can use multiline strings if we want to pass multiple values.
# 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
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
22 changes: 11 additions & 11 deletions action.yml
Expand Up @@ -40,18 +40,18 @@ runs:
gem install hoc
pip install anybadge
$GITHUB_ACTION_PATH/generate-badge.sh \
-b $BEFORE \
-d $DIR \
-s $SINCE \
-o $OUTPUT_DIR \
-f $FILENAME \
-e $EXCLUDE
-b "$BEFORE" \
-d "$DIR" \
-s "$SINCE" \
-o "$OUTPUT_DIR" \
-f "$FILENAME" \
-e "$EXCLUDE"
shell: bash
env:
BEFORE: ${{ inputs.before }}
DIR: ${{ inputs.dir }}
EXCLUDE: ${{ inputs.exclude }}
SINCE: ${{ inputs.since }}
OUTPUT_DIR: ${{ inputs.output_dir }}
BEFORE: ${{ inputs.before }}
DIR: ${{ inputs.dir }}
EXCLUDE: ${{ inputs.exclude }}
SINCE: ${{ inputs.since }}
OUTPUT_DIR: ${{ inputs.output_dir }}
FILENAME: ${{ inputs.filename }}

11 changes: 7 additions & 4 deletions generate-badge.sh
Expand Up @@ -33,13 +33,16 @@ while getopts 'b:d:e:f:o:s:' opt; do
done

if [ "$Before" == '[]' ]; then Before="$(date +%F)"; fi
if [ "$Excld" != '[]' ]; then Exclude="$Excld"; fi

echo "$Dir ${Exclude[*]} $Since $Before"
if [ "$Excld" != '[]' ]; then
IFS=$'\n' read -rd '' -a array <<< "$Excld"
for word in "${array[@]}"; do
Exclude="${Exclude} -e $word"
done
fi

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 eb9a2b3

Please sign in to comment.