Skip to content

Commit

Permalink
Merging develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pearce8 committed Jan 8, 2024
2 parents fa765a6 + f6a1482 commit aea9180
Show file tree
Hide file tree
Showing 113 changed files with 1,533 additions and 83 deletions.
10 changes: 9 additions & 1 deletion .github/dependabot.yml
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"]
31 changes: 31 additions & 0 deletions .github/labeler.yml
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/**
184 changes: 184 additions & 0 deletions .github/workflows/bin/license
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)
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
docs: ${{ steps.filter.outputs.docs }}
style: ${{ steps.filter.outputs.style }}
run: ${{ steps.filter.outputs.run }}
license: ${{ steps.filter.outputs.license }}

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # @v2
Expand Down Expand Up @@ -49,6 +50,13 @@ jobs:
- 'configs/**'
- 'experiments/**'
- 'repo/**'
license:
- '.github/**'
- 'bin/**'
- 'configs/**'
- 'docs/**'
- 'experiments/**'
- 'repo/**'
docs:
if: ${{ needs.changes.outputs.docs == 'true' }}
Expand All @@ -64,3 +72,8 @@ jobs:
if: ${{ needs.changes.outputs.run == 'true' }}
needs: changes
uses: ./.github/workflows/run.yml

license:
if: ${{ needs.changes.outputs.license == 'true' }}
needs: changes
uses: ./.github/workflows/license.yml
14 changes: 8 additions & 6 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Build & Deploy docs site to GitHub Pages
on:
# This Workflow can be triggered manually
workflow_dispatch:
workflow_call:

jobs:
Expand All @@ -12,15 +10,15 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Setup Python
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: '.github/workflows/requirements/docs.txt'

- name: Setup GitHub Pages
id: pages
uses: actions/configure-pages@f156874f8191504dae5b037505266ed5dda6c382
uses: actions/configure-pages@1f0c5cde4bc74cd7e1254d0cb4de8d49e9068c7d

- name: Install Sphinx and Theme via Pip
run: |
Expand All @@ -30,8 +28,12 @@ jobs:
run: |
sphinx-build docs/ _build
- name: Check for Typos using Codespell
run: |
codespell
- name: Upload artifact
uses: actions/upload-pages-artifact@a753861a5debcf57bf8b404356158c8e1e33150c
uses: actions/upload-pages-artifact@0252fc4ba7626f0298f0cf00902a25c6afc77fa8
if: github.ref == 'refs/heads/develop'
with:
path: ./_build
Expand All @@ -52,4 +54,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@9dbe3824824f8a1377b8e298bafde1a50ede43e5
uses: actions/deploy-pages@7a9bd943aa5e5175aeb8502edcc6c1c02d398e10
21 changes: 21 additions & 0 deletions .github/workflows/label.yml
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
19 changes: 19 additions & 0 deletions .github/workflows/license.yml
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
13 changes: 13 additions & 0 deletions .github/workflows/nightly.yml
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
3 changes: 2 additions & 1 deletion .github/workflows/requirements/docs.txt
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
6 changes: 4 additions & 2 deletions .github/workflows/requirements/style.txt
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
Loading

0 comments on commit aea9180

Please sign in to comment.