Skip to content

Commit 83d9d66

Browse files
GregACmoidx
authored andcommitted
[util] Add script to check functioning of BLOCKFILE
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]>
1 parent ec955da commit 83d9d66

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

ci/scripts/check-pr-changes-allowed.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ def main() -> int:
157157
help='Name of the repository on github to read PR comments from',
158158
default='lowrisc/opentitan')
159159

160+
arg_parser.add_argument(
161+
'--plain-block-msg',
162+
help='''Just outputs the path of each blocked file with no further
163+
information''',
164+
action='store_true')
165+
166+
arg_parser.add_argument(
167+
'--report-unused-patterns',
168+
help='Produces a list of block patterns that did not block anything',
169+
action='store_true')
170+
160171
args = arg_parser.parse_args()
161172

162173
blocklist = load_blockfile(args.block_file)
@@ -184,16 +195,37 @@ def main() -> int:
184195
authorizers = ', '.join(
185196
[f'{committers[handle]} ({handle})' for handle in
186197
authorized_changes[change]])
187-
print(f'{change} change is authorized by {authorizers}')
198+
199+
if not args.plain_block_msg:
200+
print(f'{change} change is authorized by {authorizers}')
201+
202+
if args.report_unused_patterns:
203+
unused_patterns = set(blocklist)
204+
205+
used_patterns = set(sum(blocked_changes.values(), []))
206+
unused_patterns = set(blocklist) - used_patterns
207+
208+
if unused_patterns:
209+
print('WARNING: Unused patterns have been found:')
210+
211+
for pattern in unused_patterns:
212+
print(pattern)
213+
214+
print('')
188215

189216
if blocked_changes:
190217
# If there are blocked changes present print out what's been blocked and
191218
# the pattern(s) that blocked it and return error code 1
192219
for change, block_patterns in blocked_changes.items():
193220
patterns_str = ' '.join(block_patterns)
194-
print(f'{change} blocked by pattern(s): {patterns_str}')
221+
if args.plain_block_msg:
222+
print(change)
223+
else:
224+
print(f'{change} blocked by pattern(s): {patterns_str}')
225+
226+
if not args.plain_block_msg:
227+
print('UNAUTHORIZED CHANGES PRESENT, PR cannot be merged!')
195228

196-
print('UNAUTHORIZED CHANGES PRESENT, PR cannot be merged!')
197229
return 1
198230

199231
print('No unauthorized changes, clear to merge')

util/check-blockfile.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
# Copyright lowRISC contributors.
3+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
echo "Checking BLOCKFILE. This will output all files blocked from changes and "
7+
echo "a warning if there are any patterns in BLOCKFILES which don't match any "
8+
echo "file. Must be run from repository root."
9+
10+
# Produce a list of all files, chop off the first two characters which as './'
11+
# as the change blocker script doesn't work correctly with them.
12+
find -type f | cut -c 3- > ot-filelist
13+
14+
./ci/scripts/check-pr-changes-allowed.py \
15+
--plain-block-msg \
16+
--report-unused-patterns \
17+
ot-filelist

0 commit comments

Comments
 (0)