From 5585e7f42cd07ee2e2f721824cbfae8c12fe17ea Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 4 Aug 2024 01:31:51 -0400 Subject: [PATCH 1/8] Run the test suite as a GitHub Action --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc4feaf..f3b88d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,12 +8,12 @@ on: workflow_dispatch: jobs: - Test: + PreCommit: name: pre-commit runs-on: ubuntu-latest steps: - name: 💾 Check out repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: 🪝 Cache pre-commit hooks uses: actions/cache@v3 @@ -29,6 +29,28 @@ jobs: - name: 🔥 Test run: pre-commit run --show-diff-on-failure --all-files + Test: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: 💾 Check out repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Install OpenSCAD + run: | + sudo apt-get update + sudo apt-get install openscad + + - name: Run Unit Tests + shell: bash + working-directory: ./tests + run: python3 -m unittest + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: false From 904b8e947bda4261586a04a255d03a2e20018b29 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 4 Aug 2024 02:25:19 -0400 Subject: [PATCH 2/8] First attempt at making the tests Linux compatible --- tests/openscad_runner.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/openscad_runner.py b/tests/openscad_runner.py index c73987d..25a6b19 100644 --- a/tests/openscad_runner.py +++ b/tests/openscad_runner.py @@ -5,12 +5,15 @@ from __future__ import annotations import json +import logging import subprocess from dataclasses import dataclass, is_dataclass, asdict from pathlib import Path from tempfile import NamedTemporaryFile from typing import NamedTuple, Optional +logger = logging.getLogger(__name__) + class DataClassJSONEncoder(json.JSONEncoder): '''Allow json serialization''' def default(self, o): @@ -99,13 +102,15 @@ class CameraRotations: class OpenScadRunner: '''Helper to run the openscad binary''' + camera_arguments: CameraArguments scad_file_path: Path openscad_binary_path: Path image_folder_base: Path parameters: Optional[dict] '''If set, a temporary parameter file is created, and used with these variables''' - WINDOWS_DEFAULT_PATH = 'C:\\Program Files\\OpenSCAD\\openscad.exe' + LINUX_DEFAULT_PATH = Path('/bin/openscad') + WINDOWS_DEFAULT_PATH = Path('C:\\Program Files\\OpenSCAD\\openscad.exe') TOP_ANGLE_CAMERA = CameraArguments(Vec3(0,0,0),Vec3(45,0,45),150) common_arguments = [ @@ -121,20 +126,30 @@ class OpenScadRunner: set_variable_argument('$fa', 8) + set_variable_argument('$fs', 0.25) def __init__(self, file_path: Path): - self.openscad_binary_path = self.WINDOWS_DEFAULT_PATH + self.openscad_binary_path = self.find_openscad_binary() self.scad_file_path = file_path self.image_folder_base = Path('.') self.camera_arguments = None self.parameters = None + @classmethod + def find_openscad_binary(cls) -> Path: + if cls.WINDOWS_DEFAULT_PATH.exists(): + return cls.WINDOWS_DEFAULT_PATH + if cls.LINUX_DEFAULT_PATH.exists(): + return cls.LINUX_DEFAULT_PATH + logger.warning("Could not find OpenSCAD binary, defaulting to 'openscad'") + return Path("openscad") + def create_image(self, args: [str], image_file_name: str): """ Run the code, to create an image. @Important The only verification is that no errors occured. There is no verification if the image was created, or the image contents. """ - assert(self.scad_file_path.exists()) - assert(self.image_folder_base.exists()) + assert self.openscad_binary_path.exists(), f"OpenSCAD binary not found at '{self.openscad_binary_path}'" + assert self.scad_file_path.exists(), f"OpenSCAD file not found at '{self.scad_file_path}'" + assert self.image_folder_base.exists(), f"Image folder not found at '{self.image_folder_base}'" image_path = self.image_folder_base.joinpath(image_file_name) command_arguments = self.common_arguments + \ @@ -150,6 +165,6 @@ def create_image(self, args: [str], image_file_name: str): json.dump(params, file, sort_keys=True, indent=2, cls=DataClassJSONEncoder) file.close() command_arguments += ["-p", file.name, "-P", "python_generated"] - return subprocess.run([self.openscad_binary_path]+command_arguments, check=True) + return subprocess.run([str(self.openscad_binary_path)] + command_arguments, check=True) else: - return subprocess.run([self.openscad_binary_path]+command_arguments, check=True) + return subprocess.run([str(self.openscad_binary_path)] + command_arguments, check=True) From ea976db7e7cd9ec7e5ef17f5d52e2e820980a6cd Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 4 Aug 2024 02:31:17 -0400 Subject: [PATCH 3/8] CI: Print some information about the OpenSCAD version used --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3b88d4..44e0b6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,10 @@ jobs: sudo apt-get update sudo apt-get install openscad + - name: OpenSCAD Build Information + run: openscad --info + continue-on-error: true + - name: Run Unit Tests shell: bash working-directory: ./tests From df9b7e52624a1bfe236fce02a9f52c55d849fd62 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 4 Aug 2024 02:58:26 -0400 Subject: [PATCH 4/8] CI: Disable flags which require a beta version of OpenSCAD --- tests/openscad_runner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/openscad_runner.py b/tests/openscad_runner.py index 25a6b19..2f52096 100644 --- a/tests/openscad_runner.py +++ b/tests/openscad_runner.py @@ -115,8 +115,8 @@ class OpenScadRunner: common_arguments = [ #'--hardwarnings', // Does not work when setting variables by using functions - '--enable=fast-csg', - '--enable=predictible-output', + #'--enable=fast-csg', // Requires Beta version of OpenSCAD + #'--enable=predictible-output', // Requires Beta version of OpenSCAD '--imgsize=1280,720', '--view=axes', '--projection=ortho', From 49718cccc2a48c9696349f06e7f410b473895d2f Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 4 Aug 2024 03:04:41 -0400 Subject: [PATCH 5/8] ci: Fully render the geometry when creating images. Required on headless systems. --- tests/openscad_runner.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/openscad_runner.py b/tests/openscad_runner.py index 2f52096..e635397 100644 --- a/tests/openscad_runner.py +++ b/tests/openscad_runner.py @@ -114,9 +114,10 @@ class OpenScadRunner: TOP_ANGLE_CAMERA = CameraArguments(Vec3(0,0,0),Vec3(45,0,45),150) common_arguments = [ - #'--hardwarnings', // Does not work when setting variables by using functions - #'--enable=fast-csg', // Requires Beta version of OpenSCAD - #'--enable=predictible-output', // Requires Beta version of OpenSCAD + #'--hardwarnings', # Does not work when setting variables by using functions + #'--enable=fast-csg', # Requires Beta version of OpenSCAD + #'--enable=predictible-output', # Requires Beta version of OpenSCAD + '--render=true' # Required on headless systems '--imgsize=1280,720', '--view=axes', '--projection=ortho', From 8414ffba3560f88a1127c0502bb206be03e4036c Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 4 Aug 2024 03:08:42 -0400 Subject: [PATCH 6/8] ci: another pass at getting OpenSCAD working --- .github/workflows/ci.yml | 10 ++++++---- tests/openscad_runner.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44e0b6e..2418272 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,10 +50,12 @@ jobs: run: openscad --info continue-on-error: true - - name: Run Unit Tests - shell: bash - working-directory: ./tests - run: python3 -m unittest + - name: Run Unit Tests (Headless) + uses: coactions/setup-xvfb@6b00cf1889f4e1d5a48635647013c0508128ee1a + with: + shell: bash + working-directory: ./tests + run: python3 -m unittest concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/tests/openscad_runner.py b/tests/openscad_runner.py index e635397..ac586d3 100644 --- a/tests/openscad_runner.py +++ b/tests/openscad_runner.py @@ -117,7 +117,7 @@ class OpenScadRunner: #'--hardwarnings', # Does not work when setting variables by using functions #'--enable=fast-csg', # Requires Beta version of OpenSCAD #'--enable=predictible-output', # Requires Beta version of OpenSCAD - '--render=true' # Required on headless systems + #'--render=true' # Fully render geometry for images, instead of using fast preview mode. '--imgsize=1280,720', '--view=axes', '--projection=ortho', From 42970e71fee494df136b7d05c14e132b9620a1d2 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 4 Aug 2024 03:22:04 -0400 Subject: [PATCH 7/8] ci: Ensure image directories exist --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2418272..5512956 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,10 +50,13 @@ jobs: run: openscad --info continue-on-error: true + - name: Create Image Directories + run: mkdir -p base_hole_options baseplate hole_cutouts spiral_vase_base + working-directory: ./images + - name: Run Unit Tests (Headless) uses: coactions/setup-xvfb@6b00cf1889f4e1d5a48635647013c0508128ee1a with: - shell: bash working-directory: ./tests run: python3 -m unittest From d59adee4f4e7ddb1fa26ad5a1aef752fc5ff3d6c Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 4 Aug 2024 03:30:11 -0400 Subject: [PATCH 8/8] ci: Upload generated images as artifacts --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5512956..c2dc2ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,12 @@ jobs: working-directory: ./tests run: python3 -m unittest + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: images + path: images/**/*.png + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: false