From 0a489059b2482ce01c9e6974c8363fced8d31b3a Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Wed, 27 Nov 2024 17:18:25 +0100 Subject: [PATCH] action: Allow the user to set the west manifest import flag In some cases, when using checked out trees to construct the manifest objects, it is important for users to be able to select which projects are imported, because they may have import statements in their manifests that they may want to honour or not. This commit allows the action user to select between import all projects (the default), none or only the projects in the self: section of the manifest. Signed-off-by: Carles Cufi --- action.py | 19 ++++++++++++++----- action.yml | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/action.py b/action.py index f55ad6d..e9708e3 100644 --- a/action.py +++ b/action.py @@ -48,9 +48,12 @@ def cmd2str(cmd): return " ".join(shlex.quote(word) for word in cmd) -# Taken from Zephyr's check_compliance script - +def str2import_flag(import_flag): + flags = {'all': ImportFlag.DEFAULT, 'none': ImportFlag.IGNORE, + 'self': ImportFlag.IGNORE_PROJECTS} + return flags[import_flag] +# Taken from Zephyr's check_compliance script def git(*args, cwd=None): # Helper for running a Git command. Returns the rstrip()ed stdout output. # Called like git("diff"). Exits with SystemError (raised by sys.exit()) on @@ -238,7 +241,7 @@ def _get_manifests_from_gh(token, gh_repo, mpath, new_mfile, base_sha): return (old_manifest, new_manifest) -def _get_manifests_from_tree(mpath, gh_pr, checkout, base_sha): +def _get_manifests_from_tree(mpath, gh_pr, checkout, base_sha, import_flag): # Check if current tree is at the right location mfile = (Path(checkout) / Path(mpath)).resolve() @@ -253,7 +256,7 @@ def manifest_at_rev(sha): # Use --quiet to avoid Git writing a warning about a commit left # behind in stderr git('checkout', '--quiet', '--detach', sha, cwd=checkout) - return Manifest.from_file(mfile) + return Manifest.from_file(mfile, import_flags=import_flag) old_manifest = manifest_at_rev(base_sha) new_manifest = manifest_at_rev(gh_pr.head.sha) @@ -337,6 +340,10 @@ def main(): required=False, help='Use a checked-out tree to parse the manifests.') + parser.add_argument('--west-import-flag', action='store', + required=False, choices=['all', 'none', 'self'], + help='Use a checked-out tree to parse the manifests.') + parser.add_argument('--check-impostor-commits', action='store', required=False, help='Check for impostor commits.') @@ -366,6 +373,7 @@ def main(): message = args.message if args.message != 'none' else None checkout = args.checkout_path if args.checkout_path != 'none' else None + import_flag = str2import_flag(args.west_import_flag or 'all') use_tree = args.use_tree_checkout != 'false' check_impostor = args.check_impostor_commits != 'false' labels = [x.strip() for x in args.labels.split(',')] \ @@ -414,7 +422,8 @@ def main(): if use_tree: (old_manifest, new_manifest) = _get_manifests_from_tree(mpath, gh_pr, checkout, - base_sha) + base_sha, + import_flag) else: (old_manifest, new_manifest) = _get_manifests_from_gh(token, gh_repo, mpath, new_mfile, diff --git a/action.yml b/action.yml index adb5ad3..feb49c2 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,11 @@ inputs: description: 'If true, comparison will be made on Git tree checkouts' default: 'false' required: false + west-import-flag: + description: 'West import flag to use when parsing the checked out manifest. + Choices are all, none, self' + default: 'all' + required: false check-impostor-commits: description: 'If true, a check for impostor commits will be performed' default: 'false' @@ -62,6 +67,7 @@ runs: -l "${{ inputs.labels }}" --label-prefix "${{ inputs.label-prefix }}" \ --dnm-labels "${{ inputs.dnm-labels }}" -v "${{ inputs.verbosity-level }}" \ --use-tree-checkout "${{ inputs.use-tree-checkout }}" \ + --west-import-flag "${{ inputs.west-import-flag }}" \ --check-impostor-commits "${{ inputs.check-impostor-commits }}" shell: bash env: