Skip to content

Commit

Permalink
Merge branch 'edge' into chore_update-cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
shlokamin committed Apr 22, 2024
2 parents 09e00ed + 8776ed9 commit 7bc6302
Show file tree
Hide file tree
Showing 918 changed files with 53,231 additions and 16,763 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/app-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: 'downgrade npm version'
run: npm install -g npm@6
- name: check make version
run: make --version
- name: 'install libudev and libsystemd'
Expand Down Expand Up @@ -245,8 +243,6 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: 'downgrade npm version'
run: npm install -g npm@6
- name: check make version
run: make --version
- name: 'install libudev and libsystemd'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/components-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ jobs:
with:
node-version: '18.19.0'
registry-url: 'https://registry.npmjs.org'
- name: 'install udev for usb-detection'
run: sudo apt-get update && sudo apt-get install libudev-dev
- name: 'setup-js'
run: |
npm config set cache ./.npm-cache
yarn config set cache-folder ./.yarn-cache
make setup-js
- name: 'build typescript'
run: make build-ts
- name: 'build library'
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/opentrons-ai-client-test-build-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Run tests, build the app, and deploy it cross platform

name: 'OpentronsAI client test, build, and deploy'

# ToDo (kk:04/16/2024) Add build and deploy task

on:
push:
paths:
- 'Makefile'
- 'opentrons-ai-client/**/*'
- 'components/**/*'
- '*.js'
- '*.json'
- 'yarn.lock'
- '.github/workflows/app-test-build-deploy.yaml'
- '.github/workflows/utils.js'
branches:
- '**'
tags:
- 'v*'
- 'ot3@*'
pull_request:
paths:
- 'Makefile'
- 'opentrons-ai-client/**/*'
- 'components/**/*'
- '*.js'
- '*.json'
- 'yarn.lock'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.ref_name != 'edge' || github.run_id}}-${{ github.ref_type != 'tag' || github.run_id }}
cancel-in-progress: true

env:
CI: true

jobs:
js-unit-test:
runs-on: 'ubuntu-22.04'
name: 'opentrons ai frontend unit tests'
timeout-minutes: 60
steps:
- uses: 'actions/checkout@v3'
- uses: 'actions/setup-node@v3'
with:
node-version: '18.19.0'
- name: 'install udev'
run: sudo apt-get update && sudo apt-get install libudev-dev
- name: 'set complex environment variables'
id: 'set-vars'
uses: actions/github-script@v6
with:
script: |
const { buildComplexEnvVars } = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/utils.js`)
buildComplexEnvVars(core, context)
- name: 'cache yarn cache'
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/.npm-cache/_prebuild
${{ github.workspace }}/.yarn-cache
key: js-${{ secrets.GH_CACHE_VERSION }}-${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: 'setup-js'
run: |
npm config set cache ${{ github.workspace }}/.npm-cache
yarn config set cache-folder ${{ github.workspace }}/.yarn-cache
make setup-js
- name: 'test frontend packages'
run: |
make -C opentrons-ai-client test-cov
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
with:
files: ./coverage/lcov.info
flags: opentrons-ai-client
54 changes: 54 additions & 0 deletions .github/workflows/performance-metrics-test-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This workflow runs lint on pull requests that touch anything in the performance-metrics directory

name: 'performance-metrics test & lint'

on:
pull_request:
paths:
- 'performance-metrics/**'
- '.github/workflows/performance-metrics-test-lint.yaml'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
lint:
name: 'performance-metrics test & lint'
timeout-minutes: 5
runs-on: 'ubuntu-latest'
steps:
- name: Checkout opentrons repo
uses: 'actions/checkout@v4'

- name: Setup Python
uses: 'actions/setup-python@v5'
with:
python-version: '3.10'
cache: 'pipenv'
cache-dependency-path: performance-metrics/Pipfile.lock

- name: "Install Python deps"
uses: './.github/actions/python/setup'
with:
project: 'performance-metrics'

- name: Setup
id: install
working-directory: ./performance-metrics
run: make setup

- name: Test
if: always() && steps.install.outcome == 'success' || steps.install.outcome == 'skipped'
working-directory: ./performance-metrics
run: make test

- name: Lint
if: always() && steps.install.outcome == 'success' || steps.install.outcome == 'skipped'
working-directory: ./performance-metrics
run: make lint
3 changes: 2 additions & 1 deletion .github/workflows/shared-data-test-lint-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ jobs:
- name: 'js deps'
run: |
npm config set cache ./.npm-cache
yarn config set cache-folder ./.yarn-cache
yarn config set cache-folder ./.yarn-cache
make setup-js
- name: 'build typescript'
run: make build-ts
- name: 'build library'
Expand Down
1 change: 1 addition & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
stories: [
'../components/**/*.stories.@(js|jsx|ts|tsx)',
'../app/**/*.stories.@(js|jsx|ts|tsx)',
'../opentrons-ai-client/**/*.stories.@(js|jsx|ts|tsx)',
],

addons: [
Expand Down
2 changes: 1 addition & 1 deletion .storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const parameters = {
options: {
storySort: {
method: 'alphabetical',
order: ['Design Tokens', 'Library', 'App', 'ODD'],
order: ['Design Tokens', 'Library', 'App', 'ODD', 'AI'],
},
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Google Drive Tool."""
import os
from typing import Set, Any
from typing import Set, Any, Optional
import webbrowser
import mimetypes
from oauth2client.service_account import ServiceAccountCredentials # type: ignore[import]
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
Expand All @@ -14,15 +16,15 @@
class google_drive:
"""Google Drive Tool."""

def __init__(self, credentials: Any, folder_name: str, parent_folder: Any) -> None:
def __init__(self, credentials: Any, folder_name: str, email: str) -> None:
"""Connects to google drive via credentials file."""
self.scope = ["https://www.googleapis.com/auth/drive"]
self.credentials = ServiceAccountCredentials.from_json_keyfile_name(
credentials, self.scope
)
self.drive_service = build("drive", "v3", credentials=self.credentials)
self.folder_name = folder_name
self.parent_folder = parent_folder
self.parent_folder = folder_name
self.email = email

def list_folder(self, delete: Any = False) -> Set[str]:
"""List folders and files in Google Drive."""
Expand Down Expand Up @@ -72,26 +74,37 @@ def upload_file(self, file_path: str) -> str:
"""Upload file to Google Drive."""
file_metadata = {
"name": os.path.basename(file_path),
"mimeType": "application/vnd.google-apps.folder",
"parents": [self.parent_folder] if self.parent_folder else "",
"mimeType": str(mimetypes.guess_type(file_path)[0]),
"parents": [self.parent_folder],
}

media = MediaFileUpload(file_path, resumable=True)

uploaded_file = (
self.drive_service.files()
.create(body=file_metadata, media_body=media, fields="id") # type: ignore
.execute()
)

return uploaded_file["id"]

def upload_missing_files(self, storage_directory: str, missing_files: set) -> None:
def upload_missing_files(self, storage_directory: str) -> None:
"""Upload missing files to Google Drive."""
# Read Google Drive .json files.
google_drive_files = self.list_folder()
google_drive_files_json = [
file for file in google_drive_files if file.endswith(".json")
]
# Read local directory.
local_files_json = set(
file for file in os.listdir(storage_directory) if file.endswith(".json")
)
missing_files = local_files_json - set(google_drive_files_json)
print(f"Missing files: {len(missing_files)}")
# Upload missing files.
uploaded_files = []
for file in missing_files:
file_path = os.path.join(storage_directory, file)
uploaded_file_id = google_drive.upload_file(self, file_path)
self.share_permissions(uploaded_file_id)
uploaded_files.append(
{"name": os.path.basename(file_path), "id": uploaded_file_id}
)
Expand All @@ -108,3 +121,31 @@ def upload_missing_files(self, storage_directory: str, missing_files: set) -> No
print(
f"File '{this_name}' was not found in the list of files after uploading."
)

def open_folder(self) -> Optional[str]:
"""Open folder in web browser."""
folder_metadata = (
self.drive_service.files()
.get(fileId=self.parent_folder, fields="webViewLink")
.execute()
)
folder_link = folder_metadata.get("webViewLink")
if folder_link:
print(f"Folder link: {folder_link}")
webbrowser.open(
folder_link
) # Open the folder link in the default web browser
else:
print("Folder link not found.")
return folder_link

def share_permissions(self, file_id: str) -> None:
"""Share permissions with self."""
new_permission = {
"type": "user",
"role": "writer",
"emailAddress": self.email,
}
self.drive_service.permissions().create(
fileId=file_id, body=new_permission, transferOwnership=False # type: ignore
).execute()
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import gspread # type: ignore[import]
import socket
import httplib2
from datetime import datetime
from oauth2client.service_account import ServiceAccountCredentials # type: ignore[import]
from typing import Dict, List, Any, Set, Tuple

Expand Down Expand Up @@ -57,6 +58,12 @@ def write_to_row(self, data: List) -> None:
"""Write data into a row in a List[] format."""
try:
self.row_index += 1
data = [
item.strftime("%Y/%m/%d %H:%M:%S")
if isinstance(item, datetime)
else item
for item in data
]
self.worksheet.insert_row(data, index=self.row_index)
except socket.gaierror:
pass
Expand Down

0 comments on commit 7bc6302

Please sign in to comment.