From 0c75b1b3f38e0777badc4865cb1b2334217773fb Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Mon, 9 Sep 2024 18:03:17 +0100 Subject: [PATCH] Enable caches on CI (#556) --- .github/workflows/build.yml | 19 ++++++++++-- .github/workflows/linting-and-testing.yaml | 36 ++++++++++++++++++++-- .github/workflows/publish.yml | 22 +++++++++++-- .pre-commit-config.yaml | 1 - pyproject.toml | 10 +++--- 5 files changed, 73 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index db0c9d0..a58abe5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,11 +28,24 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install Poetry - uses: abatilo/actions-poetry@v3.0.0 + uses: abatilo/actions-poetry@v3 + + - name: Use local virtual environment + run: | + poetry config virtualenvs.create true --local + poetry config virtualenvs.in-project true --local + + - uses: actions/cache@v4 + id: cache-poetry-deps + name: Cache Poetry dependencies with: - poetry-version: 1.3.2 + path: ./.venv + key: venv-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }} + restore-keys: | + venv-${{ matrix.os }}-${{ matrix.python-version }}- - - name: Install dependencies + - name: Install dependencies with Poetry + if: steps.cache-poetry-deps.outputs.cache-hit != 'true' run: poetry install - name: Test package building diff --git a/.github/workflows/linting-and-testing.yaml b/.github/workflows/linting-and-testing.yaml index ac67b69..abbdb3f 100644 --- a/.github/workflows/linting-and-testing.yaml +++ b/.github/workflows/linting-and-testing.yaml @@ -6,6 +6,9 @@ on: - master pull_request: +env: + RUNS_ON: ubuntu-latest + jobs: pre-commit: name: Pre-commit @@ -23,11 +26,38 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install Poetry - uses: abatilo/actions-poetry@v3.0.0 + uses: abatilo/actions-poetry@v3 + + - name: Use local virtual environment + run: | + poetry config virtualenvs.create true --local + poetry config virtualenvs.in-project true --local + + - uses: actions/cache@v4 + id: cache-poetry-deps + name: Cache Poetry dependencies + with: + path: ./.venv + key: venv-${{ env.RUNS_ON }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }} + restore-keys: | + venv-${{ env.RUNS_ON }}-${{ matrix.python-version }}- + + - uses: actions/cache@v4 + name: Cache pre-commit hooks with: - poetry-version: 1.3.2 + path: ~/.cache/pre-commit/ + key: > + ${{ format('pre-commit-{0}-{1}-{2}', + env.RUNS_ON, + matrix.python-version, + hashFiles('.pre-commit-config.yaml') + ) }} + restore-keys: | + pre-commit-${{ env.RUNS_ON }}-${{ matrix.python-version }}- + pre-commit-${{ env.RUNS_ON }}- - - name: Install dependencies + - name: Install dependencies with Poetry + if: steps.cache-poetry-deps.outputs.cache-hit != 'true' run: poetry install - name: Run pre-commit on all files diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 38c1284..4d8ef02 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,9 @@ on: release: types: [published] +env: + RUNS_ON: ubuntu-latest + jobs: publish: name: Publish @@ -21,11 +24,24 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install Poetry - uses: abatilo/actions-poetry@v3.0.0 + uses: abatilo/actions-poetry@v3 + + - name: Use local virtual environment + run: | + poetry config virtualenvs.create true --local + poetry config virtualenvs.in-project true --local + + - uses: actions/cache@v4 + id: cache-poetry-deps + name: Cache Poetry dependencies with: - poetry-version: 1.3.2 + path: ./.venv + key: venv-${{ env.RUNS_ON }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }} + restore-keys: | + venv-${{ env.RUNS_ON }}-${{ matrix.python-version }}- - - name: Install dependencies + - name: Install dependencies with Poetry + if: steps.cache-poetry-deps.outputs.cache-hit != 'true' run: poetry install - name: Set version diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d336c81..b08a1c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,7 +34,6 @@ repos: - id: pylint name: pylint entry: poetry run pylint - exclude: ^glocaltokens/google/ language: system types: [python] - id: pytest diff --git a/pyproject.toml b/pyproject.toml index 6040327..dba7404 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,10 @@ types-protobuf = "^4.24.0.4" "Bug Tracker" = "https://github.com/leikoilja/glocaltokens/issues" "Release Notes" = "https://github.com/leikoilja/glocaltokens/releases" +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + [tool.pylint.master] extension-pkg-whitelist = [ "_socket", @@ -98,8 +102,4 @@ warn_unreachable = true [tool.codespell] ignore-words-list = "aas" quiet-level = 2 -skip = "poetry.lock,./.git/*,./.mypy_cache/*,*.egg-info" - -[build-system] -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" +skip = "poetry.lock,./.git/*,./.mypy_cache/*,./.venv/*,*.egg-info"