Skip to content

Commit 1807b4c

Browse files
committed
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 <carles.cufi@nordicsemi.no>
1 parent 4419089 commit 1807b4c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

action.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ def cmd2str(cmd):
4848

4949
return " ".join(shlex.quote(word) for word in cmd)
5050

51-
# Taken from Zephyr's check_compliance script
52-
51+
def str2import_flag(import_flag):
52+
flags = {'all': ImportFlag.DEFAULT, 'none': ImportFlag.IGNORE,
53+
'self': ImportFlag.IGNORE_PROJECTS}
54+
return flags[import_flag]
5355

56+
# Taken from Zephyr's check_compliance script
5457
def git(*args, cwd=None):
5558
# Helper for running a Git command. Returns the rstrip()ed stdout output.
5659
# 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):
238241

239242
return (old_manifest, new_manifest)
240243

241-
def _get_manifests_from_tree(mpath, gh_pr, checkout, base_sha):
244+
def _get_manifests_from_tree(mpath, gh_pr, checkout, base_sha, import_flag):
242245
# Check if current tree is at the right location
243246

244247
mfile = (Path(checkout) / Path(mpath)).resolve()
@@ -253,7 +256,7 @@ def manifest_at_rev(sha):
253256
# Use --quiet to avoid Git writing a warning about a commit left
254257
# behind in stderr
255258
git('checkout', '--quiet', '--detach', sha, cwd=checkout)
256-
return Manifest.from_file(mfile)
259+
return Manifest.from_file(mfile, import_flags=import_flag)
257260

258261
old_manifest = manifest_at_rev(base_sha)
259262
new_manifest = manifest_at_rev(gh_pr.head.sha)
@@ -337,6 +340,10 @@ def main():
337340
required=False,
338341
help='Use a checked-out tree to parse the manifests.')
339342

343+
parser.add_argument('--west-import-flag', action='store',
344+
required=False, choices=['all', 'none', 'self'],
345+
help='Use a checked-out tree to parse the manifests.')
346+
340347
parser.add_argument('--check-impostor-commits', action='store',
341348
required=False,
342349
help='Check for impostor commits.')
@@ -366,6 +373,7 @@ def main():
366373

367374
message = args.message if args.message != 'none' else None
368375
checkout = args.checkout_path if args.checkout_path != 'none' else None
376+
import_flag = str2import_flag(args.west_import_flag or 'all')
369377
use_tree = args.use_tree_checkout != 'false'
370378
check_impostor = args.check_impostor_commits != 'false'
371379
labels = [x.strip() for x in args.labels.split(',')] \
@@ -414,7 +422,8 @@ def main():
414422
if use_tree:
415423
(old_manifest, new_manifest) = _get_manifests_from_tree(mpath,
416424
gh_pr, checkout,
417-
base_sha)
425+
base_sha,
426+
import_flag)
418427
else:
419428
(old_manifest, new_manifest) = _get_manifests_from_gh(token, gh_repo,
420429
mpath, new_mfile,

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ inputs:
1818
description: 'If true, comparison will be made on Git tree checkouts'
1919
default: 'false'
2020
required: false
21+
west-import-flag:
22+
description: 'West import flag to use when parsing the checked out manifest.
23+
Choices are all, none, self'
24+
default: 'all'
25+
required: false
2126
check-impostor-commits:
2227
description: 'If true, a check for impostor commits will be performed'
2328
default: 'false'
@@ -62,6 +67,7 @@ runs:
6267
-l "${{ inputs.labels }}" --label-prefix "${{ inputs.label-prefix }}" \
6368
--dnm-labels "${{ inputs.dnm-labels }}" -v "${{ inputs.verbosity-level }}" \
6469
--use-tree-checkout "${{ inputs.use-tree-checkout }}" \
70+
--west-import-flag "${{ inputs.west-import-flag }}" \
6571
--check-impostor-commits "${{ inputs.check-impostor-commits }}"
6672
shell: bash
6773
env:

0 commit comments

Comments
 (0)