Skip to content

Commit

Permalink
Testing and CI (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort authored Oct 1, 2024
1 parent 806ae80 commit 5b7f246
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.python-version
Dockerfile
.dockerignore
LICENSE.txt
LICENSE
README.md

# Byte-compiled / optimized / DLL files
Expand Down
6 changes: 3 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DJANGO_SETTINGS_MODULE="parlance.settings.development"

PARLANCE_DEBUG=True
PARLANCE_SECRET_KEY="devjnz9&&+zo3i!j3)z_c-7xl&ti&26x02vokwx#uqlulu(wl_1ujparlance"
PARLANCE_DATABASE_URL="postgres://django@localhost:5432/parlance"
DJANGO_DEBUG=True
SECRET_KEY="devjnz9&&+zo3i!j3)z_c-7xl&ti&26x02vokwx#uqlulu(wl_1ujparlance"
DATABASE_URL="postgres://django@localhost:5432/parlance"
27 changes: 27 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
### Scope of changes

Describe the problem you're trying to solve and the fix/solution that you've implemented in this PR.

### Type of change

- [ ] bug fix
- [ ] new feature
- [ ] documentation
- [ ] other (describe)

### Acceptance criteria

Describe how reviewers can test this change to be sure that it works correctly. Add a checklist if possible.

### Author checklist

- [ ] I have manually tested the change and/or added automation in the form of unit tests or integration tests
- [ ] I have updated the dependencies list
- [ ] I have added new test fixtures as needed to support added tests
- [ ] I have added or updated the documentation
- [ ] Check this box if a reviewer can merge this pull request after approval (leave it unchecked if you want to do it yourself)

### Reviewer(s) checklist

- [ ] Any new user-facing content that has been added for this PR has been QA'ed to ensure correct grammar, spelling, and understandability.
- [ ] To the best of my ability, I believe that this PR represents a good solution to the specified problem and that it should be merged into the main code base.
43 changes: 43 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "CodeQL"
on:
push:
branches:
- main
pull_request:
# The branches below must be a subset of the branches above
branches:
- main
schedule:
# At 14:16 on Fridays
- cron: '16 14 * * 5'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language:
- javascript
- python

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
74 changes: 74 additions & 0 deletions .github/workflows/containers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Containers
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main

jobs:
# Parlance Image Build
parlance:
name: Parlance
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Environment
id: vars
run: |
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as basenames for tags
# this should be configured for each container built
images: |
rotationalio/parlance
gcr.io/rotationalio-habanero/parlance
tags: |
type=semver,pattern={{raw}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=,suffix=,format=short
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

- name: Login to GCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCR_SERVICE_ACCOUNT }}

- name: Build and Push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_REVISION=${{ steps.vars.outputs.revision }}
71 changes: 71 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Tests
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:

jobs:
lint:
name: Flake8
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12.x'

- name: Install Flake8
run: |
python3 -m pip install --upgrade pip
python3 -m pip install flake8
- name: Checkout Code
uses: actions/checkout@v4

- name: Lint Python Code
run: flake8 .

test:
name: Django Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: django
POSTGRES_PASSWORD: supersecret
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12.x'

- name: Checkout Code
uses: actions/checkout@v4

- name: Install Test Dependencies
run: |
pip install -U pip
pip install factory_boy==3.3.1 pytest==8.3.3 pytest-cov==5.0.0 \
pytest-django==4.9.0 pytest-env==1.1.5 pytest-flakes==4.0.5
- name: Install Dependencies
run: pip install -r requirements.txt

- name: Execute Tests
env:
DJANGO_SETTINGS_MODULE: parlance.settings.testing
PARLANCE_DATABASE_URL: postgres://django:[email protected]:5432/parlance_test
PARLANCE_SECRET_KEY: supersecretsquirrel
run: pytest
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Parlance

**An LLM evaluation tool that uses a model-to-model qualitative comparison metric.**
[![Tests](https://github.com/rotationalio/parlance/actions/workflows/tests.yaml/badge.svg)](https://github.com/rotationalio/parlance/actions/workflows/tests.yaml)
[![Containers](https://github.com/rotationalio/parlance/actions/workflows/containers.yaml/badge.svg)](https://github.com/rotationalio/parlance/actions/workflows/containers.yaml)
[![CodeQL](https://github.com/rotationalio/parlance/actions/workflows/codeql.yaml/badge.svg)](https://github.com/rotationalio/parlance/actions/workflows/codeql.yaml)

**An LLM evaluation tool that uses a model-to-model qualitative comparison metric.**

## Getting Started

Expand Down
19 changes: 9 additions & 10 deletions parlance/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def parse_bool(val):
##########################################################################

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = environ_setting("PARLANCE_SECRET_KEY", required=True)
SECRET_KEY = environ_setting("SECRET_KEY", required=True)


##########################################################################
Expand All @@ -87,8 +87,7 @@ def parse_bool(val):
# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
DATABASES = {
"default": dj_database_url.parse(
environ_setting("PARLANCE_DATABASE_URL", required=True, default=""),
"default": dj_database_url.config(
conn_max_age=600,
conn_health_checks=True,
test_options={"NAME": "parlance_testing"},
Expand All @@ -107,7 +106,7 @@ def parse_bool(val):
##########################################################################

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = parse_bool(environ_setting("PARLANCE_DEBUG", default=True))
DEBUG = parse_bool(environ_setting("DJANGO_DEBUG", default=True))

# Specify hosts in production settings
ALLOWED_HOSTS = []
Expand Down Expand Up @@ -223,12 +222,12 @@ def parse_bool(val):
## Logging and Error Reporting
##########################################################################

ADMINS = [("Parlance Admin", environ_setting("PARLANCE_ADMIN_EMAIL", ""))]
ADMINS = [("Parlance Admin", environ_setting("ADMIN_EMAIL", ""))]

SERVER_EMAIL = environ_setting("PARLANCE_SERVER_EMAIL", default="")
SERVER_EMAIL = environ_setting("SERVER_EMAIL", default="")
EMAIL_USE_TLS = True
EMAIL_HOST = environ_setting("PARLANCE_EMAIL_HOST", default="")
EMAIL_HOST_USER = environ_setting("PARLANCE_EMAIL_HOST_USER", default="")
EMAIL_HOST_PASSWORD = environ_setting("PARLANCE_EMAIL_HOST_PASSWORD", default="")
EMAIL_PORT = environ_setting("PARLANCE_EMAIL_PORT", default=587)
EMAIL_HOST = environ_setting("EMAIL_HOST", default="")
EMAIL_HOST_USER = environ_setting("EMAIL_HOST_USER", default="")
EMAIL_HOST_PASSWORD = environ_setting("EMAIL_HOST_PASSWORD", default="")
EMAIL_PORT = environ_setting("EMAIL_PORT", default=587)
EMAIL_SUBJECT_PREFIX = "[PARLANCE] "
4 changes: 2 additions & 2 deletions parlance/settings/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
##########################################################################

from .base import * # noqa
from base import PROJECT
from .base import PROJECT


##########################################################################
Expand All @@ -34,5 +34,5 @@
]

## Static files served by WhiteNoise
STATIC_ROOT = PROJECT / "static"
STATIC_ROOT = PROJECT / "assets"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
23 changes: 23 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[pytest]
DJANGO_SETTINGS_MODULE = parlance.settings.testing
addopts = --cov=. --flakes
python_files = tests.py test_*.py *_tests.py
norecursedirs = .git _build assets theme tmp

env =
SECRET_KEY=supersecretsquirrel

filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
ignore:No directory at.*:UserWarning

flakes-ignore =
__init__.py UnusedImport
__init__.py ImportStarUsed
test_*.py ImportStarUsed
test_*.py ImportStarUsage
parlance/settings/*.py ImportStarUsage
parlance/settings/*.py ImportStarUsed
parlance/urls.py ImportStarUsed
parlance/urls.py ImportStarUsage

0 comments on commit 5b7f246

Please sign in to comment.