Skip to content

Commit

Permalink
✨ Linux workflow (#41)
Browse files Browse the repository at this point in the history
* set up kai-demo-evaluator ci

Signed-off-by: Alejandro Brugarolas <[email protected]>

* aux

Signed-off-by: Alejandro Brugarolas <[email protected]>

* aux

Signed-off-by: Alejandro Brugarolas <[email protected]>

* aux

Signed-off-by: Alejandro Brugarolas <[email protected]>

* add linux workflow and minor changes

Signed-off-by: Alejandro Brugarolas <[email protected]>

* format

Signed-off-by: Alejandro Brugarolas <[email protected]>

* remove use of kai-eval for now

Signed-off-by: Alejandro Brugarolas <[email protected]>

* finish

Signed-off-by: Alejandro Brugarolas <[email protected]>

* update worflow to run once a day

Signed-off-by: Alejandro Brugarolas <[email protected]>

* minor improvements

Signed-off-by: Alejandro Brugarolas <[email protected]>

---------

Signed-off-by: Alejandro Brugarolas <[email protected]>
  • Loading branch information
abrugaro authored Dec 18, 2024
1 parent 42a1829 commit 05bbeb4
Show file tree
Hide file tree
Showing 39 changed files with 181 additions and 2,891 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/kai-demo-evaluator-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Run demo with kai client and evaluate results

on:
schedule:
- cron: '0 0 * * 0,1,2,3,4,5'
jobs:
test-and-evaluate:
name: Run demo and evaluation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
distribution: "oracle"
java-version: "17"

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Set up venv
run: |
python -m venv venv
. venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
- name: Set up dependencies
run: |
cd kai-client-ci
pip install -r requirements.txt
env:
PATH: ${{ env.PATH }}

- name: Run execution & evaluation test
run: |
python --version
cd kai-client-ci
python ./main.py
env:
PATH: ${{ env.PATH }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
out
gen
kai-client-ci/.idea
kai-client-ci/venv
kai-client-ci/output
kai-client-ci/fixtures
kai-client-ci/kai_files
1 change: 1 addition & 0 deletions kai-client-ci/consts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
KAI_FILES_FOLDER='kai_files'
KAI_FOLDER='kai_files/kai'
KAI_EVAL_FOLDER='kai_files/kai-eval'
COOLSTORE_FOLDER='kai_files/kai/example/coolstore'
34 changes: 26 additions & 8 deletions kai-client-ci/files.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import platform
import shutil
import stat
import zipfile
import json
import os
import git

import requests
from git import Repo

from logger import get_logger

logger = get_logger(__name__)


def download_file(url, file_path):
def download_file(url: str, file_path: str):
response = requests.get(url, stream=True)
if response.status_code == 200:
with open(file_path, 'wb') as file:
Expand All @@ -22,7 +24,7 @@ def download_file(url, file_path):
logger.error(f'Failed to download the file {file_path} | Status code: {response.status_code}')


def rename_extracted_folder(base_folder, target_folder_name):
def rename_extracted_folder(base_folder: str, target_folder_name: str):
"""
Renames the extracted source code folder which is in format konveyor-kai-[uid] to a standard name 'kai'
"""
Expand All @@ -40,13 +42,18 @@ def rename_extracted_folder(base_folder, target_folder_name):
logger.error(f'Failed to rename folder: {e}')


def clone_repository(app_name, repository_url, branch):
def clone_repository(app_name: str, repository_url: str, branch: str):
clone_dir = os.path.join('data', f'{app_name}')
git.Repo.clone_from(repository_url, clone_dir, branch=branch)
logger.info(f"Repository {app_name} {branch} cloned into 'data'")

def count_modified_files(repo_path: str) -> int:
repo = Repo(repo_path)
diff = repo.git.diff('--numstat')
modified_files = len(diff.splitlines())
return modified_files

def unzip_file(zip_path, extract_folder):
def unzip_file(zip_path: str, extract_folder: str):
extract_folder = winapi_path(extract_folder)
try:
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
Expand All @@ -56,7 +63,7 @@ def unzip_file(zip_path, extract_folder):
logger.error(f'Failed to extract {zip_path}')


def zip_folder(input_dir, file_name, output_dir):
def zip_folder(input_dir: str, file_name: str, output_dir: str) -> str:
zip_filename = f'{file_name}.zip'
zip_path = os.path.join(output_dir, zip_filename)

Expand All @@ -65,7 +72,7 @@ def zip_folder(input_dir, file_name, output_dir):
return zip_path


def copy_file(src, dst):
def copy_file(src: str, dst: str):
try:
if os.path.isdir(src):
shutil.copytree(src, dst)
Expand All @@ -75,8 +82,16 @@ def copy_file(src, dst):
except Exception as e:
logger.error(f'Error while copying {src} to {dst}: {e}')

def append_to_json_file(file_path, new_data):
with open(file_path, 'r', encoding='utf-8') as ogFile:
data = json.load(ogFile)

data.append(new_data)

def set_executable_permissions(file_path):
with open(file_path, 'w', encoding='utf-8') as modFile:
json.dump(data, modFile, indent=4)

def set_executable_permissions(file_path: str):
try:
logger.info(f'Setting executable permissions for {file_path}')
st = os.stat(file_path)
Expand Down Expand Up @@ -110,6 +125,9 @@ def winapi_path(dos_path, encoding=None):
"""
Fix to avoid path too long errors while extracting kai in Windows
"""
if platform.system().lower() != "windows":
return dos_path

path = os.path.abspath(dos_path)

if path.startswith("\\\\"):
Expand Down
5 changes: 3 additions & 2 deletions kai-client-ci/fixtures/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
log_level = "info"
file_log_level = "debug"
log_dir = "../logs/"
demo_mode = false
trace_enabled = true
log_level = "debug"
file_log_level = "debug"
[models]
provider = "ChatBedrock"
[models.args]
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 05bbeb4

Please sign in to comment.