Skip to content

Commit

Permalink
v1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
y3rsh committed Nov 28, 2023
1 parent 668ca90 commit cc6eaf7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

<https://github.com/y3rsh/ot-analyze-test>

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/[email protected]
```
Add the the following to your workflow to analyze your protocols and create a pull request with the results.
```yml
- name: Analyze
uses: y3rsh/[email protected]
- 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
6 changes: 5 additions & 1 deletion bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 11 additions & 23 deletions ot_analyze.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import pprint
import shutil
import subprocess
import time
Expand Down Expand Up @@ -54,6 +53,7 @@ class ProtocolType(Enum):
PROTOCOL_DESIGNER = auto()
PYTHON = auto()


class AnalysisResult(Enum):
PASS = auto()
FAIL = auto()
Expand All @@ -80,23 +80,15 @@ 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:
return self.protocol_file.name

@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
Expand Down Expand Up @@ -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.")

Expand All @@ -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:
Expand All @@ -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(
Expand All @@ -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]),
)
Expand Down Expand Up @@ -283,4 +272,3 @@ def set_env(**environ: Dict[str, str]) -> Iterator[None]:

with set_env(**environ_vars_to_add):
main()

0 comments on commit cc6eaf7

Please sign in to comment.