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

Setup/GitHub actions #7

Merged
merged 8 commits into from
Sep 14, 2023
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
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI

on: push

jobs:

tests:

runs-on: ubuntu-latest

steps:

- name: Checkout repository
uses: actions/checkout@v3

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

- uses: actions/cache@v3
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('./requirements/*') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
pip3 install --upgrade pip
pip3 install -r ./requirements/dev.txt

- name: Run Tests
run: coverage run --rcfile=pyproject.toml -m pytest ./tests/

- name: Enforce Coverage
run: |
coverage combine
coverage report --rcfile=pyproject.toml -m

docstring-coverage:

runs-on: ubuntu-latest

steps:

- name: Checkout repository
uses: actions/checkout@v3

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

- uses: actions/cache@v3
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('./requirements/*') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
pip3 install --upgrade pip
pip3 install -r ./requirements/dev.txt

- name: Run Interrogate
run: |
interrogate
45 changes: 45 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Create and publish a Docker image

on:
push:
branches: ['main']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:

build-and-push-image:

runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:

- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Empty file added app/utils/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions app/utils/regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import re


def camel_to_snake(text: str) -> str:
"""
Converts CamelCase to snake_case

Usage:
>>> camel_to_snake('HTTPResponseCodeXYZ')
'http_response_code_xyz'
>>> camel_to_snake('getHTTPResponseCode')
'get_http_response_code'
"""
# https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
expression = r"((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))"
replacement_exp = r"_\1"
return re.sub(expression, replacement_exp, text).lower()
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ignore-module = true
ignore-nested-functions = true
ignore-nested-classes = true
ignore-setters = false
fail-under = 70
fail-under = 20
exclude = [
"tests/*",
"alembic/*",
Expand Down Expand Up @@ -70,7 +70,6 @@ ignore = [
"locustfile.py" = ["B012"] # B012 `break` inside `finally` blocks cause exceptions to be silenced

[tool.coverage.run]
source = ["app"]
branch = true
parallel = true

Expand Down
Empty file added tests/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions tests/utils/test_regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from app.utils.regex import camel_to_snake


@pytest.mark.parametrize('input, expected', [
('', ''),
('HTTP', 'http'),
('CamelCase', 'camel_case'),
('camel_camel_case', 'camel_camel_case'),
('HTTPResponseCode', 'http_response_code'),
('HTTPResponseCodeXYZ', 'http_response_code_xyz'),
])
def test_camel_to_snake(input: str, expected: str):
assert camel_to_snake(input) == expected