diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3bd669f..b8401b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,8 +10,10 @@ jobs: - id: badge-generator uses: ./ with: - dir: '.' - since: '2000-01-01' + dir: . + since: 2000-01-01 + output_dir: ./output + filename: hits.svg - name: Deploy to image-data branch uses: peaceiris/actions-gh-pages@v3.9.3 diff --git a/README.md b/README.md index c2778ff..59b5c61 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ GitHub action to generate Hits-of-Code badge with hoc calculated metric. **hoc** - is a command line tool to calculate Hits-of-Code metric in a source code repository (at the moment it supports Git 2+ and Subversion 1.7+). + You can read more about Hits-of-Code metric in this blog post: [Hits-of-Code Instead of SLoC](http://www.yegor256.com/2014/11/14/hits-of-code.html). [**hoc** project page](https://github.com/yegor256/hoc/tree/master) @@ -21,12 +22,16 @@ 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' + 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' ``` -The badge will be generated in ./output/hits.svg file. Use whatever tool you prefer to upload it somewhere. \ No newline at end of file +The badge will be generated into file ./output/hoc-badge.svg by default. + +Use whatever tool you prefer to upload it somewhere. \ No newline at end of file diff --git a/action.yml b/action.yml index 230be06..1d6897e 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,15 @@ inputs: description: 'Set the start date of hoc (YYYY-MM-DD). Default: 2000-01-01' required: false default: '2000-01-01' + output_dir: + description: 'Output directory. Default: ./output' + required: false + default: './output' + filename: + description: 'Output filename. Default: hoc-badge.svg' + required: false + default: 'hoc-badge.svg' + runs: using: "composite" steps: @@ -29,10 +38,13 @@ runs: gem install hoc pip install anybadge mkdir ./output - $GITHUB_ACTION_PATH/generate-badge.sh $BEFORE $DIR $EXCLUDE $SINCE + $GITHUB_ACTION_PATH/generate-badge.sh $BEFORE $DIR $EXCLUDE $SINCE $OUTPUT_DIR $FILENAME shell: bash env: 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 907ebee..75cb271 100755 --- a/generate-badge.sh +++ b/generate-badge.sh @@ -1,11 +1,13 @@ #!/bin/bash if [ "$1" == '[]' ]; then Before="$(date +%F)"; else Before=$1; fi -if [ "$2" == '[]' ]; then Dir='.'; else Dir=$2; fi -if [ "$3" == '[]' ]; then Exclude=[]; else Exclude=$3; fi -if [ "$4" == '[]' ]; then Since='2000-01-01'; else Since=$4; fi +Dir=$2 +Exclude=$3 +Since=$4 +OutDir=$5 +Filename=$6 -Count=$(hoc -d "$Dir" -e "$Exclude" -s "$Since" -b "$Before" -f 'int' ) +Count=$(hoc -d "$Dir" -e "$Exclude" -s "$Since" -b "$Before" -f "int") echo "Hits of code: $Count" -anybadge -l "Hits of Code" -v "$Count" -f ./output/hits.svg -c royalblue +anybadge -l "Hits of Code" -v "$Count" -f "$OutDir/$Filename" -c royalblue