Skip to content

Commit

Permalink
Merge pull request #2 from MikhailEpatko/emi/i1-configure-output-file…
Browse files Browse the repository at this point in the history
…name

Add output directory and output filename configuration
  • Loading branch information
MikhailEpatko committed Mar 4, 2024
2 parents 560278b + b48d393 commit ddc393f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions README.md
Expand Up @@ -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)
Expand All @@ -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.
The badge will be generated into file ./output/hoc-badge.svg by default.

Use whatever tool you prefer to upload it somewhere.
14 changes: 13 additions & 1 deletion action.yml
Expand Up @@ -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:
Expand All @@ -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 }}

12 changes: 7 additions & 5 deletions 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

0 comments on commit ddc393f

Please sign in to comment.