From 8b313a398a2fe0fd3e1535177d2151decc415f97 Mon Sep 17 00:00:00 2001 From: RusticPotato <3542090+RusticPotatoes@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:22:02 -0400 Subject: [PATCH] GitHub workflow init for pytest (#17) * merge conflicts * removing unused * remove test requirements and docker runs in detached mode * add workflow for pytest * Revert "merge conflicts" This reverts commit 553305ab3b89fbba7f357a70e81eecd0d5e9335f. * run on self hosted + minor changes * on push & pull request * fix style * sudo apt install python3-venv -y * make file improvements * run deployment affter succesfull test --------- Co-authored-by: extreme4all <40169115+extreme4all@users.noreply.github.com> --- .github/workflows/hetzner-prd-workflow.yml | 9 +-- .github/workflows/pytest-workflow.yml | 74 ++++++++++++++++++++++ Makefile | 23 +++---- requirements.txt | 1 - 4 files changed, 91 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/pytest-workflow.yml diff --git a/.github/workflows/hetzner-prd-workflow.yml b/.github/workflows/hetzner-prd-workflow.yml index e85fff1f..75e8ffc3 100644 --- a/.github/workflows/hetzner-prd-workflow.yml +++ b/.github/workflows/hetzner-prd-workflow.yml @@ -1,13 +1,14 @@ name: hetzner production workflow -# Controls when the workflow will run -# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows on: - # Triggers the workflow on push events but only for the "develop" branch push: branches: - develop - + workflow_run: + workflows: ["Pytest report"] + types: + - completed + # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.github/workflows/pytest-workflow.yml b/.github/workflows/pytest-workflow.yml new file mode 100644 index 00000000..94f72a9b --- /dev/null +++ b/.github/workflows/pytest-workflow.yml @@ -0,0 +1,74 @@ +name: Pytest report + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + linter: + name: Black Syntax Check + runs-on: [self-hosted, "hetzner"] + steps: + - uses: actions/checkout@v3 + + - name: Install python3-venv package + run: sudo apt update && sudo apt install python3-venv -y + + - name: Run Black + uses: psf/black@stable + with: + options: "--check --verbose" + src: "./src" + + Build-Test: + name: Setup Enviornment and Run Tests + runs-on: [self-hosted, "hetzner"] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: "3.11.6" + + - name: Setup Docker Containers + run: | + make setup-detached + + - name: Check API is Up + uses: cygnetdigital/wait_for_response@v2.0.0 + with: + url: 'http://localhost:5000/docs' + responseCode: '200,500' + timeout: 120000 # wait up to 120 seconds + interval: 5000 # poll every 5 seconds + + - name: Generate Pytest Report + run: | + make test-report + + # https://github.com/marketplace/actions/pytest-results-actions + - name: Surface Failing Tests + if: always() + uses: pmeier/pytest-results-action@main + with: + # A list of JUnit XML files, directories containing the former, and wildcard + # patterns to process. + # See @actions/glob for supported patterns. + path: pytest_report.xml + + # Add a summary of the results at the top of the report + # Default: true + summary: true + + # Select which results should be included in the report. + # Follows the same syntax as + # `pytest -r` + # Default: fEX + display-options: fEX + + # Fail the workflow if no JUnit XML was found. + # Default: true + fail-on-empty: true \ No newline at end of file diff --git a/Makefile b/Makefile index 265f13d3..5f1c7e4b 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,9 @@ clean-test: ## cleanup pytests leftovers test: clean-test ## Run pytest unit tests python3 -m pytest --verbosity=1 +test-report: + python3 -m pytest --junit-xml=pytest_report.xml + test-debug: ## Run unit tests with debugging enabled python3 -m pytest --pdb @@ -46,17 +49,21 @@ docker-up: ## Startup docker docker-build: ## Startup docker with build switch docker-compose --verbose up --build -setup: requirements venv-create pre-commit-setup docker-build test-setup api-setup ## setup & run after downloaded repo +docker-build-detached: ## Startup docker with build switch + docker-compose up --build -d + +setup: venv-create requirements pre-commit-setup docker-build test-setup ## setup & run after downloaded repo + +setup-detached: venv-create requirements pre-commit-setup docker-build-detached test-setup ## setup & run after downloaded repo detached pre-commit-setup: ## Install pre-commit python3 -m pip install pre-commit pre-commit --version -pre-commit: ## Run pre-commit - pre-commit run --all-files - test-setup: ## installs pytest singular package for local testing python3 -m pip install pytest + python3 -m pip install requests + python3 -m pip install hypothesis requirements: ## installs all requirements python3 -m pip install -r requirements.txt @@ -70,9 +77,6 @@ docker-rebuild: docker-down ## shuts down docker then brings it up and rebuilds docker-force-rebuild: docker-down ## shuts down docker than brings it up and force rebuilds docker-compose --verbose up --build --force-recreate -api-setup: ## installs fastapi singular package, for local testing - python3 -m pip install "fastapi[all]" - docs: # opens your browser to the webapps testing docs open http://localhost:5000/docs xdg-open http://localhost:5000/docs @@ -82,7 +86,4 @@ venv-create: venv-remove ## cleans the .venv then creates a venv in the folder . python3 -m venv .venv venv-remove: ## removes the .venv folder - rm -rf .venv - -check: ## run pre commit hooks for github, should do black checks - pre-commit \ No newline at end of file + rm -rf .venv \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3ab70794..30f945d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -40,5 +40,4 @@ uvicorn==0.23.2 virtualenv==20.24.5 watchfiles==0.20.0 websockets==11.0.3 -hypothesis==6.88.1 cryptography==41.0.4 \ No newline at end of file