From e8a661e522859a71a8726c9cc59123b017b4619e Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 14 Aug 2024 23:51:03 -0400 Subject: [PATCH] feat: Update "vendorize" noxfile session to allow commit directly on main --- noxfile.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/noxfile.py b/noxfile.py index cffb6d1..68e7029 100644 --- a/noxfile.py +++ b/noxfile.py @@ -22,9 +22,16 @@ def _vendorize(session: nox.Session, paths: list[str]) -> None: """ Vendorize files into a directory. Directory must exist. """ + project = "MorphoCloudWorkflow" + parser = argparse.ArgumentParser() parser.add_argument( - "--commit", action="store_true", help="Make a branch and commit." + "--commit", action="store_true", help="Commit onto the current branch." + ) + parser.add_argument( + "--branch", + action="store_true", + help=f"Make a branch (e.g update-to-{project.lower()}-SHA).", ) parser.add_argument( "target", type=Path, help="The target directory to vendorize file into." @@ -50,7 +57,6 @@ def _vendorize(session: nox.Session, paths: list[str]) -> None: if args.commit: org = "MorphoCloud" - project = "MorphoCloudWorkflow" # if any, extract SHA associated with the last update with session.chdir(target_dir): @@ -87,13 +93,15 @@ def _vendorize(session: nox.Session, paths: list[str]) -> None: ) with session.chdir(target_dir): - session.run( - "git", - "switch", - "-c", - f"update-to-{project.lower()}-{after}", - external=True, - ) + if args.branch: + session.run( + "git", + "switch", + "-c", + f"update-to-{project.lower()}-{after}", + external=True, + ) + session.run("git", "add", "-A", external=True) session.run( "git", @@ -114,10 +122,13 @@ def _vendorize(session: nox.Session, paths: list[str]) -> None: else f"fix: Update to {org}/{project}@{after}", external=True, ) - command = f"cd MorphoCloudWorkflow; pipx run nox -s {session.name} -- /path/to/{target_dir.stem} --commit" - session.log( - f'Complete! Now run: gh pr create --fill --body "Created by running `{command}`"' - ) + if args.branch: + command = f"cd {src_dir.stem}; pipx run nox -s {session.name} -- /path/to/{target_dir.stem} --commit" + session.log( + f'Complete! Now run: cd {target_dir}; gh pr create --fill --body "Created by running `{command}`"' + ) + else: + session.log(f"Complete! Now run: cd {target_dir}; git push origin main") @nox.session