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

Added branch protection and limited automated testing #3

Closed
wants to merge 29 commits into from
Closed
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
98 changes: 0 additions & 98 deletions .github/workflows/deploy.yml

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy Images to GHCR

on:
push:
branches: [ "dev" ]

jobs:
unit-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: '.'
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install pip and pytest
run: |
python -m pip install --upgrade pip
pip install -r docker/requirements.txt
- name: Test with pytest
run: |
python3 -m pytest --import-mode=append tests/

build-dev:
# if: github.ref == 'refs/heads/dev'
needs: unit-tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: '.'
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@main

- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: "Build, Tag, and push the Docker image"
env:
IMAGE_NAME: ghcr.io/manimatter/decluttarr
IMAGE_TAG: dev
run: |
docker build -f docker/Dockerfile -t $IMAGE_NAME:$IMAGE_TAG .
docker push $IMAGE_NAME:$IMAGE_TAG
100 changes: 100 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Deploy Images to GHCR

on:
pull_request:
types:
- closed
branches:
- main

jobs:
# unit-tests:
# runs-on: ubuntu-latest
# defaults:
# run:
# working-directory: '.'
# steps:
# - uses: actions/checkout@v4

# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: '3.x'
# - name: Install pip and pytest
# run: |
# python -m pip install --upgrade pip
# pip install -r docker/requirements.txt
# - name: Test with pytest
# run: |
# python3 -m pytest --import-mode=append tests/

build-main:
# if: github.ref == 'refs/heads/main'
# needs: unit-tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: '.'
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@main

- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- uses: actions/checkout@v2
with:
fetch-depth: '0'

- name: Bump version and push tag
uses: anothrNick/[email protected]
id: setversion
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true

- name: "Build, Tag, and push the Docker image"
env:
IMAGE_NAME: ghcr.io/manimatter/decluttarr
IMAGE_TAG: ${{ steps.setversion.outputs.new_tag }}
run: |
docker build -f docker/Dockerfile -t $IMAGE_NAME:$IMAGE_TAG .
docker push $IMAGE_NAME:$IMAGE_TAG

- name: "Build, Tag, and push the Docker image"
env:
IMAGE_NAME: ghcr.io/manimatter/decluttarr
IMAGE_TAG: latest
run: |
docker build -f docker/Dockerfile -t $IMAGE_NAME:$IMAGE_TAG .
docker push $IMAGE_NAME:$IMAGE_TAG

# build-dev:
# if: github.ref == 'refs/heads/dev'
# needs: unit-tests
# runs-on: ubuntu-latest
# defaults:
# run:
# working-directory: '.'
# steps:
# - name: 'Checkout GitHub Action'
# uses: actions/checkout@main

# - name: 'Login to GitHub Container Registry'
# uses: docker/login-action@v1
# with:
# registry: ghcr.io
# username: ${{github.actor}}
# password: ${{secrets.GITHUB_TOKEN}}

# - name: "Build, Tag, and push the Docker image"
# env:
# IMAGE_NAME: ghcr.io/manimatter/decluttarr
# IMAGE_TAG: dev
# run: |
# docker build -f docker/Dockerfile -t $IMAGE_NAME:$IMAGE_TAG .
# docker push $IMAGE_NAME:$IMAGE_TAG
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ __pycache__/
.pytest_cache/
.vscode/
config/config.conf
test*.py
ToDo
4 changes: 3 additions & 1 deletion docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ requests
aiohttp
asyncio
python-dateutil
verboselogs
verboselogs
pytest
pytest-asyncio
53 changes: 53 additions & 0 deletions tests/test_nest_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pytest
from src.utils.nest_functions import nested_set, add_keys_nested_dict, nested_get
import asyncio

# Dictionary that is modified / queried as part of tests
input_dict = { 1: {'name': 'Breaking Bad 1', 'data': {'episodes': 3, 'year': 1991, 'actors': ['Peter', 'Paul', 'Ppacey']}},
2: {'name': 'Breaking Bad 2', 'data': {'episodes': 6, 'year': 1992, 'actors': ['Weter', 'Waul', 'Wpacey']}},
3: {'name': 'Breaking Bad 3', 'data': {'episodes': 9, 'year': 1993, 'actors': ['Zeter', 'Zaul', 'Zpacey']}}}

@pytest.mark.asyncio
async def test_nested_set():
expected_output = { 1: {'name': 'Breaking Bad 1', 'data': {'episodes': 3, 'year': 1991, 'actors': ['Peter', 'Paul', 'Ppacey']}},
2: {'name': 'Breaking Bad 2', 'data': {'episodes': 6, 'year': 1994, 'actors': ['Weter', 'Waul', 'Wpacey']}},
3: {'name': 'Breaking Bad 3', 'data': {'episodes': 9, 'year': 1993, 'actors': ['Zeter', 'Zaul', 'Zpacey']}}}
output = input_dict
await nested_set(output, [2, 'data' ,'year'], 1994)
assert expected_output == output

@pytest.mark.asyncio
async def test_nested_set_conditions():
input = { 1: [{'year': 2001, 'rating': 'high'}, {'year': 2002, 'rating': 'high'}, {'year': 2003, 'rating': 'high'}],
2: [{'year': 2001, 'rating': 'high'}, {'year': 2002, 'rating': 'high'}, {'year': 2003, 'rating': 'high'}]}
expected_output = { 1: [{'year': 2001, 'rating': 'high'}, {'year': 2002, 'rating': 'high'}, {'year': 2003, 'rating': 'high'}],
2: [{'year': 2001, 'rating': 'high'}, {'year': 2002, 'rating': 'high'}, {'year': 2003, 'rating': 'LOW'}]}
output = input
await nested_set(output, [2, 'rating'], 'LOW', {'year': 2003})
assert expected_output == output

@pytest.mark.asyncio
async def test_nested_set_conditions_multiple():
input = { 1: [{'rating': 'high', 'color': 1, 'stack': 1}, {'rating': 'high', 'color': 2, 'stack': 2}, {'rating': 'high', 'color': 2, 'stack': 1}]}
expected_output = { 1: [{'rating': 'high', 'color': 1, 'stack': 1}, {'rating': 'high', 'color': 2, 'stack': 2}, {'rating': 'LOW', 'color': 2, 'stack': 1}]}
output = input
await nested_set(output, [1, 'rating'], 'LOW', {'color': 2, 'stack': 1})
assert expected_output == output

@pytest.mark.asyncio
async def test_add_keys_nested_dict():
expected_output = { 1: {'name': 'Breaking Bad 1', 'data': {'episodes': 3, 'year': 1991, 'actors': ['Peter', 'Paul', 'Ppacey']}},
2: {'name': 'Breaking Bad 2', 'data': {'episodes': 6, 'year': 1994, 'actors': ['Weter', 'Waul', 'Wpacey'], 'spaceship': True}},
3: {'name': 'Breaking Bad 3', 'data': {'episodes': 9, 'year': 1993, 'actors': ['Zeter', 'Zaul', 'Zpacey']}}}
output = input_dict
await add_keys_nested_dict(output, [2, 'data' ,'spaceship'], True)
assert expected_output == output


@pytest.mark.asyncio
async def test_nested_get():
input = { 1: [{'name': 'A', 'color': 1, 'stack': 1}, {'name': 'B', 'color': 2, 'stack': 2}, {'name': 'C', 'color': 2, 'stack': 1}]}
expected_output = ['C']
output = await nested_get(input[1], 'name', {'color': 2, 'stack': 1})
assert expected_output == output

Loading