From a5727c155b49456fd03bceef23b3d5fe401df8a3 Mon Sep 17 00:00:00 2001 From: ilai Date: Tue, 24 Oct 2023 12:42:53 +0300 Subject: [PATCH 1/7] [CI] Added caching of dependencies If the dependencies haven't changed - used a cached version, which would save a lot of the CI's time --- .github/workflows/CI.yml | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index cc99659f..4a3935d5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -28,8 +28,23 @@ jobs: uses: snok/install-poetry@v1 with: version: 1.3.2 - - name: install dependencies - run: poetry install --with dev + #---------------------------------------------- + # load cached venv if cache exists + #---------------------------------------------- + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + #---------------------------------------------- + # install dependencies if cache does not exist + #---------------------------------------------- + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root --with dev + - name: Install project + run: poetry install --no-interaction - name: Run flake8 Check run: poetry run flake8 . - name: Run mypy check @@ -55,8 +70,23 @@ jobs: uses: snok/install-poetry@v1 with: version: 1.3.2 - - name: install dependencies - run: poetry install --with dev --all-extras + #---------------------------------------------- + # load cached venv if cache exists + #---------------------------------------------- + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + #---------------------------------------------- + # install dependencies if cache does not exist + #---------------------------------------------- + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root --with dev + - name: Install project + run: poetry install --no-interaction - name: Run unit tests run: poetry run pytest --html=report.html --self-contained-html tests/unit - name: Set Index Name for System / E2E From 50c0dc619047af791c301d17e8aa564d3a3b28ce Mon Sep 17 00:00:00 2001 From: ilai Date: Tue, 24 Oct 2023 14:43:51 +0300 Subject: [PATCH 2/7] [CI] Bug fix - wrong name for cache key --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4a3935d5..b874e942 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -36,7 +36,7 @@ jobs: uses: actions/cache@v3 with: path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} #---------------------------------------------- # install dependencies if cache does not exist #---------------------------------------------- @@ -78,7 +78,7 @@ jobs: uses: actions/cache@v3 with: path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} #---------------------------------------------- # install dependencies if cache does not exist #---------------------------------------------- From c0b7ec2a7828e7ff4aeb10538e0f6e0c933146cd Mon Sep 17 00:00:00 2001 From: ilai Date: Tue, 24 Oct 2023 15:08:33 +0300 Subject: [PATCH 3/7] [CI] Change the cache key Since we don't push the lock file, that doesn't seem to be working --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b874e942..82af3514 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -36,7 +36,7 @@ jobs: uses: actions/cache@v3 with: path: .venv - key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} #---------------------------------------------- # install dependencies if cache does not exist #---------------------------------------------- @@ -78,7 +78,7 @@ jobs: uses: actions/cache@v3 with: path: .venv - key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} #---------------------------------------------- # install dependencies if cache does not exist #---------------------------------------------- From c1fa6e1670ba288cf7a2f9a1f1da15a04f318655 Mon Sep 17 00:00:00 2001 From: ilai Date: Tue, 24 Oct 2023 16:00:09 +0300 Subject: [PATCH 4/7] TEMP! disable tests to check if cache is working --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 82af3514..47aceecd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -52,6 +52,7 @@ jobs: run-tests: name: Run tests + if: false runs-on: ubuntu-latest needs: run-linters strategy: From 9a538bcae11259ebb4a2509dcac4886fe7ef779b Mon Sep 17 00:00:00 2001 From: ilai Date: Tue, 24 Oct 2023 16:18:00 +0300 Subject: [PATCH 5/7] [CI] Make poetry install venv locally This way the cache can work --- .github/workflows/CI.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 47aceecd..86504f9f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -28,6 +28,9 @@ jobs: uses: snok/install-poetry@v1 with: version: 1.3.2 + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true #---------------------------------------------- # load cached venv if cache exists #---------------------------------------------- @@ -52,7 +55,6 @@ jobs: run-tests: name: Run tests - if: false runs-on: ubuntu-latest needs: run-linters strategy: From 722e26e4839ad6d56dd9f3305b9f727324fec330 Mon Sep 17 00:00:00 2001 From: ilai Date: Tue, 24 Oct 2023 16:29:09 +0300 Subject: [PATCH 6/7] [CI] Only run mypy on src --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 86504f9f..7c54c9c3 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -51,7 +51,7 @@ jobs: - name: Run flake8 Check run: poetry run flake8 . - name: Run mypy check - run: poetry run mypy . + run: poetry run mypy src run-tests: name: Run tests From b241d2310a0288a462ea1b2c6a92a7222696726a Mon Sep 17 00:00:00 2001 From: ilai Date: Tue, 24 Oct 2023 17:52:07 +0300 Subject: [PATCH 7/7] [CI] Don't run flake8 on .venv To allow local installation in CI --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 17e812c5..8a767ceb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ build-backend = "poetry.core.masonry.api" [tool.mypy] allow_redefinition = true -exclude = ['tests'] +exclude = ['tests', '.venv'] [[tool.mypy.overrides]] module = [ @@ -61,6 +61,7 @@ ignore_missing_imports = true per-file-ignores = [ '*/__init__.py:F401', ] +exclude = ['.venv'] max-line-length = 88 [tool.poetry.scripts]