From 5d2448b6400e4c60dffc470cd3c0e6d4f6f37dd1 Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Tue, 26 Dec 2023 10:50:27 -0500 Subject: [PATCH] ci: Add testing for django 5.0 and django main (#566) * ci: Improving tox workflow and updating test versions * build: Update classifiers * fix: Don't filter favs with unsaved (playground) queries * ci: Update github actions to run tox * fix: Change job name * fix: Adjust coverage path * fix: Remove coverage reporting from tox --------- Co-authored-by: Mark Walker --- .github/workflows/codeql-analysis.yml | 5 - .github/workflows/test.yml | 143 ++++++++++---------------- .gitignore | 2 +- explorer/views/utils.py | 2 +- requirements/django-3.2.txt | 3 - requirements/django-4.0.txt | 3 - requirements/django-4.1.txt | 3 - requirements/optional.txt | 2 + setup.py | 7 +- tox.ini | 19 ++-- 10 files changed, 67 insertions(+), 122 deletions(-) delete mode 100644 requirements/django-3.2.txt delete mode 100644 requirements/django-4.0.txt delete mode 100644 requirements/django-4.1.txt diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 959e7202..41f82f91 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -40,11 +40,6 @@ jobs: # a pull request then we can checkout the head. fetch-depth: 2 - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} - # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a6fc87a8..5611032a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,116 +1,79 @@ name: Tests -on: [push, pull_request] +on: + push: + branches: + - master + pull_request: concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.head_ref || github.run_id }} cancel-in-progress: true - jobs: - unit-tests: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] - django-version: ['3.2', '4.0', '4.1', '4.2b1'] - os: [ - ubuntu-20.04, - ] - exclude: - - python-version: '3.11' - django-version: '3.2' - - python-version: '3.11' - django-version: '4.0' - env: - ENABLE_TASKS: no - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements/base.txt - pip install Django==${{ matrix.django-version }} - python setup.py install - - - name: Run tests - run: coverage run --source=explorer manage.py test + tests: + name: Python ${{ matrix.python-version }} + runs-on: ubuntu-22.04 - - name: Upload Coverage to Codecov - uses: codecov/codecov-action@v3 - - unit-tests-with-optional-packages: - runs-on: ${{ matrix.os }} strategy: - fail-fast: false matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] - django-version: ['3.2', '4.0', '4.1', '4.2b1'] - os: [ - ubuntu-20.04, - ] - exclude: - - python-version: '3.11' - django-version: '3.2' - - python-version: '3.11' - django-version: '4.0' - env: - ENABLE_TASKS: yes + python-version: + - '3.10' + - '3.11' + - '3.12' + steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + cache: pip + - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install -r requirements/base.txt - pip install -r requirements/optional.txt - pip install Django==${{ matrix.django-version }} - python setup.py install - - - name: Run tests - run: coverage run --source=explorer manage.py test + python -m pip install --upgrade pip setuptools wheel + python -m pip install --upgrade 'tox>=4.0.0rc3' - - name: Upload Coverage to Codecov - uses: codecov/codecov-action@v3 + - name: Run tox targets for ${{ matrix.python-version }} + run: tox run -f py$(echo ${{ matrix.python-version }} | tr -d .) - unit-tests-future-versions: - # Runs for all Django/Python versions which are not yet supported - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - python-version: ['3.10', '3.11'] - django-version: [ - 'https://github.com/django/django/archive/main.tar.gz' - ] - os: [ - ubuntu-20.04, - ] + - name: Upload coverage data + uses: actions/upload-artifact@v4 + with: + name: coverage-data-${{ matrix.python-version }} + path: '${{ github.workspace }}/.coverage*' + coverage: + name: Coverage + runs-on: ubuntu-22.04 + needs: tests steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: '3.12' + - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install ${{ matrix.django-version }} coverage - python setup.py install + run: python -m pip install --upgrade coverage[toml] + + - name: Download data + uses: actions/download-artifact@v4 + with: + path: ${{ github.workspace }} + pattern: coverage-data-* + merge-multiple: true - - name: Run coverage - run: coverage run --source=explorer manage.py test - continue-on-error: true + - name: Combine coverage + run: | + python -m coverage combine + python -m coverage html --skip-covered --skip-empty + python -m coverage report - - name: Upload Coverage to Codecov - uses: codecov/codecov-action@v3 + - name: Upload HTML report + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: html-report + path: htmlcov diff --git a/.gitignore b/.gitignore index 679afa06..feaddbf7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ /build *# *~ -.coverage +.coverage* /htmlcov/ *.orig tmp diff --git a/explorer/views/utils.py b/explorer/views/utils.py index 298b14f9..9272e2a2 100644 --- a/explorer/views/utils.py +++ b/explorer/views/utils.py @@ -38,7 +38,7 @@ def query_viewmodel(request, query, title=None, form=None, message=None, user = request.user is_favorite = False - if user.is_authenticated: + if user.is_authenticated and query.pk: is_favorite = QueryFavorite.objects.filter(user=user, query=query).exists() ret = { diff --git a/requirements/django-3.2.txt b/requirements/django-3.2.txt deleted file mode 100644 index c013bdab..00000000 --- a/requirements/django-3.2.txt +++ /dev/null @@ -1,3 +0,0 @@ --r base.txt - -django>=3.2,<4.0 diff --git a/requirements/django-4.0.txt b/requirements/django-4.0.txt deleted file mode 100644 index 20d23b9c..00000000 --- a/requirements/django-4.0.txt +++ /dev/null @@ -1,3 +0,0 @@ --r base.txt - -django>=4.0,<4.1 diff --git a/requirements/django-4.1.txt b/requirements/django-4.1.txt deleted file mode 100644 index e0f070cd..00000000 --- a/requirements/django-4.1.txt +++ /dev/null @@ -1,3 +0,0 @@ --r base.txt - -django>=4.1rc1,<4.2 diff --git a/requirements/optional.txt b/requirements/optional.txt index d9ed98cd..e22b30ff 100644 --- a/requirements/optional.txt +++ b/requirements/optional.txt @@ -1,3 +1,5 @@ +-r base.txt + importlib-metadata<5.0; python_version <= '3.7' celery>=4.0 boto3>=1.20.0 diff --git a/setup.py b/setup.py index c1aad6b5..cc2f85ea 100644 --- a/setup.py +++ b/setup.py @@ -70,20 +70,19 @@ def read(fname): 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Topic :: Utilities', - 'Framework :: Django :: 3.2', - 'Framework :: Django :: 4.0', - 'Framework :: Django :: 4.1', 'Framework :: Django :: 4.2', + 'Framework :: Django :: 5.0', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: 3 :: Only', ], python_requires='>=3.8', install_requires=[ - 'Django>=3.2.12', + 'Django>=3.2', 'sqlparse>=0.4.0', ], extras_require={ diff --git a/tox.ini b/tox.ini index adc377ec..09a162c5 100644 --- a/tox.ini +++ b/tox.ini @@ -2,27 +2,22 @@ envlist = flake8 isort - py{38,39,310}-dj{32,40,41,42} - py{310,311}-dj{41,42,main} + {base-reqs,optional}-py{310,311,312}-dj{42,50} + {base-reqs,optional}-py{311,312}-dj{50,main} skip_missing_interpreters=True [testenv] +allowlist_externals = coverage deps = - -r{toxinidir}/requirements/base.txt - -r{toxinidir}/requirements/optional.txt - dj32: Django>=3.2,<3.3 - dj40: Django>=4.0,<4.1 - dj41: Django>=4.1,<4.2 - dj42: Django>=4.2b1,<4.3 + base-reqs: -r requirements/base.txt + dj42: django>=4.2,<5.0 + dj50: django>=5.0,<5.1 djmain: https://github.com/django/django/archive/main.tar.gz + optional: -r requirements/optional.txt commands = {envpython} --version - {env:COMMAND:coverage} erase {env:COMMAND:coverage} run manage.py test - {env:COMMAND:coverage} combine - {env:COMMAND:coverage} html --skip-covered --skip-empty - {env:COMMAND:coverage} report ignore_outcome = djmain: True ignore_errors =