-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (59 loc) · 2.32 KB
/
lint-and-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Lint checks & tests
on:
pull_request:
push:
branches:
- master
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # [email protected]
- name: Set up Python
uses: actions/setup-python@57ded4d7d5e986d7296eab16560982c6dd7c923b # [email protected]
with:
python-version: "3.10"
- name: Install poetry
run: pipx install poetry==1.4.2
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install
- name: Run pre-commit
run: poetry run pre-commit run --all-files
- name: Run mypy
run: poetry run mypy ichthywhat/ tests/
- name: Run tests
run: poetry run pytest
test-docker-api:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # [email protected]
- name: Build API Docker image
run: docker build -t ichthywhat .
- name: List images
run: docker images
- name: Run API Docker container
run: docker run -d --env UVICORN_HOST=0.0.0.0 -p 127.0.0.1:8000:8000 ichthywhat:latest
# Retrying all errors because it's normal for the initial request to fail while
# the container is starting. This can probably be improved with Docker health
# checks, but it's good enough for the purpose of verifying that the Dockerfile
# builds correctly and serves the API.
- name: Check container API health
run: |
output=$(curl --retry-all-errors --retry 3 -sS http://localhost:8000/)
if [[ "$output" != '"Hello!"' ]]; then
echo "Test failed. Output is: $output"
exit 1
fi
# Checking for the probability of the top result on a known image.
- name: Check prediction works
run: |
full_response=$(curl -sS -X POST -F "img_file=@tests/pterois-volitans.jpg" http://localhost:8000/predict | jq)
jq_check_result=$(echo "$full_response" | jq 'to_entries | .[0].key == "Pterois volitans"')
if [[ "$jq_check_result" != 'true' ]]; then
echo -e "Test failed. Check result: $jq_check_result\nFull response:\n$full_response"
exit 1
fi