Skip to content

Commit

Permalink
Merge branch 'develop' into tom-cg-10888-wildcard-resolution-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcodgen authored Feb 25, 2025
2 parents 6f8fa89 + 82764e1 commit 047c64a
Show file tree
Hide file tree
Showing 59 changed files with 3,108 additions and 1,219 deletions.
2 changes: 1 addition & 1 deletion .github/actions/run-ats/ats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if [ ! -s codecov_ats/tests_to_run.txt ]; then
echo "No tests to run, collecting from default tests"
PYTEST_ARGS="${COLLECT_ARGS} ${DEFAULT_TESTS}"
echo "Using args: ${PYTEST_ARGS}"
TESTS_TO_RUN=$(PYTEST_ARGS=${PYTEST_ARGS} ./.circleci/collect.sh)
TESTS_TO_RUN=$(PYTEST_ARGS=${PYTEST_ARGS} ./.github/actions/run-ats/collect.sh)
echo "${TESTS_TO_RUN}" > codecov_ats/tests_to_run.txt
run_count=1
echo "Added ${TESTS_TO_RUN} as fallback. New run count: $run_count"
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/run-ats/collect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
TESTS_TO_RUN=$(uv run --frozen pytest --collect-only ${PYTEST_ARGS} -q --disable-warnings --no-summary --no-header)
TESTS_TO_RUN=$(echo "${TESTS_TO_RUN}" | head -n -2)
echo $TESTS_TO_RUN
11 changes: 4 additions & 7 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
REPO_SCOPED_TOKEN: ${{ secrets.REPO_SCOPED_TOKEN }}

steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.REPO_SCOPED_TOKEN }}
token: ${{ env.REPO_SCOPED_TOKEN || github.token }}

- name: Setup environment
uses: ./.github/actions/setup-environment
Expand All @@ -36,12 +36,9 @@ jobs:

- run: uv run --frozen pre-commit run --show-diff-on-failure --color=always --all-files --source ${{ github.event.pull_request.base.sha || github.event.before }} --origin ${{ github.event.pull_request.head.sha || github.event.after }}
shell: bash
env:
SKIP: circleci_validate

- uses: stefanzweifel/git-auto-commit-action@v5
# Always commit changes even if pre-commit failed
if: always() && github.event_name == 'pull_request'
if: ${{ always() && env.REPO_SCOPED_TOKEN && github.event_name == 'pull_request' }}
with:
commit_message: "Automated pre-commit update"
push_options: "--no-verify"
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
with:
fetch-depth: 0
ref: ${{ inputs.release-tag || github.event.pull_request.head.ref || github.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name || github.event.repository.full_name }}

- name: Install UV
uses: astral-sh/[email protected]
Expand All @@ -64,6 +65,7 @@ jobs:
cache-suffix: 3.${{ matrix.python }}

- name: Fetch tags
if: ${{ inputs.release-tag || startsWith(github.ref, 'refs/tags/') }}
run: |
git branch
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ARG CODEGEN_BOT_GHE_TOKEN=""
FROM ghcr.io/astral-sh/uv:python${PYTHON_VERSION}-bookworm-slim AS base_uv
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
ENV GITHUB_WORKSPACE=/workspace
LABEL com.circleci.preserve-entrypoint=true
## Change the working directory to the `codegen-sdk` directory
FROM base_uv AS install-tools
RUN apt-get update && apt-get install -y build-essential curl git
Expand Down
62 changes: 62 additions & 0 deletions Dockerfile-runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim

# Set environment variables to prevent interactive prompts during installation
ENV NVM_DIR=/root/.nvm \
NODE_VERSION=18.17.0 \
DEBIAN_FRONTEND=noninteractive \
NODE_OPTIONS="--max-old-space-size=8192" \
PYTHONUNBUFFERED=1 \
COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
PYTHONPATH="/usr/local/lib/python3.13/site-packages" \
IS_SANDBOX=True \
HATCH_BUILD_HOOKS_ENABLE=1

# Update packages lists and install git and curl
RUN apt-get update && apt-get install -y \
git \
curl \
gcc \
build-essential \
python3-dev \
# Cleanup apt cache to reduce image size
&& rm -rf /var/lib/apt/lists/*

# Install nvm and Node.js
SHELL ["/bin/bash", "-c"]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
&& source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm use default \
&& npm install -g yarn pnpm \
&& corepack enable \
&& corepack prepare yarn@stable --activate \
&& corepack prepare pnpm@latest --activate \
&& uv pip install --system uvicorn[standard]

# Add node and npm to PATH
ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
RUN node --version \
&& corepack --version \
&& npm --version \
&& yarn --version \
&& pnpm --version \
&& python --version

# Build codegen
WORKDIR /codegen-sdk
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv venv && source .venv/bin/activate \
&& uv sync --frozen --no-dev --all-extras \
&& uv pip install --system -e . --no-deps \
&& uv pip install --system .
RUN codegen --version

# Create a non-root user for local development + debugging
RUN useradd -m -s /bin/bash user
USER root
RUN chown -R user:user /home/user
USER user

WORKDIR /app
ENTRYPOINT ["/bin/bash", "-c"]
33 changes: 33 additions & 0 deletions codegen-examples/examples/codegen_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Codegen App

Simple example of running a codegen app.

## Run Locally

Spin up the server:

```
codegen serve
```

Spin up ngrok

```
ngrok http 8000
```

Go to Slack [app settings](https://api.slack.com/apps/A08CR9HUJ3W/event-subscriptions) and set the URL for event subscriptions

```
{ngrok_url}/slack/events
```

## Deploy to Modal

This will deploy it as a function

```
modal deploy app.py
```

Then you can swap in the modal URL for slack etc.
100 changes: 100 additions & 0 deletions codegen-examples/examples/codegen_app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import logging

import modal
from codegen import CodeAgent, CodegenApp
from codegen.extensions.github.types.events.pull_request import PullRequestLabeledEvent
from codegen.extensions.linear.types import LinearEvent
from codegen.extensions.slack.types import SlackEvent
from codegen.extensions.tools.github.create_pr_comment import create_pr_comment

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

########################################################################################################################
# EVENTS
########################################################################################################################

# Create the cg_app
cg = CodegenApp(name="codegen-test", repos=["codegen-sh/Kevin-s-Adventure-Game"])


@cg.slack.event("app_mention")
async def handle_mention(event: SlackEvent):
logger.info("[APP_MENTION] Received cg_app_mention event")
logger.info(event)

# Codebase
logger.info("[CODEBASE] Initializing codebase")
codebase = cg.get_codebase("codegen-sh/Kevin-s-Adventure-Game")

# Code Agent
logger.info("[CODE_AGENT] Initializing code agent")
agent = CodeAgent(codebase=codebase)

logger.info("[CODE_AGENT] Running code agent")
response = agent.run(event.text)

cg.slack.client.chat_postMessage(channel=event.channel, text=response, thread_ts=event.ts)
return {"message": "Mentioned", "received_text": event.text, "response": response}


@cg.github.event("pull_request:labeled")
def handle_pr(event: PullRequestLabeledEvent):
logger.info("PR labeled")
logger.info(f"PR head sha: {event.pull_request.head.sha}")
codebase = cg.get_codebase("codegen-sh/Kevin-s-Adventure-Game")

# =====[ Check out commit ]=====
# Might require fetch?
logger.info("> Checking out commit")
codebase.checkout(commit=event.pull_request.head.sha)

logger.info("> Getting files")
file = codebase.get_file("README.md")

# =====[ Create PR comment ]=====
create_pr_comment(codebase, event.pull_request.number, f"File content:\n```python\n{file.content}\n```")

return {"message": "PR event handled", "num_files": len(codebase.files), "num_functions": len(codebase.functions)}


@cg.linear.event("Issue")
def handle_issue(event: LinearEvent):
logger.info(f"Issue created: {event}")
codebase = cg.get_codebase("codegen-sh/Kevin-s-Adventure-Game")
return {"message": "Linear Issue event", "num_files": len(codebase.files), "num_functions": len(codebase.functions)}


########################################################################################################################
# MODAL DEPLOYMENT
########################################################################################################################
# This deploys the FastAPI app to Modal
# TODO: link this up with memory snapshotting.

# For deploying local package
REPO_URL = "https://github.com/codegen-sh/codegen-sdk.git"
COMMIT_ID = "26dafad2c319968e14b90806d42c6c7aaa627bb0"

# Create the base image with dependencies
base_image = (
modal.Image.debian_slim(python_version="3.13")
.apt_install("git")
.pip_install(
# =====[ Codegen ]=====
# "codegen",
f"git+{REPO_URL}@{COMMIT_ID}",
# =====[ Rest ]=====
"openai>=1.1.0",
"fastapi[standard]",
"slack_sdk",
)
)

app = modal.App("codegen-test")


@app.function(image=base_image, secrets=[modal.Secret.from_dotenv()])
@modal.asgi_app()
def fastapi_app():
return cg.app
Loading

0 comments on commit 047c64a

Please sign in to comment.