From c1a8ba3cf11a7dca207e8e162ecff0b1a228cdba Mon Sep 17 00:00:00 2001 From: Javed Habib Date: Thu, 23 May 2024 15:33:13 +0530 Subject: [PATCH] cache --- .github/workflows/code_quality.yaml | 84 +++++++++++++++++++------- .github/workflows/code_test_unit.yaml | 24 ++++++-- .github/workflows/vulnerabilities.yaml | 48 ++++++++++++--- 3 files changed, 118 insertions(+), 38 deletions(-) diff --git a/.github/workflows/code_quality.yaml b/.github/workflows/code_quality.yaml index 8fe668a..341200e 100644 --- a/.github/workflows/code_quality.yaml +++ b/.github/workflows/code_quality.yaml @@ -22,28 +22,25 @@ jobs: python-version: '3.11' - name: Install Poetry - run: pip install poetry + run: pipx install poetry - - name: Generate hash of req dependencies - id: cq + - name: Generate hash of lint dependencies only run: | poetry export --only=lint --format=requirements.txt --output=requirements.txt echo "hash=$(sha256sum requirements.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV - name: Cache dependencies uses: actions/cache@v4 + id: cql with: path: | ~/.cache/pypoetry - ~/.cache/pip - key: ${{ runner.os }}-poetry-${{ env.hash }} + key: ${{ runner.os }}-lint-${{ env.hash }} restore-keys: | - ${{ runner.os }}-poetry- - - - name: Echo env - run: poetry env info + ${{ runner.os }}-lint- - name: Install lint dependencies + if: steps.cql.outputs.cache-hit == 'false' run: poetry install --only=lint --no-interaction --no-root - name: Check code quality @@ -56,17 +53,31 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry - - name: Set up Python uses: actions/setup-python@v5 - id: cq with: python-version: '3.11' - cache: 'poetry' + + - name: Install poetry + run: pipx install poetry + + - name: Generate hash of lint dependencies only + run: | + poetry export --only=lint --format=requirements.txt --output=requirements.txt + echo "hash=$(sha256sum requirements.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV + + - name: Cache dependencies + uses: actions/cache@v4 + id: cqf + with: + path: | + ~/.cache/pypoetry + key: ${{ runner.os }}-lint-${{ env.hash }} + restore-keys: | + ${{ runner.os }}-lint- - name: Install lint dependencies + if: steps.cqf.outputs.cache-hit == 'false' run: poetry install --only=lint --no-interaction --no-root - name: Check code style @@ -79,15 +90,28 @@ jobs: - name: Check out repository uses: actions/checkout@v4 + - name: Set up python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install poetry run: pipx install poetry - - name: Set up python + - name: Generate hash of types dependencies only + run: | + poetry export --only=types --format=requirements.txt --output=requirements.txt + echo "hash=$(sha256sum requirements.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV + + - name: Cache dependencies + uses: actions/cache@v4 id: cqtc - uses: actions/setup-python@v5 with: - python-version: '3.11' - cache: 'poetry' + path: | + ~/.cache/pypoetry + key: ${{ runner.os }}-types-${{ env.hash }} + restore-keys: | + ${{ runner.os }}-types- - name: Install types and mypy dependencies run: poetry install --only=types --no-interaction --no-root @@ -102,17 +126,31 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry - - name: Set up Python uses: actions/setup-python@v5 - id: cq with: python-version: '3.11' - cache: 'poetry' + + - name: Install poetry + run: pipx install poetry + + - name: Generate hash of lint dependencies only + run: | + poetry export --only=lint --format=requirements.txt --output=requirements.txt + echo "hash=$(sha256sum requirements.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV + + - name: Cache dependencies + uses: actions/cache@v4 + id: cqsc + with: + path: | + ~/.cache/pypoetry + key: ${{ runner.os }}-lint-${{ env.hash }} + restore-keys: | + ${{ runner.os }}-lint- - name: Install lint dependencies + if: steps.cqsc.outputs.cache-hit == 'false' run: poetry install --only=lint --no-interaction --no-root - name: Check spellings diff --git a/.github/workflows/code_test_unit.yaml b/.github/workflows/code_test_unit.yaml index 119b452..b83d928 100644 --- a/.github/workflows/code_test_unit.yaml +++ b/.github/workflows/code_test_unit.yaml @@ -16,17 +16,31 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry - - name: Set up Python uses: actions/setup-python@v5 - id: ct with: python-version: '3.11' - cache: 'poetry' + + - name: Install poetry + run: pipx install poetry + + - name: Generate hash of tesk with test dependencies only + run: | + poetry export --with=lint --format=requirements.txt --output=requirements.txt + echo "hash=$(sha256sum requirements.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV + + - name: Cache dependencies + uses: actions/cache@v4 + id: ctuut + with: + path: | + ~/.cache/pypoetry + key: ${{ runner.os }}-test-${{ env.hash }} + restore-keys: | + ${{ runner.os }}-test- - name: Install test dependencies + if: steps.ctuut.outputs.cache-hit == 'false' run: poetry install --only=test --no-interaction - name: Run tests and generate coverage as test_unit.xml diff --git a/.github/workflows/vulnerabilities.yaml b/.github/workflows/vulnerabilities.yaml index 9126347..4841732 100644 --- a/.github/workflows/vulnerabilities.yaml +++ b/.github/workflows/vulnerabilities.yaml @@ -16,17 +16,31 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry - - name: Set up python - id: vt uses: actions/setup-python@v5 with: python-version: '3.11' - cache: 'poetry' + + - name: Install poetry + run: pipx install poetry + + - name: Generate hash of security dependencies only + run: | + poetry export --only=security --format=requirements.txt --output=requirements.txt + echo "hash=$(sha256sum requirements.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV + + - name: Cache dependencies + uses: actions/cache@v4 + id: vcv + with: + path: | + ~/.cache/pypoetry + key: ${{ runner.os }}-security-${{ env.hash }} + restore-keys: | + ${{ runner.os }}-security- - name: Install vulnerabilities check dependencies + if: steps.vcv.outputs.cache-hit == 'false' run: poetry install --only=security --no-interaction --no-root - name: Check code vulnerabilities with bandit @@ -39,17 +53,31 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry - - name: Set up python - id: vt uses: actions/setup-python@v5 with: python-version: '3.11' - cache: 'poetry' + + - name: Install poetry + run: pipx install poetry + + - name: Generate hash of security dependencies only + run: | + poetry export --only=security --format=requirements.txt --output=requirements.txt + echo "hash=$(sha256sum requirements.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV + + - name: Cache dependencies + uses: actions/cache@v4 + id: vdv + with: + path: | + ~/.cache/pypoetry + key: ${{ runner.os }}-security-${{ env.hash }} + restore-keys: | + ${{ runner.os }}-security- - name: Install vulnerabilities check dependencies + if: steps.vdv.outputs.cache-hit == 'false' run: poetry install --only=security --no-interaction --no-root - name: Check dependency vulnerabilities with safety