From db604e8abb01db3927028ed0b694540b597b0dab Mon Sep 17 00:00:00 2001 From: Brendan Haines Date: Sat, 18 Mar 2023 01:17:31 -0600 Subject: [PATCH] automated release process stuff --- templates/jlcpcb_template/.bumpversion.cfg | 14 ++ templates/jlcpcb_template/.gitignore | 6 +- .../jlcpcb_template/jlcpcb_template.kicad_prl | 2 +- templates/jlcpcb_template/release.py | 155 ++++++++++++++++++ 4 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 templates/jlcpcb_template/.bumpversion.cfg create mode 100644 templates/jlcpcb_template/release.py diff --git a/templates/jlcpcb_template/.bumpversion.cfg b/templates/jlcpcb_template/.bumpversion.cfg new file mode 100644 index 0000000..9ff8b6f --- /dev/null +++ b/templates/jlcpcb_template/.bumpversion.cfg @@ -0,0 +1,14 @@ +[bumpversion] +current_version = 0.0 +serialize = {major}.{minor} +parse = (?P\d+).(?P\d+) +commit = True +tag = True + +[bumpversion:glob:mellifera/*.kicad_pcb] +search = (property "PCB_REVISION" "{current_version}") +replace = (property "PCB_REVISION" "{new_version}") + +[bumpversion:glob:mellifera/*.kicad_pro] +search = "PCB_REVISION": "{current_version}" +replace = "PCB_REVISION": "{new_version}" diff --git a/templates/jlcpcb_template/.gitignore b/templates/jlcpcb_template/.gitignore index 3299a6b..4b274c9 100644 --- a/templates/jlcpcb_template/.gitignore +++ b/templates/jlcpcb_template/.gitignore @@ -1,2 +1,6 @@ +# kicad backup/cache files *-backups -*.bak \ No newline at end of file +*.bak + +# prerelease outputs directory +outputs \ No newline at end of file diff --git a/templates/jlcpcb_template/jlcpcb_template.kicad_prl b/templates/jlcpcb_template/jlcpcb_template.kicad_prl index 8f3bb3b..09ecc87 100644 --- a/templates/jlcpcb_template/jlcpcb_template.kicad_prl +++ b/templates/jlcpcb_template/jlcpcb_template.kicad_prl @@ -1,6 +1,6 @@ { "board": { - "active_layer": 44, + "active_layer": 37, "active_layer_preset": "All Layers", "auto_track_width": true, "hidden_netclasses": [], diff --git a/templates/jlcpcb_template/release.py b/templates/jlcpcb_template/release.py new file mode 100644 index 0000000..ae902dc --- /dev/null +++ b/templates/jlcpcb_template/release.py @@ -0,0 +1,155 @@ +# %% Imports +import shutil +import subprocess +import zipfile +from pathlib import Path + +# %% Find the relevant files +projects = list(Path(__file__).parent.glob("*.kicad_pro")) +if len(projects) == 1: + root_project = projects[0].resolve() +else: + raise NotImplementedError("Need to determine which project is the root one (when multiple exist for sim)") + +project_name = root_project.stem + +dir_out = root_project.parent / "outputs" +if dir_out.exists(): + shutil.rmtree(str(dir_out)) +dir_out.mkdir(parents=True) +print(f"Writing outputs to {dir_out}") + +# %% Verify state of repository +# TODO: check if repo is committed and pushed or if we're in CI + +# %% Check Kicad version +kicad_version = subprocess.run(["kicad-cli", "version"], capture_output=True, check=True).stdout.decode() +major, minor, patch = kicad_version.split(".") +if int(major) < 7: + raise ValueError(f"Requires minimum Kicad version 7.0.0 buf found {kicad_version}") + +# %% General documentation PDFs +subprocess.run( + [ + "kicad-cli", + "sch", + "export", + "pdf", + str(root_project.with_suffix(".kicad_sch")), + "-o", + str(dir_out / f"{project_name}_schematic.pdf"), + ], + check=True, +) + +subprocess.run( + [ + "kicad-cli", + "pcb", + "export", + "pdf", + str(root_project.with_suffix(".kicad_pcb")), + "-o", + str(dir_out / f"{project_name}_fabrication_drawing.pdf"), + "--include-border-title", + "--layers", + ",".join(["Edge.Cuts", "F.Cu", "F.Mask", "F.Silkscreen", "F.Fab"]), + ], + check=True, +) + +subprocess.run( + [ + "kicad-cli", + "pcb", + "export", + "step", + str(root_project.with_suffix(".kicad_pcb")), + "-o", + str(dir_out / f"{project_name}.step"), + "--subst-models", + "--no-virtual", # TODO: decide if I want virtual models. I might just generate both + ], + check=True, +) + +# %% Fabrication Files +dir_gerber = dir_out / f"{project_name}_gerbers" +dir_gerber.mkdir(exist_ok=True) + +subprocess.run( + [ + "kicad-cli", + "pcb", + "export", + "gerbers", + str(root_project.with_suffix(".kicad_pcb")), + "-o", + str(dir_gerber), + ], + check=True, +) + +subprocess.run( + [ + "kicad-cli", + "pcb", + "export", + "drill", + str(root_project.with_suffix(".kicad_pcb")), + "--separate-files", + "--generate-map", # not necessary but kinda nice since I can't nicely make a drill table in the main pdf + # "-o", # -0 flag is not working so I'm just using cwd instead + # str(dir_gerber), + ], + cwd=str(dir_gerber.resolve()), + check=True, +) + + +# TODO: add version strings to every single filename + +# %% Zip up the gerbers +with zipfile.ZipFile(dir_gerber.with_suffix(".zip"), "w") as z: + for f in dir_gerber.glob("*"): + z.write(f, f.name) + +# %% Assembly files +subprocess.run( + [ + "kicad-cli", + "pcb", + "export", + "pdf", + str(root_project.with_suffix(".kicad_pcb")), + "-o", + str(dir_out / f"{project_name}_assembly_drawing.pdf"), + "--include-border-title", + "--layers", + ",".join(["Edge.Cuts", "F.Mask", "F.Silkscreen", "F.Fab"]), + ], + check=True, +) + +subprocess.run( + [ + "kicad-cli", + "sch", + "export", + "python-bom", + str(root_project.with_suffix(".kicad_sch")), + "-o", + str(dir_out / f"{project_name}_bom.xml"), + ], + check=True, +) +# TODO: post-process XML BOM into something more useful or skip XML altogether and just make an interactive HTML BOM + +# subprocess.run( +# [ +# "python3", +# "path/to/InteractiveHtmlBom/generate_interactive_bom.py", # TODO: locate this somewhere reasonable +# str(root_project.with_suffix(".kicad_pcb")), +# ], +# check=True, +# )