From 5951b385515471955e4f06759c17fee07d05b50e Mon Sep 17 00:00:00 2001 From: "Soren I. Bjornstad" Date: Thu, 26 Aug 2021 17:31:31 -0500 Subject: [PATCH] add publish step and option to skip a builder This will preserve the ability to skip a publish if I want to. --- builders.py | 19 +++++++++++++++++++ tzk.py | 24 ++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/builders.py b/builders.py index 435d412..6df8195 100644 --- a/builders.py +++ b/builders.py @@ -275,3 +275,22 @@ def set_tiddler_values(mappings: Dict[str, str]) -> None: with tiddler_path.open("w") as f: f.writelines(tiddler_lines[0:first_blank_line_index+1]) f.write(new_text) + + +@tzk_builder +def publish_wiki_to_github( + output_folder: str = "output/public_site/", + commit_message: str = "publish checkpoint", + remote: str = "origin", + refspec: str = "master") -> None: + "Publish the wiki to GitHub" + + os.chdir(output_folder) + if not os.path.isdir(".git"): + info(f"The output folder {output_folder} doesn't appear to be a Git repository. " + f"I'll try to make it one.") + git.exec("init") + + git.exec("add", "-A") + git.exec("commit", "-m", commit_message) + git.exec("push", remote, refspec) diff --git a/tzk.py b/tzk.py index 1d8b1bf..7de5fd0 100644 --- a/tzk.py +++ b/tzk.py @@ -160,6 +160,13 @@ class BuildCommand(CliCommand): metavar="PRODUCT", help="Name of the product you want to build (defined in your config file).", ) + parser.add_argument( + "-s", "--skip-builder", + metavar="BUILDER_NAME", + help="Function name of a builder to skip even if part of the PRODUCT. " + "This option can be specified multiple times.", + action="append", + ) def _precheck(self, product: str) -> None: if cm.products is None: @@ -180,18 +187,23 @@ class BuildCommand(CliCommand): for idx, step in enumerate(steps, 1): if hasattr(step, '__doc__'): - print(f"\ntzk: Step {idx}/{len(steps)}: {step.__doc__}") + print(f"tzk: Step {idx}/{len(steps)}: {step.__doc__}") else: - print(f"\ntzk: Step {idx}/{len(steps)}") + print(f"tzk: Step {idx}/{len(steps)}") + + if step.__name__ in args.skip_builder: + print(f"tzk: Skipping step {idx} due to --skip-builder parameter.") + continue + try: step() except BuildError as e: print(f"tzk: ERROR: {str(e)}") - print(f"\ntzk: Build of product '{args.product}' failed on step {idx}, " + print(f"tzk: Build of product '{args.product}' failed on step {idx}, " f"backed by builder '{step.__name__}'.") sys.exit(1) except Exception: - print(f"\ntzk: Build of product '{args.product}' failed on step {idx}: " + print(f"tzk: Build of product '{args.product}' failed on step {idx}: " f"unhandled exception. " f"The original error follows:") traceback.print_exc() @@ -200,10 +212,10 @@ class BuildCommand(CliCommand): # TODO: This should run in a finally() block; leaving for now as it's convenient for development :) for idx, step in enumerate(steps, 1): if hasattr(step, 'cleaner'): - print(f"\ntzk: Running cleanup routine for step {idx}...") + print(f"tzk: Running cleanup routine for step {idx}...") step.cleaner() - print(f"\ntzk: Build of product '{args.product}' completed successfully.") + print(f"tzk: Build of product '{args.product}' completed successfully.") parser = argparse.ArgumentParser()