Skip to content

Commit 8cdbaaf

Browse files
committed
fix: github actions
1 parent 4d0bde0 commit 8cdbaaf

File tree

6 files changed

+50
-32
lines changed

6 files changed

+50
-32
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ name: Lint
44

55
on:
66
pull_request:
7-
workflow_call:
87

98
jobs:
109
lint:
1110
runs-on: ubuntu-latest
1211
steps:
1312
- uses: actions/checkout@v2
14-
- name: black Lint
13+
- name: Run black
1514
uses: psf/black@stable
1615
with:
1716
options: "--check --diff"
1817
src: "."
1918
version: "22.8.0"
20-
- name: isort Lint
19+
- name: Run isort
2120
uses: isort/isort-action@master
22-
- name: flake8 Lint
21+
- name: Run flake8
2322
uses: py-actions/flake8@v2

.github/workflows/tests.yml

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ concurrency:
55
cancel-in-progress: true
66

77
on:
8-
push:
98
pull_request:
109

1110
jobs:
1211
tests:
1312
runs-on: ubuntu-latest
13+
environment: testing
1414
services:
1515
postgres:
1616
image: postgres
@@ -23,30 +23,45 @@ jobs:
2323
--health-retries 5
2424
ports:
2525
- 5432:5432
26+
container:
27+
image: python:3.12
28+
env:
29+
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
30+
CACHE_FILE: /tmp/meep
31+
POETRY_VIRTUALENVS_CREATE: "false"
32+
MAPIT_URL: https://mapit.mysociety.org/
33+
MAPIT_API_KEY: "not_a_key"
34+
TEST_AIRTABLE_BASE_ID: ${{ vars.TEST_AIRTABLE_BASE_ID }}
35+
TEST_AIRTABLE_TABLE_NAME: ${{ vars.TEST_AIRTABLE_TABLE_NAME }}
36+
TEST_AIRTABLE_API_KEY: ${{ secrets.TEST_AIRTABLE_API_KEY }}
37+
SECRET_KEY: keyboardcat
2638
steps:
27-
- name: checkout repo content
39+
- name: Checkout repo content
2840
uses: actions/checkout@v2
29-
41+
- name: Install linux dependencies
42+
run: |
43+
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null
44+
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | tee /etc/apt/sources.list.d/ngrok.list
45+
apt-get update && apt-get install -y binutils gdal-bin libproj-dev ngrok less
46+
- name: Install poetry
47+
run: curl -sSL https://install.python-poetry.org | python3 -
48+
- name: Install python dependencies
49+
run: ~/.local/bin/poetry export --with dev -f requirements.txt --output requirements.txt && pip install -r requirements.txt
50+
- name: Start server
51+
run: gunicorn local_intelligence_hub.asgi:application -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 &
52+
- name: Start ngrok tunnelling
53+
run: |
54+
ngrok authtoken ${{ secrets.NGROK_AUTHTOKEN }}
55+
ngrok http 8000 --log=stdout > ngrok.log &
56+
- name: Extract ngrok URL
57+
run: BASE_URL=$(cat ngrok.log | grep 'url=' | awk -F= '{print $NF}') && echo "BASE_URL=$BASE_URL" > .env
3058
- name: Run django tests
31-
uses: ./.github/actions/in-container
32-
env:
33-
DATABASE_URL: postgres://postgres:postgres@postgres/postgres
34-
CACHE_FILE: /tmp/meep
35-
SECRET_KEY: keyboardcat
36-
with:
37-
run: |
38-
script/bootstrap
39-
script/test --coverage
40-
41-
# do this inside the docker container otherwise the paths don't work
42-
- name: generate coverage xml
43-
uses: ./.github/actions/in-container
44-
with:
45-
run: coverage xml
46-
47-
# do this outside the docker container otherwise can't get repo details
48-
- name: upload code coverage
59+
run: cat .env && coverage run --source=. --branch manage.py test
60+
- name: Generate coverage xml
61+
run: coverage xml
62+
- name: Upload code coverage
4963
run: |
5064
less coverage.xml
5165
pip install codecov
5266
codecov
67+

hub/middleware.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def record_last_seen_middleware(get_response):
2424
def process_request(request):
2525
if request.user.is_authenticated:
2626
user = request.user
27-
props = UserProperties.objects.get_or_create(user=user)
27+
props, _ = UserProperties.objects.get_or_create(user=user)
2828
last_seen = request.session.get("last_seen", None)
2929
yesterday = now().replace(hour=0, minute=0) - one_day
3030
if last_seen is None or last_seen < yesterday.timestamp():
@@ -33,11 +33,13 @@ def process_request(request):
3333
props.save()
3434

3535
if iscoroutinefunction(get_response):
36+
3637
async def middleware(request: HttpRequest):
3738
await sync_to_async(process_request)(request)
3839
return await get_response(request)
3940

4041
else:
42+
4143
def middleware(request: HttpRequest):
4244
process_request(request)
4345
return get_response(request)
@@ -51,13 +53,15 @@ def logic(request):
5153
return WhiteNoiseMiddleware(get_response)(request)
5254

5355
if iscoroutinefunction(get_response):
56+
5457
async def middleware(request: HttpRequest):
5558
response = logic(request)
5659
if isawaitable(response):
5760
response = await response
5861
return response
5962

6063
else:
64+
6165
def middleware(request: HttpRequest):
6266
return logic(request)
6367

@@ -81,6 +85,7 @@ def exception_handler(error: Exception, request: HttpRequest):
8185
setattr(request, USER_OR_ERROR_KEY, user_or_error)
8286

8387
if iscoroutinefunction(get_response):
88+
8489
async def middleware(request: HttpRequest):
8590
try:
8691
return await gqlauth_middleware(request)
@@ -89,10 +94,11 @@ async def middleware(request: HttpRequest):
8994
return await get_response(request)
9095

9196
else:
97+
9298
def middleware(request: HttpRequest):
9399
try:
94100
return gqlauth_middleware(request)
95-
except Exception as e:
101+
except Exception:
96102
exception_handler(request)
97103
return get_response(request)
98104

hub/views/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from django.db import connection
22
from django.db.utils import OperationalError
3-
from django.http import JsonResponse
3+
from django.http import HttpResponse, JsonResponse
44
from django.views.generic import TemplateView
55

66
from hub.mixins import TitleMixin
77
from hub.models import Area, DataSet
8-
from django.http import HttpResponse
98

109

1110
async def async_healthcheck(request):

local_intelligence_hub/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
https://docs.djangoproject.com/en/4.1/ref/settings/
1111
"""
1212

13-
import socket
1413
from datetime import timedelta
1514
from pathlib import Path
1615

@@ -28,7 +27,7 @@
2827
SCHEDULED_UPDATE_SECONDS_DELAY=(int, 3),
2928
DEBUG=(bool, False),
3029
ALLOWED_HOSTS=(list, []),
31-
CORS_ALLOWED_ORIGINS=(list, ['http://localhost:3000']),
30+
CORS_ALLOWED_ORIGINS=(list, ["http://localhost:3000"]),
3231
GOOGLE_ANALYTICS=(str, ""),
3332
GOOGLE_SITE_VERIFICATION=(str, ""),
3433
TEST_AIRTABLE_BASE_ID=(str, ""),

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ requests-cache = "^0.9.6"
1515
Pillow = "^10.2.0"
1616
python-magic = "^0.4.27"
1717
tqdm = "^4.64.1"
18+
pandas = "^2.2.1"
1819
openpyxl = "^3.0.10"
1920
mysoc-dataset = "^0.3.0"
2021
django-jsonform = "^2.15.0"
@@ -34,7 +35,6 @@ whitenoise = "^6.6.0"
3435
setuptools = "^69.1.1"
3536
uvicorn = "^0.27.1"
3637
strawberry-graphql = {extras = ["asgi"], version = "^0.220.0"}
37-
pandas = "^2.2.1"
3838

3939
[tool.poetry.dev-dependencies]
4040
black = "^22.8.0"

0 commit comments

Comments
 (0)