From 2a3da9b90a62fdef65a9f4b1d6c0e9ddcd219aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Fri, 24 Mar 2023 23:22:34 +0000 Subject: [PATCH 01/18] ci: add linter job --- .github/workflows/linter.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/linter.yaml diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml new file mode 100644 index 0000000..e5fe230 --- /dev/null +++ b/.github/workflows/linter.yaml @@ -0,0 +1,21 @@ +name: linter +on: [push] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + steps: + - uses: actions/checkout@v3 + - 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 pylint + - name: Analysing the code with pylint + run: | + pylint $(git ls-files '*.py') \ No newline at end of file From 870cd6ac642463f6c4e232762f19b35a2faf0dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Fri, 24 Mar 2023 23:25:32 +0000 Subject: [PATCH 02/18] ci: change linter to flake8 --- .github/workflows/linter.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index e5fe230..6ece5a6 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -15,7 +15,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pylint - - name: Analysing the code with pylint + pip install flake8 + pip install -r requirements.txt + - name: Analysing the code with flake8 run: | - pylint $(git ls-files '*.py') \ No newline at end of file + flake8 $(git ls-files '*.py') --rcfile=./configs/.flake8 \ No newline at end of file From dfc90ad1a32e77e3298a0d2472236ab7df7deb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Fri, 24 Mar 2023 23:29:24 +0000 Subject: [PATCH 03/18] ci: change flake8 config file --- .github/workflows/linter.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index 6ece5a6..7e4ef12 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -19,4 +19,4 @@ jobs: pip install -r requirements.txt - name: Analysing the code with flake8 run: | - flake8 $(git ls-files '*.py') --rcfile=./configs/.flake8 \ No newline at end of file + flake8 $(git ls-files '*.py') --config=./configs/.flake8 \ No newline at end of file From c883659b8a2ebece6864c2de416fb52a0ea4d9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Fri, 24 Mar 2023 23:54:24 +0000 Subject: [PATCH 04/18] ci: add test job with CodeCov --- .github/workflows/CI.yaml | 49 +++++++++++++++++++++++++++++++++++ .github/workflows/linter.yaml | 22 ---------------- 2 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/CI.yaml delete mode 100644 .github/workflows/linter.yaml diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml new file mode 100644 index 0000000..476fb9a --- /dev/null +++ b/.github/workflows/CI.yaml @@ -0,0 +1,49 @@ +name: CI +on: [push] +jobs: + lint: + 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 flake8 + pip install -r requirements.txt + - name: Analysing the code with flake8 + run: | + flake8 $(git ls-files '*.py') --config=./configs/.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 \ No newline at end of file diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml deleted file mode 100644 index 7e4ef12..0000000 --- a/.github/workflows/linter.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: linter -on: [push] -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10"] - steps: - - uses: actions/checkout@v3 - - 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 flake8 - pip install -r requirements.txt - - name: Analysing the code with flake8 - run: | - flake8 $(git ls-files '*.py') --config=./configs/.flake8 \ No newline at end of file From 71d4fda7a0b309d4b8b27fae535286f9e7a7cf30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Fri, 24 Mar 2023 23:56:25 +0000 Subject: [PATCH 05/18] ci: add pytest-cov dependency --- .github/workflows/CI.yaml | 3 ++- requirements.txt | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 476fb9a..2d01014 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -40,7 +40,8 @@ jobs: 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 + pytest --cov=./arquimedia --cov-report xml:coverage.xml --cov-report term-missing tests/ + - name: Upload coverage to Codecov uses: codecov/codecov-action@v2 with: 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 From 1b175dd05592a0264efd13c85faf198633aceb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 00:42:53 +0000 Subject: [PATCH 06/18] ci: add black formatter and fix any errors --- .github/workflows/CI.yaml | 39 ++++++++++++++++++++++----------------- configs/.flake8 | 3 --- 2 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 configs/.flake8 diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 2d01014..03ada40 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -2,26 +2,31 @@ name: CI on: [push] jobs: lint: + name: Run linters 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 flake8 - pip install -r requirements.txt - - name: Analysing the code with flake8 - run: | - flake8 $(git ls-files '*.py') --config=./configs/.flake8 + - 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: + black: true + black_args: --config=./configs/pyproject.toml + + flake8: true + flake8_args: --config=./configs/pyproject.toml + commit_message: "style: format code with black and flake8" test: runs-on: ubuntu-latest strategy: diff --git a/configs/.flake8 b/configs/.flake8 deleted file mode 100644 index 5f32207..0000000 --- a/configs/.flake8 +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -max-line-length = 120 - From 6a1999288230653de257f41d532cdfb04f1fb143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 00:50:25 +0000 Subject: [PATCH 07/18] ci: add pyproject.toml --- .github/workflows/CI.yaml | 6 +++--- configs/pyproject.toml | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 configs/pyproject.toml diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 03ada40..09b9ab5 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -2,7 +2,6 @@ name: CI on: [push] jobs: lint: - name: Run linters runs-on: ubuntu-latest steps: @@ -21,12 +20,13 @@ jobs: uses: wearerequired/lint-action@v2 with: black: true - black_args: --config=./configs/pyproject.toml + black_args: --config=${{ github.workspace }}/configs/pyproject.toml flake8: true - flake8_args: --config=./configs/pyproject.toml + flake8_args: --config=${{ github.workspace }}/configs/pyproject.toml commit_message: "style: format code with black and flake8" + test: runs-on: ubuntu-latest strategy: diff --git a/configs/pyproject.toml b/configs/pyproject.toml new file mode 100644 index 0000000..d9fb228 --- /dev/null +++ b/configs/pyproject.toml @@ -0,0 +1,8 @@ +[tool.black] +line-length = 120 +exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv,env + +[flake8] +max-line-length = 120 +ignore = E203, E266, E501, W503, F403, F401 +exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv,env \ No newline at end of file From 04f03e3170d90f0584db3a6fd44d14e22565b931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:01:41 +0000 Subject: [PATCH 08/18] ci: fix pyproject.toml file --- .github/workflows/CI.yaml | 4 ++-- configs/pyproject.toml | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 09b9ab5..5e56a79 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -20,10 +20,10 @@ jobs: uses: wearerequired/lint-action@v2 with: black: true - black_args: --config=${{ github.workspace }}/configs/pyproject.toml + black_args: --config=./configs/pyproject.toml flake8: true - flake8_args: --config=${{ github.workspace }}/configs/pyproject.toml + flake8_args: --config=./configs/pyproject.toml commit_message: "style: format code with black and flake8" diff --git a/configs/pyproject.toml b/configs/pyproject.toml index d9fb228..8381ead 100644 --- a/configs/pyproject.toml +++ b/configs/pyproject.toml @@ -1,8 +1,30 @@ [tool.black] line-length = 120 -exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv,env +exclude = ''' + /( + \.git + | \.mypy_cache + | \.pytest_cache + | \.tox + | build + | dist + | venv + | .github + )/ +''' [flake8] max-line-length = 120 -ignore = E203, E266, E501, W503, F403, F401 -exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv,env \ No newline at end of file +ignore = ["E203", "E266", "E501", "W503", "F403", "F401"] +exclude = ''' + /( + \.git + | \.mypy_cache + | \.pytest_cache + | \.tox + | build + | dist + | venv + | .github + )/ +''' From 331f96ddc8493b2e70b0a67f0d95330117edeaf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:05:51 +0000 Subject: [PATCH 09/18] ci: fix pyproject.toml file --- configs/pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs/pyproject.toml b/configs/pyproject.toml index 8381ead..c2afd1b 100644 --- a/configs/pyproject.toml +++ b/configs/pyproject.toml @@ -10,6 +10,7 @@ exclude = ''' | dist | venv | .github + | configs )/ ''' @@ -26,5 +27,6 @@ exclude = ''' | dist | venv | .github + | configs )/ ''' From e1b8cce654ccbf52fe0b825805bed6c78320b1c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:13:36 +0000 Subject: [PATCH 10/18] ci: separate config files --- .github/workflows/CI.yaml | 2 +- configs/.flake8 | 13 +++++++++++++ configs/pyproject.toml | 16 ---------------- 3 files changed, 14 insertions(+), 17 deletions(-) create mode 100644 configs/.flake8 diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 5e56a79..be1bc25 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -23,7 +23,7 @@ jobs: black_args: --config=./configs/pyproject.toml flake8: true - flake8_args: --config=./configs/pyproject.toml + flake8_args: --config=./configs/.flake8 commit_message: "style: format code with black and flake8" diff --git a/configs/.flake8 b/configs/.flake8 new file mode 100644 index 0000000..a994ced --- /dev/null +++ b/configs/.flake8 @@ -0,0 +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 index c2afd1b..94b0b7f 100644 --- a/configs/pyproject.toml +++ b/configs/pyproject.toml @@ -14,19 +14,3 @@ exclude = ''' )/ ''' -[flake8] -max-line-length = 120 -ignore = ["E203", "E266", "E501", "W503", "F403", "F401"] -exclude = ''' - /( - \.git - | \.mypy_cache - | \.pytest_cache - | \.tox - | build - | dist - | venv - | .github - | configs - )/ -''' From df52f9eeb4d9b973f66be5533817adffbb80dbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:16:19 +0000 Subject: [PATCH 11/18] ci: fix flake8 config file --- configs/.flake8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/.flake8 b/configs/.flake8 index a994ced..41be26b 100644 --- a/configs/.flake8 +++ b/configs/.flake8 @@ -1,6 +1,6 @@ [flake8] max-line-length = 120 -ignore = ["E203", "E266", "E501", "W503", "F403", "F401"] +ignore = E203,E266,E501,W503,F403,F401 exclude = .git .mypy_cache From f58dfc4f216f5a8abefc68561872e04c49854bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:17:56 +0000 Subject: [PATCH 12/18] ci: trigger black auto fix --- arquimedia/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arquimedia/main.py b/arquimedia/main.py index 2eb1cc5..0bee4f9 100644 --- a/arquimedia/main.py +++ b/arquimedia/main.py @@ -2,6 +2,7 @@ app = FastAPI() +a=1 @app.get("/") def tmp_root(): From 2c4b84e8dd4ff98ff6a1e0a7bbb1487bbf7c0215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:22:38 +0000 Subject: [PATCH 13/18] ci: make lint-action trigger auto-fix --- .github/workflows/CI.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index be1bc25..80956d6 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -19,12 +19,13 @@ jobs: - 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: From c4b5920d6d16c235d512edb3dc7c931872ea1ea3 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Sat, 25 Mar 2023 01:22:55 +0000 Subject: [PATCH 14/18] style: format code with black and flake8 --- arquimedia/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arquimedia/main.py b/arquimedia/main.py index 0bee4f9..b23e028 100644 --- a/arquimedia/main.py +++ b/arquimedia/main.py @@ -2,7 +2,8 @@ app = FastAPI() -a=1 +a = 1 + @app.get("/") def tmp_root(): From 33d569965d1f6def96b8a418052b6ffd3858e9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:24:36 +0000 Subject: [PATCH 15/18] ci: rollback trigger line and add pull requests to action --- .github/workflows/CI.yaml | 2 +- arquimedia/main.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 80956d6..5895bd8 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -1,5 +1,5 @@ name: CI -on: [push] +on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest diff --git a/arquimedia/main.py b/arquimedia/main.py index b23e028..2eb1cc5 100644 --- a/arquimedia/main.py +++ b/arquimedia/main.py @@ -2,8 +2,6 @@ app = FastAPI() -a = 1 - @app.get("/") def tmp_root(): From c7607331757fcead3e5428e922a97a8ef097788f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:30:01 +0000 Subject: [PATCH 16/18] ci: check for conventional commits --- .github/workflows/CI.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 5895bd8..6574246 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -53,4 +53,10 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml - fail_ci_if_error: true \ No newline at end of file + 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 From 14bf983a8def2dfd438262ac3c13360a86657f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:50:21 +0000 Subject: [PATCH 17/18] ci: add pre-commit configuration file --- .pre-commit-config.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .pre-commit-config.yaml 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 From 9a7c5d575bcbbcb1722a84d14f1567d10623c05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= Date: Sat, 25 Mar 2023 01:55:27 +0000 Subject: [PATCH 18/18] docs: update README with pre-commit info --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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.