Skip to content

Commit

Permalink
[util] Add script to check functioning of BLOCKFILE
Browse files Browse the repository at this point in the history
The new script outputs warnings if any pattern in the BLOCKFILE doesn't
match a file in the repository tree along with a full list of files in
the repository tree that are blocked.

Signed-off-by: Greg Chadwick <[email protected]>
  • Loading branch information
GregAC authored and moidx committed May 13, 2023
1 parent ec955da commit 83d9d66
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
38 changes: 35 additions & 3 deletions ci/scripts/check-pr-changes-allowed.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ def main() -> int:
help='Name of the repository on github to read PR comments from',
default='lowrisc/opentitan')

arg_parser.add_argument(
'--plain-block-msg',
help='''Just outputs the path of each blocked file with no further
information''',
action='store_true')

arg_parser.add_argument(
'--report-unused-patterns',
help='Produces a list of block patterns that did not block anything',
action='store_true')

args = arg_parser.parse_args()

blocklist = load_blockfile(args.block_file)
Expand Down Expand Up @@ -184,16 +195,37 @@ def main() -> int:
authorizers = ', '.join(
[f'{committers[handle]} ({handle})' for handle in
authorized_changes[change]])
print(f'{change} change is authorized by {authorizers}')

if not args.plain_block_msg:
print(f'{change} change is authorized by {authorizers}')

if args.report_unused_patterns:
unused_patterns = set(blocklist)

used_patterns = set(sum(blocked_changes.values(), []))
unused_patterns = set(blocklist) - used_patterns

if unused_patterns:
print('WARNING: Unused patterns have been found:')

for pattern in unused_patterns:
print(pattern)

print('')

if blocked_changes:
# If there are blocked changes present print out what's been blocked and
# the pattern(s) that blocked it and return error code 1
for change, block_patterns in blocked_changes.items():
patterns_str = ' '.join(block_patterns)
print(f'{change} blocked by pattern(s): {patterns_str}')
if args.plain_block_msg:
print(change)
else:
print(f'{change} blocked by pattern(s): {patterns_str}')

if not args.plain_block_msg:
print('UNAUTHORIZED CHANGES PRESENT, PR cannot be merged!')

print('UNAUTHORIZED CHANGES PRESENT, PR cannot be merged!')
return 1

print('No unauthorized changes, clear to merge')
Expand Down
17 changes: 17 additions & 0 deletions util/check-blockfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

echo "Checking BLOCKFILE. This will output all files blocked from changes and "
echo "a warning if there are any patterns in BLOCKFILES which don't match any "
echo "file. Must be run from repository root."

# Produce a list of all files, chop off the first two characters which as './'
# as the change blocker script doesn't work correctly with them.
find -type f | cut -c 3- > ot-filelist

./ci/scripts/check-pr-changes-allowed.py \
--plain-block-msg \
--report-unused-patterns \
ot-filelist

0 comments on commit 83d9d66

Please sign in to comment.