Skip to content

Commit

Permalink
Merge pull request #32 from antmicro/rkol/extra-exts
Browse files Browse the repository at this point in the history
Allow for overriding file extensions to be checked by linter
  • Loading branch information
tgorochowik committed Mar 29, 2023
2 parents 0153ead + 08432b1 commit 5ccc03c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
```
You can provide optional arguments to specify paths, exclude paths,
You can provide optional arguments to specify paths, exclude paths, extensions of tested files,
a config file, Verible version and extra arguments for ``verible-verilog-lint``.
```yaml
Expand All @@ -49,6 +49,11 @@ a config file, Verible version and extra arguments for ``verible-verilog-lint``.
./rtl/some_file
extra_args: "--check_syntax=true"
verible_version: "v0.0-3100-gd75b1c47"
extensions: |
.sv
.v
.vh
.svh
github_token: ${{ secrets.GITHUB_TOKEN }}
```
Expand Down
17 changes: 12 additions & 5 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def unwrap_from_gha_string(args):
return elements


def find_sources_in_paths(paths):
'''Scan {paths} for Verilog and SystemVerilog files
def find_sources_in_paths(paths, exts):
'''Scan {paths} for files with extensions from set
'''
files = set()
for filename in paths:
# check if filename is a directory or a source file
if os.path.isdir(filename):
new_files = recursive_find({".v", ".sv"}, filename)
new_files = recursive_find(exts, filename)
files.update(new_files)
elif os.path.isfile(filename):
files.add(filename)
Expand All @@ -72,12 +72,14 @@ def find_sources_in_paths(paths):
help='extra options for the linter')
@click.option('--exclude-paths', '-x', required=False,
help='exclude these paths from the files to lint')
@click.option('--extensions', '-t', type=str, required=False,
help='lint files with these extensions (starting with a dot, split by comma)')
@click.option('--log-file', '-l', type=str, required=False,
help='log file name')
@click.option('--patch', '-p', type=str, required=False,
help='patch file name')
@click.argument('path', nargs=-1, required=True)
def main(conf_file, extra_opts, exclude_paths, log_file, patch, path):
def main(conf_file, extra_opts, exclude_paths, extensions, log_file, patch, path):
'''
Lint .v and .sv files specified in PATHs
'''
Expand All @@ -96,9 +98,14 @@ def main(conf_file, extra_opts, exclude_paths, log_file, patch, path):
else:
patch = []

if extensions:
extensions = set(ext if ext.startswith('.') else '.' + ext for ext in extensions.split())
else:
extensions = {'.v', '.sv'}

paths = unwrap_from_gha_string(path)
# set of target files to lint
files = find_sources_in_paths(paths)
files = find_sources_in_paths(paths, extensions)

if exclude_paths:
for p in exclude_paths.split():
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ inputs:
exclude_paths:
description: 'Exclude these paths after finding all target files'
required: false
extensions:
description: 'Run linting on files ending with following extensions'
required: false
default: ''
log_file:
description: 'Name for a log file'
required: false
Expand Down Expand Up @@ -66,6 +70,7 @@ runs:
INPUT_CONFIG_FILE: ${{ inputs.config_file }}
INPUT_EXCLUDE_PATHS: ${{ inputs.exclude_paths }}
INPUT_EXTRA_ARGS: ${{ inputs.extra_args }}
INPUT_EXTENSIONS: ${{ inputs.extensions }}
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
INPUT_LOG_FILE: ${{ inputs.log_file }}
Expand Down
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ if [ "$INPUT_SUGGEST_FIXES" = "true" ]; then
--conf-file "$INPUT_CONFIG_FILE" \
--extra-opts "$INPUT_EXTRA_ARGS" \
--exclude-paths "$INPUT_EXCLUDE_PATHS" \
--extensions "$INPUT_EXTENSIONS" \
--log-file "$INPUT_LOG_FILE" \
--patch "$patch" \
"$INPUT_PATHS"
Expand All @@ -55,6 +56,7 @@ else
--conf-file "$INPUT_CONFIG_FILE" \
--extra-opts "$INPUT_EXTRA_ARGS" \
--exclude-paths "$INPUT_EXCLUDE_PATHS" \
--extensions "$INPUT_EXTENSIONS" \
--log-file "$INPUT_LOG_FILE" \
"$INPUT_PATHS"

Expand Down

0 comments on commit 5ccc03c

Please sign in to comment.