Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub workflow cicd #27

Merged
merged 11 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tests
.Makefile
LICENSE
requirements.txt
.github/

# Ignore all log files and temporary files
*.log
Expand Down
76 changes: 76 additions & 0 deletions .github/actions/python_setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Action code from:
# https://github.com/langchain-ai/langchain/blob/master/.github/actions/poetry_setup/action.yml
name: poetry-install-with-caching
description: Poetry install with support for caching of dependency groups.

inputs:
python-version:
description: Python version, supporting MAJOR.MINOR only
required: true

poetry-version:
description: Poetry version
required: true

cache-key:
description: Cache key to use for manual handling of caching
required: true

working-directory:
description: Directory whose poetry.lock file should be cached
required: true

runs:
using: composite
steps:
- uses: actions/setup-python@v5
name: Setup python ${{ inputs.python-version }}
id: setup-python
with:
python-version: ${{ inputs.python-version }}

- uses: actions/cache@v4
id: cache-bin-poetry
name: Cache Poetry binary - Python ${{ inputs.python-version }}
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
with:
path: |
/opt/pipx/venvs/poetry
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}

- name: Refresh shell hashtable and fixup softlinks
if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
shell: bash
env:
POETRY_VERSION: ${{ inputs.poetry-version }}
PYTHON_VERSION: ${{ inputs.python-version }}
run: |
set -eux

# Refresh the shell hashtable, to ensure correct `which` output.
hash -r

# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks.
# Delete and recreate the softlinks pipx expects to have.
rm /opt/pipx/venvs/poetry/bin/python
cd /opt/pipx/venvs/poetry/bin
ln -s "$(which "python$PYTHON_VERSION")" python
chmod +x python
cd /opt/pipx_bin/
ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
chmod +x poetry

# Ensure everything got set up correctly.
/opt/pipx/venvs/poetry/bin/python --version
/opt/pipx_bin/poetry --version

- name: Install poetry
if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
shell: bash
env:
POETRY_VERSION: ${{ inputs.poetry-version }}
PYTHON_VERSION: ${{ inputs.python-version }}
# Install poetry using the python version installed by setup-python step.
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose
102 changes: 102 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: CI/CD

on:
pull_request:
types:
- opened
- edited
- synchronize
- reopened
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
POETRY_VERSION: "1.8.2"
PYTHON_VERSION: "3.11"
WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
RUFF_OUTPUT_FORMAT: github

defaults:
run:
shell: bash
working-directory: .

jobs:
lint:
name: "Code Style"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/python_setup"
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ env.WORKDIR }}
cache-key: lint-with-extras

- name: Check Poetry File
run: |
poetry check

- name: Check lock file
run: |
poetry lock --check

- name: Install dependencies
run: |
poetry install --with dev

- name: Linting with ruff
run: |
make lint

- name: Style check with ruff
run: |
make format

- name: CodeSpell
run: |
make spell_check

test:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/python_setup"
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ env.WORKDIR }}
cache-key: lint-with-extras

- name: Install deps
run: poetry install --with tests

- name: Run tests
shell: bash
run: |
make test

build:
runs-on: ubuntu-latest
name: Build Docker Image
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
tags: thehapyone/codesage:test-${{ github.sha }}
push: false
2 changes: 1 addition & 1 deletion sage/utils/ai_tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Helps to initialize various tools that can be used by AI agents
from typing import List

from sage.constants import LLM_MODEL as llm
from langchain.tools import Tool

from sage.constants import LLM_MODEL as llm
from sage.utils.source_qa import SourceQAService


Expand Down
3 changes: 2 additions & 1 deletion sage/utils/jira_agent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Any

from sage.constants import LLM_MODEL, logger
from jira import Issue, JIRAError
from langchain.chains.llm import LLMChain
from langchain.prompts import ChatPromptTemplate, PromptTemplate

from sage.constants import LLM_MODEL, logger

# from langchain_experimental.plan_and_execute.planners.base import LLMPlanner
# from langchain_experimental.plan_and_execute.planners.chat_planner import (
# PlanningOutputParser,
Expand Down
3 changes: 2 additions & 1 deletion sage/utils/jira_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from time import sleep
from typing import List

from sage.constants import JIRA_QUERY, jira_config
from jira import JIRA, Issue
from jira.resources import Comment

from sage.constants import JIRA_QUERY, jira_config

issue_fields = [
"summary",
"status",
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/utils/test_validator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# test_validator.py

import base64
import os
from logging import getLevelName
from pathlib import Path

Expand Down