diff --git a/README.md b/README.md index 8e51837..51c2553 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,49 @@ # ot-analyze + Github action to analyze Opentrons protocols -To be able to analyze: -python -m pip install 'opentrons-hardware @ git+https://github.com/Opentrons/opentrons@f6b79cb8d3eb3ecd4a1c794cfbdb25cee199526d#subdirectory=hardware' +## Inputs + +## `BASE_DIRECTORY` + +**Required** The topmost directory to search for protocols to analyze. + +- default directory is protocols +- The action will search this directory and all descendant directories for protocols to analyze. +- Both Python and Protocol Library protocols will be analyzed. + +## Outputs + +## TODO + +## Custom Labware + +If your protocol uses custom labware, you must include it in a `custom_labware` directory in the same directory as the protocol. The action will automatically include it in the analysis. + +## Example usage + + + + Adding the following to your workflow will analyze your protocols and you may see the results in the Actions tab of your repository. + +```yml + - name: Analyze + uses: y3rsh/ot-analyze@v1.18 +``` + +Add the the following to your workflow to analyze your protocols and create a pull request with the results. + +```yml +- name: Analyze + uses: y3rsh/ot-analyze@v1.18 +- name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + base: ${{ github.head_ref }} +``` + +## Development + +- on Linux, have python 3.10, pip, and make installed +- `make setup` to install dependencies +- uses venv and requirements.txt diff --git a/bump_version.py b/bump_version.py index aa5b4aa..469aef4 100644 --- a/bump_version.py +++ b/bump_version.py @@ -32,9 +32,13 @@ def bump_version(tag): def main(): latest_tag = get_latest_tag() new_version = bump_version(latest_tag) - # Execute git commands subprocess.run(["git", "add", "."], check=True) + try: + subprocess.run(["git", "diff", "--quiet"], check=True) + except subprocess.CalledProcessError: + print("No changes to commit") + exit(0) subprocess.run(["git", "commit", "-m", new_version], check=True) subprocess.run(["git", "tag", "-a", "-m", new_version, new_version], check=True) subprocess.run(["git", "push", "--follow-tags"], check=True) diff --git a/ot_analyze.py b/ot_analyze.py index 6ba7eb2..e2c0d3d 100644 --- a/ot_analyze.py +++ b/ot_analyze.py @@ -1,6 +1,5 @@ import json import os -import pprint import shutil import subprocess import time @@ -54,6 +53,7 @@ class ProtocolType(Enum): PROTOCOL_DESIGNER = auto() PYTHON = auto() + class AnalysisResult(Enum): PASS = auto() FAIL = auto() @@ -80,11 +80,7 @@ def analysis_error(self) -> str: @property def analysis_result(self) -> AnalysisResult: - return ( - AnalysisResult.PASS - if self._analysis_success - else AnalysisResult.FAIL - ) + return AnalysisResult.PASS if self._analysis_success else AnalysisResult.FAIL @property def protocol_file_name(self) -> str: @@ -92,11 +88,7 @@ def protocol_file_name(self) -> str: @property def protocol_type(self) -> str: - return ( - ProtocolType.PYTHON - if self.protocol_file.suffix == ".py" - else ProtocolType.PROTOCOL_DESIGNER - ).name.title() + return (ProtocolType.PYTHON if self.protocol_file.suffix == ".py" else ProtocolType.PROTOCOL_DESIGNER).name.title() def set_analysis_execution_time(self, analysis_execution_time: float) -> None: self.analysis_execution_time = analysis_execution_time @@ -179,11 +171,9 @@ def has_designer_application(json_file_path): return False - - def find_protocol_paths(repo_relative_path: Path) -> List[ProtocolPaths]: def find_pd_protocols(directory: Path) -> List[Path]: - # Check if the provided path is a valid directory + # Check if the provided path is a valid directory if not directory.is_dir(): raise NotADirectoryError(f"The path {directory} is not a valid directory.") @@ -202,21 +192,23 @@ def find_python_protocols(directory: Path) -> List[Path]: python_files = list(directory.rglob("*.py")) # TODO: shallow test that they are valid protocol files return python_files + return [ ProtocolPaths(protocol_file, generate_analysis_path(protocol_file)) - for protocol_file - in find_python_protocols(repo_relative_path) + find_pd_protocols(repo_relative_path) + for protocol_file in find_python_protocols(repo_relative_path) + find_pd_protocols(repo_relative_path) ] + def create_zip(directory_path: Path): absolute_directory_path = directory_path.absolute() try: - archive_name = shutil.make_archive(ZIP_FILE_BASENAME, 'zip', absolute_directory_path, absolute_directory_path) + archive_name = shutil.make_archive(ZIP_FILE_BASENAME, "zip", absolute_directory_path, absolute_directory_path) print(f"Zipfile created and saved to: {absolute_directory_path / archive_name}") except Exception as e: print(f"Error: {e}") + def create_markdown(protocol_paths: List[ProtocolPaths]) -> None: def generate_result(protocol_path: ProtocolPaths) -> str: if protocol_path.analysis_result == AnalysisResult.PASS: @@ -225,11 +217,7 @@ def generate_result(protocol_path: ProtocolPaths) -> str: else: summary_color = FAILURE_COLOR analysis_error = ANALYSIS_ERROR_TEMPLATE.format( - analysis_error="\n".join( - error["detail"] - for error - in protocol_path.analysis_error - ) + analysis_error="\n".join(error["detail"] for error in protocol_path.analysis_error) ) return RESULTS_TEMPLATE.format( @@ -240,6 +228,7 @@ def generate_result(protocol_path: ProtocolPaths) -> str: analysis_error=analysis_error, execution_time=protocol_path.analysis_execution_time, ) + markdown_content = MARKDOWN_TEMPLATE.format( results="\n".join([generate_result(protocol_path) for protocol_path in protocol_paths]), ) @@ -283,4 +272,3 @@ def set_env(**environ: Dict[str, str]) -> Iterator[None]: with set_env(**environ_vars_to_add): main() -