Skip to content

Commit 1f8385f

Browse files
authoredApr 29, 2021
👷 Add CI (#57)
1 parent f550809 commit 1f8385f

File tree

7 files changed

+81
-3
lines changed

7 files changed

+81
-3
lines changed
 

‎.github/workflows/ci.yaml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
tests:
7+
name: Setup
8+
runs-on: ubuntu-latest
9+
services:
10+
postgres:
11+
image: postgres:12
12+
env:
13+
POSTGRES_USER: user
14+
POSTGRES_PASSWORD: password
15+
POSTGRES_DB: app
16+
ports:
17+
- 5432:5432
18+
redis:
19+
image: redis:alpine
20+
ports:
21+
- 6379:6379
22+
steps:
23+
- name: Checkout working branch
24+
uses: actions/checkout@v2
25+
26+
- name: Set up Python 3.8
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: 3.8
30+
31+
- name: Cache pip
32+
uses: actions/cache@v2
33+
with:
34+
path: ~/.cache/pip
35+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
36+
restore-keys: |
37+
${{ runner.os }}-pip-
38+
39+
- name: Set environment variables
40+
run: |
41+
echo "PYTHONPATH=$(pwd)/users" >> $GITHUB_ENV
42+
echo "POSTGRES_DB=app" >> $GITHUB_ENV
43+
echo "POSTGRES_HOST=localhost:5432" >> $GITHUB_ENV
44+
echo "POSTGRES_USER=user" >> $GITHUB_ENV
45+
echo "POSTGRES_PASSWORD=password" >> $GITHUB_ENV
46+
echo "PROJECT_NAME=Project" >> $GITHUB_ENV
47+
echo "FIRST_USER_EMAIL=user@user.com" >> $GITHUB_ENV
48+
echo "FIRST_USER_PASSWORD=user" >> $GITHUB_ENV
49+
echo "SECRET_KEY=secret" >> $GITHUB_ENV
50+
echo "ACCESS_TOKEN_EXPIRE_MINUTES=10" >> $GITHUB_ENV
51+
echo "REDIS_HOST=localhost" >> $GITHUB_ENV
52+
echo "REDIS_PORT=6379" >> $GITHUB_ENV
53+
54+
- name: Install dependencies
55+
run: |
56+
python -m pip install --upgrade pip
57+
pip install -r users/requirements.txt
58+
59+
- name: Lint
60+
run: make lint
61+
62+
- name: Database migrations
63+
run: |
64+
cd users
65+
alembic upgrade head
66+
67+
- name: Create initial data
68+
run: python users/scripts/initial_data.py
69+
70+
- name: Test
71+
run: pytest users/tests --cov users/app --cov-report=term-missing:skip-covered --cov-report=xml --cov-fail-under 69

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ format: ## Format code
3838
tests: ## Run tests
3939
@echo "🍜 Running tests..."
4040
@$(eval POD=$(shell sh -c 'kubectl get pod -l app=users -o jsonpath="{.items[0].metadata.name}"'))
41-
@kubectl exec $(POD) -- pytest -v tests
41+
@kubectl exec $(POD) -- pytest -v tests --cov app --cov-report=term-missing:skip-covered --cov-report=xml --cov-fail-under 69
4242

4343

4444
.PHONY: migrations

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ The only one that I've used for that purpose for a long time was the mentioned "
4747
* [Asynchronous I/O (asyncio) SQLALchemy documentation](https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html)
4848
* [Full Stack FastAPI and PostgreSQL - Base Project Generator](https://github.com/tiangolo/full-stack-fastapi-postgresql)
4949
* [The inner working of ARQ](https://threeofwands.com/the-inner-workings-of-arq/)
50+
* [How we set up a production CI workflow with GitHub actions](https://insights.project-a.com/how-we-set-up-a-production-ci-workflow-with-github-actions-cc1e2aacd9da)
51+
* [Using GitHub to deploy kubernetes](https://insights.project-a.com/using-github-actions-to-deploy-to-kubernetes-122c653c0b09)
5052

5153
## License
5254

‎setup.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ per-file-ignores =
1111

1212
[mypy]
1313
follow_imports = skip
14+
15+
# Reference: https://github.com/nedbat/coveragepy/issues/1082
16+
[coverage:run]
17+
concurrency = greenlet

‎users/app/core/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Settings(BaseSettings):
1717
def validate_postgres_conn(cls, v: Optional[str], values: Dict[str, Any]) -> str:
1818
if isinstance(v, str):
1919
return v
20-
password: SecretStr = values.get("POSTGRES_PASSWORD")
20+
password: SecretStr = values.get("POSTGRES_PASSWORD", SecretStr(""))
2121
return "{scheme}://{user}:{password}@{host}/{db}".format(
2222
scheme="postgresql+asyncpg",
2323
user=values.get("POSTGRES_USER"),

‎users/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ uvloop==0.15.2
1414
# TODO(Marcelo): Add dev requirements.
1515
pytest==6.2.3
1616
pytest-asyncio==0.15.0
17+
pytest-cov==2.11.1
1718
flake8==3.9.1
1819
isort==5.8.0
1920
black==20.8b1

‎users/tests/test_login.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ async def test_login(client: AsyncSession):
1111
"password": settings.FIRST_USER_PASSWORD.get_secret_value(),
1212
}
1313
res = await client.post("/api/v1/login/", data=login_data)
14-
assert res.status_code == 200
14+
assert res.status_code == 200, res.json()
1515
assert res.json().get("token_type") == "bearer"
1616
assert "access_token" in res.json().keys()

0 commit comments

Comments
 (0)
Please sign in to comment.