-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
113 changed files
with
1,533 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
versions: 2 | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
- package-ecosystem: "pip" | ||
directory: "/.github/workflows/requirements" | ||
schedule: | ||
interval: "weekly" | ||
ignore: | ||
# setuptools releases new versions almost daily | ||
- dependency-name: "setuptools" | ||
update-types: ["version-update:semver-patch"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
application: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- repo/** | ||
|
||
ci: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- .github/** | ||
|
||
configs: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- configs/** | ||
|
||
dependencies: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- .github/worklflows/requirements/** | ||
- pyproject.toml | ||
|
||
docs: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- docs/** | ||
- README.rst | ||
|
||
experiment: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- experiments/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
#!/bin/env python3 | ||
# | ||
# Copyright 2023 Lawrence Livermore National Security, LLC and other | ||
# Benchpark Project Developers. See the top-level COPYRIGHT file for details. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import print_function | ||
|
||
import os | ||
import re | ||
import sys | ||
from collections import defaultdict | ||
|
||
#: SPDX license id must appear in the first <license_lines> lines of a file | ||
license_lines = 7 | ||
|
||
#: Benchpark's license identifier | ||
apache_spdx = "Apache-2.0" | ||
|
||
#: regular expressions for licensed files. | ||
licensed_files = [ | ||
r"^bin\/benchpark", | ||
r"^configs\/[^\/]*\/[^\/]*", | ||
r"^docs\/[^\/]*\.rst$", | ||
r"^experiments\/[^\/]*\/[^\/]*", | ||
r"^repo\/[^\/]*\/[^\/]*", | ||
] | ||
|
||
|
||
def _all_files(root="."): | ||
"""Generates root-relative paths of all files in the repository.""" | ||
visited = set() | ||
for cur_root, folders, files in os.walk(root): | ||
for filename in files: | ||
path = os.path.realpath(os.path.join(cur_root, filename)) | ||
|
||
if path not in visited: | ||
yield os.path.relpath(path, root) | ||
visited.add(path) | ||
|
||
|
||
def _licensed_files(root): | ||
for relpath in _all_files(root): | ||
if any(regex.match(relpath) for regex in licensed_files): | ||
yield relpath | ||
|
||
|
||
def list_files(root): | ||
"""List files that should have license headers""" | ||
for relpath in sorted(_licensed_files(root)): | ||
print(os.path.join(".", relpath)) | ||
|
||
|
||
# Error codes for license verification. All values are chosen such that | ||
# bool(value) evaluates to True | ||
SPDX_MISMATCH, GENERAL_MISMATCH, COPYRIGHT_YEAR_MISMATCH = range(1, 4) | ||
|
||
#: Latest year that copyright applies. UPDATE THIS when bumping copyright. | ||
latest_year = 2023 | ||
strict_date = r"Copyright %s" % latest_year | ||
|
||
#: regexes for valid license lines at tops of files | ||
license_line_regexes = [ | ||
r"Copyright (%d|[0-9]{4}) Lawrence Livermore National Security, LLC and other" | ||
% latest_year, | ||
r"Benchpark Project Developers. See the top-level COPYRIGHT file for details.", | ||
r"SPDX-License-Identifier: Apache-2.0", | ||
] | ||
|
||
|
||
class LicenseError(object): | ||
def __init__(self): | ||
self.error_counts = defaultdict(int) | ||
|
||
def add_error(self, error): | ||
self.error_counts[error] += 1 | ||
|
||
def has_errors(self): | ||
return sum(self.error_counts.values()) > 0 | ||
|
||
def error_messages(self): | ||
total = sum(self.error_counts.values()) | ||
missing = self.error_counts[GENERAL_MISMATCH] | ||
spdx_mismatch = self.error_counts[SPDX_MISMATCH] | ||
copyright_year_mismatch = self.error_counts[COPYRIGHT_YEAR_MISMATCH] | ||
return ( | ||
"%d improperly licensed files\n" % (total), | ||
"files with wrong SPDX-License-Identifier: %d\n" % spdx_mismatch, | ||
"files not containing expected license: %d\n" % missing, | ||
"files with wrong copyright year: %d\n" % copyright_year_mismatch, | ||
) | ||
|
||
|
||
def _check_license(lines, path): | ||
found = [] | ||
|
||
for line in lines: | ||
line = re.sub(r"^[\s#\%\.\!\/\/]*", "", line) | ||
line = line.rstrip() | ||
for i, line_regex in enumerate(license_line_regexes): | ||
if re.match(line_regex, line): | ||
# The first line of the license contains the copyright date. | ||
# We allow it to be out of date but print a warning if it is | ||
# out of date. | ||
if i == 0: | ||
if not re.search(strict_date, line): | ||
print("{0}: Copyright date mismatch".format(path)) | ||
return COPYRIGHT_YEAR_MISMATCH | ||
found.append(i) | ||
|
||
if len(found) == len(license_line_regexes) and found == list(sorted(found)): | ||
return | ||
|
||
# If the SPDX identifier is present, then there is a mismatch (since it | ||
# did not match the above regex) | ||
def wrong_spdx_identifier(line, path): | ||
m = re.search(r"SPDX-License-Identifier: [^\n]*", line) | ||
if m and m.group(1) != apache_spdx: | ||
print( | ||
"{0}: SPDX license identifier mismatch" | ||
"(expecting {1}, found {2})".format(path, apache_spdx, m.group(1)) | ||
) | ||
return SPDX_MISMATCH | ||
else: | ||
print("{0}: SPDX license identifier missing".format(path)) | ||
return GENERAL_MISMATCH | ||
|
||
checks = [wrong_spdx_identifier] | ||
|
||
for line in lines: | ||
for check in checks: | ||
error = check(line, path) | ||
if error: | ||
return error | ||
|
||
print( | ||
"{0}: the license header at the top of the file does not match the" | ||
" expected format".format(path) | ||
) | ||
return GENERAL_MISMATCH | ||
|
||
|
||
def verify(root): | ||
"""Verify that files have the right license header""" | ||
|
||
license_errors = LicenseError() | ||
|
||
for relpath in _licensed_files(root): | ||
path = os.path.join(root, relpath) | ||
with open(path) as f: | ||
lines = [line for line in f][:license_lines] | ||
|
||
error = _check_license(lines, path) | ||
if error: | ||
license_errors.add_error(error) | ||
|
||
if license_errors.has_errors(): | ||
print(*license_errors.error_messages()) | ||
sys.exit(1) | ||
else: | ||
print("No license issues found.") | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
valid_options = ["list-files", "verify"] | ||
|
||
if len(sys.argv) != 2: | ||
print("Please specify a valid option: {}".format(valid_options)) | ||
sys.exit() | ||
|
||
cmd = sys.argv[1] | ||
if cmd not in valid_options: | ||
print("Invalid argument. Valid options are {}".format(valid_options)) | ||
sys.exit() | ||
|
||
licensed_files[:] = [re.compile(regex) for regex in licensed_files] | ||
root = os.path.abspath(os.curdir) | ||
|
||
if cmd == "list-files": | ||
list_files(root) | ||
elif cmd == "verify": | ||
verify(root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#----------------------------------------------------------------------- | ||
# DO NOT modify unless you really know what you are doing. | ||
# | ||
# See https://stackoverflow.com/a/74959635 for more info. | ||
# Talk to @alecbcs if you have questions/are not sure of a change's | ||
# possible impact to security. | ||
#----------------------------------------------------------------------- | ||
name: label | ||
on: | ||
pull_request_target: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
pr: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: License Checks | ||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
verify-license: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | ||
|
||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c | ||
with: | ||
python-version: '3.11' | ||
cache: 'pip' | ||
|
||
- name: Verify license headers | ||
run: | | ||
python .github/workflows/bin/license verify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: nightly | ||
on: | ||
schedule: | ||
- cron: '0 14 * * *' | ||
|
||
#------------------------------------------------------------------------ | ||
# Execute a nightly CI run to verify benchmarks continue to build & run | ||
# sucessfully. Will also update the CI buildcache to minimize build | ||
# times in PRs. | ||
#------------------------------------------------------------------------ | ||
jobs: | ||
run: | ||
uses: ./.github/workflows/run.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# docs | ||
sphinx==7.2.6 | ||
sphinx-rtd-theme==1.3.0 | ||
sphinx-rtd-theme==2.0.0 | ||
codespell==2.2.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
black==23.10.1 | ||
flake8==6.1.0 | ||
black==23.12.1 | ||
flake8==7.0.0 | ||
isort==5.13.2 | ||
codespell==2.2.6 |
Oops, something went wrong.