Skip to content

Commit

Permalink
added github action
Browse files Browse the repository at this point in the history
  • Loading branch information
tsebastiani committed May 3, 2024
1 parent e8c2797 commit 83557f6
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 13 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build
on:
push:
branches:
- main
tags:
- '*'
pull_request:
permissions:
# https://github.community/t/permissions-nesecary-to-comment-on-a-pr/179047/5
pull-requests: write
contents: write
jobs:
test:
name: Test
strategy:
matrix:
#python-version: [ '3.9', '3.10', 'pypy3.9' ]
python-version: [ '3.9' ]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Update version number
if: startsWith(github.ref, 'refs/tags/')
run: |
sed -i -e "s/0.0.0/${GITHUB_REF##*/}/" pyproject.toml
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Check isort, black, and flake8
run: |
pip install black flake8 isort
isort --profile black .
black --line-length 79 .
flake8 .
curl -sSL https://install.python-poetry.org | python3 -
- name: Install project dependencies
run: poetry install --no-interaction
- name: Run tests with coverage
env:
TEST_PLAN_PATH: tests/functional/testdata/plan.yaml
run: |
poetry run python3 -m coverage run -a -m pytest
poetry run python3 -m coverage html
poetry run python3 -m coverage json
- name: Publish coverage report to job summary
if: ${{ matrix.python-version == '3.9'}}
run: |
poetry run html2text --ignore-images --ignore-links -b 0 htmlcov/index.html >> $GITHUB_STEP_SUMMARY
- name: Upload json coverage
uses: actions/upload-artifact@v3
with:
name: coverage.json
path: coverage.json
if-no-files-found: error
- name: Upload dist artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
if-no-files-found: error
- name: Upload coverage HTML artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: htmlcov
if-no-files-found: error

# publish:
# name: Publish Library on PyPi
# runs-on: ubuntu-latest
# needs:
# - build
# if: startsWith(github.ref, 'refs/tags/')
# steps:
# - name: Check out code
# uses: actions/checkout@v3
# - name: Download artifacts
# uses: actions/download-artifact@v3
# with:
# name: dist
# path: dist
# - name: Install twine
# run: pip install -U twine
# - name: Publish
# env:
# TWINE_USERNAME: __token__
# TWINE_PASSWORD: ${{secrets.PYPI_TOKEN}}
# TWINE_NON_INTERACTIVE: true
# run: twine upload dist/*
# build_krkn:
# name: Build Krkn Image
# runs-on: ubuntu-latest
# steps:
# - name: Rebuild krkn
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# uses: redhat-chaos/actions/krkn@main
# with:
# QUAY_USER: ${{ secrets.RH_USERNAME }}
# QUAY_TOKEN: ${{ secrets.RH_PASSWORD }}
36 changes: 23 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,36 @@

app = Flask(__name__)
logging.error("*************************INSTANCE")
method_steps: dict[(str, str), list[dict[any]]] = dict[(str, str), list[dict[any]]]()
method_steps: dict[(str, str), list[dict[any]]] = dict[
(str, str), list[dict[any]]
]()
time_keeper = TimeKeeper()


def restart_time():
start_time = time.time()


stats: list[Resource] = list[Resource]()
test_plan_path = os.environ.get("TEST_PLAN_PATH")
stats_endpoint = (
os.environ.get("STATS_ROUTE") if os.environ.get("STATS_ROUTE") else "/stats"
os.environ.get("STATS_ROUTE")
if os.environ.get("STATS_ROUTE")
else "/stats"
)


def request_handler(params: str = None):

path = request.path if not params else request.path.replace(f"/{params}", "")
path = (
request.path if not params else request.path.replace(f"/{params}", "")
)
steps = method_steps[(request.method, path)]

for request_step in steps:
if validate_step(request_step):
return Response(
f"[KRKN ERROR] invalid plan step for route {path}, method {request.method}. "
f'The following parameters are missing : "{validate_step(request_step)}". Please '
f"refer to the documentation on https://github.com/krkn-chaos/krkn-service-hijacking",
f"[KRKN ERROR] invalid plan step for "
f"route {path}, method {request.method}. "
f'The following parameters are missing : "{validate_step(request_step)}". '
f"Please refer to the documentation on "
f"https://github.com/krkn-chaos/krkn-service-hijacking",
status=500,
)

Expand Down Expand Up @@ -64,7 +68,9 @@ def request_handler(params: str = None):
request_full_path=request.full_path,
)
return Response(
steps[-1]["payload"], steps[-1]["status"], mimetype=steps[-1]["mime_type"]
steps[-1]["payload"],
steps[-1]["status"],
mimetype=steps[-1]["mime_type"],
)


Expand Down Expand Up @@ -115,9 +121,13 @@ def __add_stat_row(

for step in test_plan:
for i, method in enumerate(step["steps"]):
app.add_url_rule(step["resource"], view_func=request_handler, methods=[method])
app.add_url_rule(
f'{step["resource"]}/<params>', view_func=request_handler, methods=[method]
step["resource"], view_func=request_handler, methods=[method]
)
app.add_url_rule(
f'{step["resource"]}/<params>',
view_func=request_handler,
methods=[method],
)
method_steps[(method, step["resource"])] = step["steps"][method]
stats.append(Resource(step["resource"], method))

0 comments on commit 83557f6

Please sign in to comment.