Skip to content

Commit

Permalink
💚 [api]: add format check for python apps #153
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-wong committed Nov 9, 2021
1 parent 50f1410 commit 3d467eb
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
6 changes: 5 additions & 1 deletion .github/actions/setup-python-app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
app-name:
description: 'Python app project name'
required: true
create-db:
description: 'Create database for testing'
required: true
runs:
using: 'composite'
steps:
Expand All @@ -25,7 +28,8 @@ runs:
run: echo "TEST_DB=${{ steps.random-generator.outputs.random-id }}" >> apps/${{ inputs.app-name }}/.env
shell: bash
- name: Create testing database
run: ./.github/actions/setup-python-app/create_db.sh ${{ steps.random-generator.outputs.random-id }}
run: |
${{ inputs.create-db }} && ./.github/actions/setup-python-app/create_db.sh ${{ steps.random-generator.outputs.random-id }} || true
shell: bash
env:
POSTGRES_USER: postgres
Expand Down
32 changes: 22 additions & 10 deletions .github/workflows/pr-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,30 @@ jobs:
version: 6.0.2
- name: Install modules
run: pnpm i
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install Poetry
run: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
- name: Setup api-evidence
uses: ./.github/actions/setup-python-app
with:
app-name: 'api-evidence'
create-db: false
- name: Setup api-dispute
uses: ./.github/actions/setup-python-app
with:
app-name: 'api-dispute'
create-db: false
- name: Check Python code format
run: pnpx nx run-many --target=format --check --all --parallel
- name: Check code format
run: pnpx nx format:check --base=origin/main

lint:
name: Lint
runs-on: ubuntu-20.04
services:
postgres:
image: postgres:13.4
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout code into workspace directory
uses: actions/checkout@v2
Expand Down Expand Up @@ -80,10 +88,12 @@ jobs:
uses: ./.github/actions/setup-python-app
with:
app-name: 'api-evidence'
create-db: false
- name: Setup api-dispute
uses: ./.github/actions/setup-python-app
with:
app-name: 'api-dispute'
create-db: false
- name: Lint source code
run: pnpx nx affected:lint --base=origin/main --parallel
# TODO
Expand Down Expand Up @@ -192,10 +202,12 @@ jobs:
uses: ./.github/actions/setup-python-app
with:
app-name: 'api-evidence'
create-db: true
- name: Setup api-dispute
uses: ./.github/actions/setup-python-app
with:
app-name: 'api-dispute'
create-db: true
- name: Run unit tests
run: pnpx nx affected:test --base=origin/main --parallel

Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ node_modules
cache
logs
log
**/.venv
**/.pytest_cache
1 change: 1 addition & 0 deletions apps/api-dispute/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ exclude = "migrations"
[tool.black]
include = '\.py$'
skip-string-normalization = true
exclude = "migrations"

[build-system]
requires = ["setuptools", "wheel"]
Expand Down
2 changes: 1 addition & 1 deletion apps/api-dispute/src/app/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_ping(client: TestClient) -> None:
"judgeContract": valid_eth_address,
"token": valid_eth_address,
"discount": 40,
"ethPaid": "1000000"
"ethPaid": "1000000",
},
True,
),
Expand Down
3 changes: 3 additions & 0 deletions apps/api-evidence/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
},
"lint": {
"executor": "nx-python-fastapi:lint"
},
"format": {
"executor": "nx-python-fastapi:format"
}
},
"tags": ["scope:api", "type:app"]
Expand Down
1 change: 1 addition & 0 deletions apps/api-evidence/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exclude = "migrations"
[tool.black]
include = '\.py$'
skip-string-normalization = true
exclude = "migrations"

[build-system]
requires = ["setuptools", "wheel"]
Expand Down

0 comments on commit 3d467eb

Please sign in to comment.