Skip to content

Commit

Permalink
feat: added "ignore-paths" which can be used to specify additional di…
Browse files Browse the repository at this point in the history
…rectories or files to ignore from the verification

Signed-off-by: Jonathan Swartz <[email protected]>
  • Loading branch information
swahtz committed Dec 17, 2024
1 parent b5bfdd4 commit da86494
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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

0 comments on commit da86494

Please sign in to comment.