Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 'ignore-paths' #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ inputs:
Apache-2.0 WITH LLVM-exception
required: true
default: ''
ignore-paths:
description: >
A newline-separated list of any paths to ignore. For example:

ignore-paths: |-
src/generated/
src/ignore-file.md
required: false
default: ''
runs:
using: "composite"
steps:
- run: echo "${{ inputs.licenses }}" | xargs -d "\n" $GITHUB_ACTION_PATH/verify-spdx-headers
shell: bash
env:
INPUT_IGNORE_PATHS: ${{ inputs.ignore-paths }}
19 changes: 14 additions & 5 deletions verify-spdx-headers
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class Index:
'.sh': 'shell',
}

def __init__(self):
def __init__(self, ignore_paths = {}):
self.__ignore_paths = { "./.git" }.union(ignore_paths)
self.__languages = {
'python': Language('#+', shebang=True),
'ruby': Language('#+', shebang=True),
Expand Down Expand Up @@ -96,16 +97,18 @@ class Index:
return self.__languages.get(name)

def scan(self, root):
IGNORE_DIRS = { ".git" }

for root, dirs, files in os.walk(root):
# Ignore the specified directories.
for dir in IGNORE_DIRS.intersection(dirs):
dirs.remove(dir)
for dir in self.__ignore_paths.intersection({os.path.join(root, d) for d in dirs}):
dirs.remove(os.path.basename(dir))

for file in files:
path = os.path.join(root, file)

# If the file is in the ignore list, skip it.
if path in self.__ignore_paths:
continue
# If the file is a symlink, don't bother
if os.path.islink( path ):
continue
Expand Down Expand Up @@ -135,8 +138,14 @@ if __name__ == '__main__':
print("Invalid license '%s'!" % license)
raise SystemExit(1)

ignore_paths = os.getenv('INPUT_IGNORE_PATHS')
if ignore_paths is not None:
ignore_paths = {"./"+p.strip() for p in ignore_paths.split("\n")}
else:
ignore_paths = {}

rv = 0
index = Index()
index = Index(ignore_paths = ignore_paths)
for (path, license) in index.scan("."):
if license not in licenses:
if license == None:
Expand Down
Loading