From 83d9d66fbfee58b1543241047277f07b5b05a662 Mon Sep 17 00:00:00 2001 From: Greg Chadwick Date: Fri, 12 May 2023 16:18:52 +0100 Subject: [PATCH] [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 --- ci/scripts/check-pr-changes-allowed.py | 38 ++++++++++++++++++++++++-- util/check-blockfile.sh | 17 ++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100755 util/check-blockfile.sh diff --git a/ci/scripts/check-pr-changes-allowed.py b/ci/scripts/check-pr-changes-allowed.py index 852ad2689c443..56ef465f76475 100755 --- a/ci/scripts/check-pr-changes-allowed.py +++ b/ci/scripts/check-pr-changes-allowed.py @@ -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) @@ -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') diff --git a/util/check-blockfile.sh b/util/check-blockfile.sh new file mode 100755 index 0000000000000..c30b018ba151a --- /dev/null +++ b/util/check-blockfile.sh @@ -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