diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml new file mode 100644 index 0000000..6574246 --- /dev/null +++ b/.github/workflows/CI.yaml @@ -0,0 +1,62 @@ +name: CI +on: [push, pull_request] +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + + - name: Install Python dependencies + run: pip install black flake8 + + - name: Run linters + uses: wearerequired/lint-action@v2 + with: + auto_fix: true + black: true + black_args: --config=./configs/pyproject.toml + black_auto_fix: true + flake8: true + flake8_args: --config=./configs/.flake8 + flake8_auto_fix: false + commit_message: "style: format code with black and flake8" + + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Testing the code with pytest + run: | + pytest --cov=./arquimedia --cov-report xml:coverage.xml --cov-report term-missing tests/ + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + fail_ci_if_error: true + + check-conventional-commits: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: webiny/action-conventional-commits@v1.1.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0bbafa8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: +- repo: https://github.com/compilerla/conventional-pre-commit + rev: v2.1.1 + hooks: + - id: conventional-pre-commit + stages: [ commit-msg ] + +- repo: https://github.com/pycqa/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + args: [--config=./configs/.flake8] + +- repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + args: [--config=./configs/pyproject.toml] \ No newline at end of file diff --git a/README.md b/README.md index b97cc15..a23076d 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,12 @@ make logs This will show the logs of the docker container. +Might also be useful to enter the container's shell and run commands manually. To do so, run the following command: + +```bash +make shell +``` + ## Testing To test the project, you need to run the following command: @@ -79,6 +85,24 @@ To access the documentation, you need to run the project and access the followin http://localhost:8001/docs ``` +## Pre-commit + +This project uses [pre-commit](https://pre-commit.com/) to run some checks before committing. + +To install hooks, run the following command: + +```bash +pre-commit install +``` + +This checks will run automatically before every commit and will check for: + +- [x] Black +- [x] Flake8 +- [x] Conventional Commits + +This is a useful tool to keep the code clean and consistent. Changes will still be checked by the CI, but it's better to fix them before pushing. + ## Contributing If not part of the Arquimedia team, you can contribute by following the steps below. diff --git a/configs/.flake8 b/configs/.flake8 index 5f32207..41be26b 100644 --- a/configs/.flake8 +++ b/configs/.flake8 @@ -1,3 +1,13 @@ [flake8] max-line-length = 120 - +ignore = E203,E266,E501,W503,F403,F401 +exclude = + .git + .mypy_cache + .pytest_cache + .tox + build + dist + venv + .github + configs diff --git a/configs/pyproject.toml b/configs/pyproject.toml new file mode 100644 index 0000000..94b0b7f --- /dev/null +++ b/configs/pyproject.toml @@ -0,0 +1,16 @@ +[tool.black] +line-length = 120 +exclude = ''' + /( + \.git + | \.mypy_cache + | \.pytest_cache + | \.tox + | build + | dist + | venv + | .github + | configs + )/ +''' + diff --git a/requirements.txt b/requirements.txt index b4bae84..b63ce8e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ fastapi sqlmodel uvicorn pytest +pytest-cov \ No newline at end of file