From eb9a2b3383c738702e4d89971ce0da0207f668f7 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sun, 10 Mar 2024 17:44:59 +0300 Subject: [PATCH] i9 provide many exclude options (#13) * #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 --- README.md | 20 +++++++++++++------- action.yml | 22 +++++++++++----------- generate-badge.sh | 11 +++++++---- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 27fbb52..e7ed2b7 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/action.yml b/action.yml index 6d5c524..e1df65e 100644 --- a/action.yml +++ b/action.yml @@ -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 }} diff --git a/generate-badge.sh b/generate-badge.sh index 7b4f7b2..8ecd792 100755 --- a/generate-badge.sh +++ b/generate-badge.sh @@ -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