Skip to content

Commit

Permalink
Fix workflow after Ubuntu and Python upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
terhisalonen committed Jan 19, 2024
1 parent 2c60cf7 commit 6e66f23
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 47 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ jobs:
tests:
strategy:
matrix:
python: ["3.5", "3.6", "3.8"]
runs-on: ubuntu-20.04
container: "python:${{matrix.python}}-slim-buster"
python: ["3.10"] #3.10
runs-on: ubuntu-22.04 #ubuntu:jammy-20231004
# container: "python:${{matrix.python}}-slim-buster"
steps:
- uses: actions/checkout@v3

- name: Update apt-get sources
run: apt-get update
run: sudo apt-get update

- name: Install PostgreSQL, PostGIS and GDAL
run: >
apt-get install -y
sudo apt-get install -y
gdal-bin
python3-gdal
postgis
Expand All @@ -32,14 +32,14 @@ jobs:
build-essential
- name: Start PostgreSQL server
run: /etc/init.d/postgresql start
run: sudo /etc/init.d/postgresql start

- name: Allow root to create PostgreSQL databases
run: su - postgres -c "createuser --createdb root"
- name: Allow runner to create PostgreSQL databases
run: sudo su - postgres -c "createuser --createdb runner"

- name: Create PostGIS extension
run: >
su - postgres
sudo su - postgres
-c "psql template1 -c 'create extension postgis'"
- name: Install Tox and tox-gh-actions
Expand All @@ -52,7 +52,7 @@ jobs:
uses: codecov/codecov-action@v3

test-dockerization:
runs-on: ubuntu-22.04
runs-on: ubuntu-22.04 #ubuntu:jammy-20231004
steps:
- uses: actions/checkout@v3

Expand All @@ -72,14 +72,14 @@ jobs:
strategy:
matrix:
toxenv: [style, requirements, sanitizer]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04 #ubuntu:jammy-20231004
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/[email protected]
with:
python-version: "3.5"
python-version: "3.10" #3.10

- name: Install GDAL
run: sudo apt-get install -y gdal-bin
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN touch /.dockerenv
RUN apt-get update \
&& apt-get install --yes \
git \
netcat \
sudo \
vim \
zsh \
Expand Down
3 changes: 1 addition & 2 deletions parkings/api/auth/drf_jwt_2fa_urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.urls import re_path

from drf_jwt_2fa import views

urlpatterns = [
re_path('^get-code/', views.obtain_code_token, name='get-code'),
re_path('^auth/', views.obtain_auth_token, name='auth'),
re_path('^refresh/', views.refresh_auth_token, name='refresh'),
re_path('^verify/', views.verify_auth_token, name='verify'),
]
]
1 change: 0 additions & 1 deletion parkings/api/enforcement/valid_permit_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def to_representation(self, instance):
return representation



class ValidPermitItemFilter(django_filters.rest_framework.FilterSet):
reg_num = django_filters.CharFilter(
label=_("Registration number"), method='filter_reg_num')
Expand Down
1 change: 1 addition & 0 deletions parkings/api/url_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import include, re_path


def versioned_url(version, include_urls, regexp=r'^'):
return re_path(
'{regexp}{version}/'.format(regexp=regexp, version=version),
Expand Down
2 changes: 1 addition & 1 deletion parkings/models/parking_check.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf import settings
from django.contrib.gis.db import models as gis_models
from django.db.models import JSONField
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models
from django.db.models import JSONField
from django.utils.translation import gettext_lazy as _

from .constants import WGS84_SRID
Expand Down
2 changes: 1 addition & 1 deletion parkings/models/permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from django.conf import settings
from django.contrib.gis.db import models as gis_models
from django.contrib.postgres.fields import JSONField
from django.core.serializers.json import DjangoJSONEncoder
from django.db import connections, models, router, transaction
from django.db.models import JSONField
from django.db.models.expressions import RawSQL
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
Expand Down
2 changes: 1 addition & 1 deletion parkings/tests/api/monitoring/test_valid_parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_list_endpoint_data(monitoring_api_client, parking):

def check_parking_feature_shape(parking_feature):
assert set(parking_feature.keys()) == {
'id', 'type','time_start', 'time_end', 'geometry', 'properties'}
'id', 'type', 'time_start', 'time_end', 'geometry', 'properties'}
assert parking_feature['type'] == 'Feature'
assert set(parking_feature['geometry'].keys()) == {
'type', 'coordinates'}
Expand Down
7 changes: 3 additions & 4 deletions parkkihubi/settings.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import os
from datetime import timedelta

import django
from django.utils.encoding import smart_str
from django.utils.translation import gettext, gettext_lazy
from environ import Env
from raven import fetch_git_sha
from raven.exceptions import InvalidGitRepository

# Prevent warning regarding
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

import django
from django.utils.translation import gettext_lazy
django.utils.translation.ugettext_lazy = gettext_lazy
from django.utils.translation import gettext
django.utils.translation.ugettext = gettext
from django.utils.encoding import smart_str
django.utils.encoding.smart_text = smart_str


Expand Down
2 changes: 1 addition & 1 deletion parkkihubi/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.urls import include, re_path
from django.contrib import admin
from django.urls import include, re_path

from parkings.api.auth import urls as auth_urls
from parkings.api.enforcement import urls as enforcement_urls
Expand Down
4 changes: 2 additions & 2 deletions post-update
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fi

# Update the backend
pip install -r requirements-pip.txt
pip install -r requirements-prequ.txt
prequ sync requirements.txt
# pip install -r requirements-prequ.txt
# prequ sync requirements.txt

./manage.py collectstatic --noinput

Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ python-dateutil==2.8.2
# freezegun
pyyaml==6.0.1
# via -r requirements-test.in
requests==2.24.0
requests==2.25.1
# via
# -c requirements-cov.txt
# requests-mock
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ django-environ==0.4.5
# via -r requirements.in
django-filter==2.3.0
# via -r requirements.in
django-sanitized-dump==1.2.1
django-sanitized-dump==1.2.2
# via -r requirements.in
djangorestframework==3.14.0
# via
Expand All @@ -52,7 +52,7 @@ pyproj==3.3.0
# via
# -r requirements.in
# owslib
python-dateutil==2.8.1
python-dateutil==2.8.2
# via owslib
python-memcached==1.59
# via -r requirements.in
Expand All @@ -61,7 +61,7 @@ pytz==2023.3.post1
# -r requirements.in
# django
# owslib
pyyaml==5.3.1
pyyaml==6.0.1
# via
# database-sanitizer
# django-sanitized-dump
Expand All @@ -72,7 +72,7 @@ requests==2.25.1
# via
# -r requirements.in
# owslib
six==1.15.0
six==1.16.0
# via
# database-sanitizer
# django-sanitized-dump
Expand Down
29 changes: 22 additions & 7 deletions run-pytest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# Run pytest locally or on docker-compose app service
# Run pytest locally or on docker-compose runserver service
#
# When using docker-compose app service, the options passed by VSCodium
# When using docker-compose runserver service, the options passed by VSCodium
# will be handled specially to make its pytest integration smoother.
#
# To run pytest within docker, set USE_DOCKER environment variable to 1
Expand All @@ -16,13 +16,22 @@ fi

if [[ "$USE_DOCKER" == "1" ]] || [[ "$USE_DOCKER" == "yes" ]]; then
docker-compose up -d
# Check if the container is running
container_id=$(docker-compose ps -q)
if [[ -z "$container_id" ]]; then
echo "Error: Container failed to start."
exit 1
fi

echo "Container is running with ID: $container_id"
else
exec pytest "$@"
exit $?
fi

unset xml_file
opts=()

while [[ $# -gt 0 ]]; do
opt="$1"
shift
Expand All @@ -44,17 +53,23 @@ docker_compose_exec=("docker-compose" "exec")
if ! tty -s; then
docker_compose_exec+=("-T") # If there is no TTY available, pass -T
fi

echo "here 0"
# Wait until the database is ready
"${docker_compose_exec[@]}" -e RUN_MIGRATIONS=0 app ./docker-entrypoint /bin/true
"${docker_compose_exec[@]}" -e RUN_MIGRATIONS=0 runserver ./docker-entrypoint /bin/true

echo "here 1"
set +e
"${docker_compose_exec[@]}" app pytest "${misc_opts[@]}" "${opts[@]}"
output="$("${docker_compose_exec[@]}" runserver pytest "${misc_opts[@]}" "${opts[@]}" 2>&1)"
exit_code=$?
set -e

echo "here 2"
if [[ -n "$xml_file" ]]; then
"${docker_compose_exec[@]}" app cat /tmp/pytest_junit.xml > "$xml_file"
"${docker_compose_exec[@]}" runserver cat /tmp/pytest_junit.xml > "$xml_file"
fi
echo "here 3"

if [ $exit_code -ne 0 ]; then
echo "$output"
fi

exit $exit_code
18 changes: 8 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{35,36,37,38},requirements,style
envlist = py310,requirements,style
skipsdist = True

[testenv]
Expand All @@ -12,28 +12,26 @@ setenv =
SECRET_KEY=topsecret123
commands =
pytest -ra -vvv --strict --doctest-modules \
--exitfirst \ # DEBUGGING ONLY
{posargs:--cov=. --cov-report=term --cov-report=xml}

[testenv:requirements]
basepython = python3.5
basepython = python3.10
deps =
-rrequirements-pip.txt
-rrequirements-prequ.txt
commands = prequ {posargs:check -v}
commands = pip {posargs:check}

[testenv:style]
basepython = python3.5
basepython = python3.10
deps = -rrequirements-style.txt
commands = flake8 {posargs:--enable=T}

[testenv:sanitizer]
basepython = python3.5
basepython = python3.10
deps = -rrequirements.txt
commands = ./manage.py check_sanitizerconfig
commands = {base_python} manage.py check_sanitizerconfig

[gh-actions]
python =
3.5: py35
3.6: py36
3.8: py38
3.10: py310
problem_matcher = False

0 comments on commit 6e66f23

Please sign in to comment.