From a13a8f1a03fbfd711cdabd5a2d4e7cf8a8171754 Mon Sep 17 00:00:00 2001 From: anchit-chandran Date: Tue, 29 Aug 2023 11:04:47 +0100 Subject: [PATCH] adds pytest on PR workflow file Signed-off-by: anchit-chandran --- ...-workflow-temp.yml => run-tests-on-pr.yml} | 157 +++++++++--------- 1 file changed, 77 insertions(+), 80 deletions(-) rename .github/workflows/{test-workflow-temp.yml => run-tests-on-pr.yml} (56%) diff --git a/.github/workflows/test-workflow-temp.yml b/.github/workflows/run-tests-on-pr.yml similarity index 56% rename from .github/workflows/test-workflow-temp.yml rename to .github/workflows/run-tests-on-pr.yml index 2e1cbce63..72adefc68 100644 --- a/.github/workflows/test-workflow-temp.yml +++ b/.github/workflows/run-tests-on-pr.yml @@ -1,80 +1,77 @@ -name: Temp workflow to test Pytest Suite - -on: - push: - branches: - - "add-cicd-auto-pytest" - workflow_dispatch: - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - - # this 'env' refers to environment variables - env: - DJANGO_CSRF_TRUSTED_ORIGINS: https://localhost,https://0.0.0.0 - E12_POSTGRES_DB_HOST: 127.0.0.1 - E12_POSTGRES_DB_NAME: test_db - E12_POSTGRES_DB_PASSWORD: postgis - E12_POSTGRES_DB_PORT: 5432 - E12_POSTGRES_DB_USER: postgis - POSTCODES_IO_API_URL: https://api.postcodes.io - RCPCH_CENSUS_PLATFORM_TOKEN: ${{ secrets.RCPCH_CENSUS_PLATFORM_TOKEN }} - RCPCH_CENSUS_PLATFORM_URL: https://api.rcpch.ac.uk/deprivation/v1 - RCPCH_HERMES_SERVER_URL: http://rcpch-hermes.uksouth.azurecontainer.io:8080/v1/snomed - - # this 'environment' refers to GitHub Environments, not environment variables - environment: - name: "development" - url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - services: - postgis: - image: postgis/postgis:15-3.3 - env: - POSTGRES_USER: postgis - POSTGRES_PASSWORD: postgis - POSTGRES_DB: test_db - ports: - - 5432:5432 - # needed because the postgis container does not provide a healthcheck - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - - steps: - - uses: actions/checkout@v3 - - - name: List all files - run: ls -al - - - name: Set up Python version - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - - name: Install PostGIS dependencies - run: sudo apt-get install -y binutils libproj-dev gdal-bin libgdal-dev python3-gdal - - - name: Create and start virtual environment - run: | - python -m venv venv - source venv/bin/activate - - # python dependencies - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - # run migrations - - name: Run migrations - run: python manage.py migrate - - - name: collect static files - run: python manage.py collectstatic --noinput - - # Run Pytest Suite - - name: print settings for debugging purposes - run: python manage.py diffsettings --all - - - name: Pytest Suite - run: pytest -rP + + +name: Pytest Suite + +on: + pull_request: + branches: + - "*" + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + # this 'environment' refers to GitHub Environments, not environment variables + environment: + name: "development" + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + # this 'env' refers to environment variables + env: + DJANGO_CSRF_TRUSTED_ORIGINS: https://localhost,https://0.0.0.0 + E12_POSTGRES_DB_HOST: 127.0.0.1 + E12_POSTGRES_DB_NAME: test_db + E12_POSTGRES_DB_PASSWORD: postgis + E12_POSTGRES_DB_PORT: 5432 + E12_POSTGRES_DB_USER: postgis + POSTCODES_IO_API_URL: https://api.postcodes.io + RCPCH_CENSUS_PLATFORM_TOKEN: ${{ secrets.RCPCH_CENSUS_PLATFORM_TOKEN }} + RCPCH_CENSUS_PLATFORM_URL: https://api.rcpch.ac.uk/deprivation/v1 + RCPCH_HERMES_SERVER_URL: http://rcpch-hermes.uksouth.azurecontainer.io:8080/v1/snomed + + # Sets up a Postgis container for the test db + services: + postgis: + image: postgis/postgis:15-3.3 + env: + POSTGRES_USER: postgis + POSTGRES_PASSWORD: postgis + POSTGRES_DB: test_db + ports: + - 5432:5432 + # needed because the postgis container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python version + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install PostGIS dependencies + run: | + sudo apt-get update + sudo apt-get install -y binutils libproj-dev gdal-bin libgdal-dev python3-gdal + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + # python dependencies + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + # run migrations + - name: Run migrations + run: python manage.py migrate + + # Runs tests + - name: Pytest Suite + run: pytest -rP + +