Просмотр исходного кода

build(ci): Fix python/pip cache (#24327)

We were using the same cache key for a bunch of our backend tests. However, the dependencies for backend lint are different than the rest as it only needs to install from `requirements-precommit.txt` and does not require setting up the sentry env. Because `backend lint` workflow also generally finishes first, we were saving its pip environment to the cache. This caused our other workflows to not have their pip environments cached.

Changes:
* Use the same cache key for all workflows that use the `setup-sentry` action
* `backend lint` and `development environment` workflows both have their own cache keys
* Use a "secret" as part of the cache key so that we can invalidate the cache via Secrets management
Billy Vong 4 лет назад
Родитель
Сommit
4dcc94b8f9

+ 3 - 2
.github/workflows/acceptance.yml

@@ -111,9 +111,10 @@ jobs:
         uses: actions/cache@v2
         uses: actions/cache@v2
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('**/requirements-*.txt') }}
+          key: |
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}-${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}
 
 
       - name: Setup sentry python env
       - name: Setup sentry python env
         uses: ./.github/actions/setup-sentry
         uses: ./.github/actions/setup-sentry

+ 3 - 2
.github/workflows/api-docs-test.yml

@@ -48,9 +48,10 @@ jobs:
         if: steps.changes.outputs.api_docs == 'true'
         if: steps.changes.outputs.api_docs == 'true'
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('**/requirements-*.txt') }}
+          key: |
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}-${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}
 
 
       - name: Setup sentry python env
       - name: Setup sentry python env
         uses: ./.github/actions/setup-sentry
         uses: ./.github/actions/setup-sentry

+ 4 - 2
.github/workflows/backend-lint.yml

@@ -62,9 +62,11 @@ jobs:
         if: steps.changes.outputs.backend == 'true'
         if: steps.changes.outputs.backend == 'true'
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('**/requirements-*.txt') }}
+          # Note this uses a different cache key than other backend-based workflows because this workflows dependencies are different
+          key: |
+            precommit-${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
+            precommit-${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
 
 
       - name: Setup pre-commit
       - name: Setup pre-commit
         if: steps.changes.outputs.backend == 'true'
         if: steps.changes.outputs.backend == 'true'

+ 3 - 2
.github/workflows/backend-test.yml

@@ -63,9 +63,10 @@ jobs:
         if: steps.changes.outputs.backend == 'true'
         if: steps.changes.outputs.backend == 'true'
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('**/requirements-*.txt') }}
+          key: |
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}-${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}
 
 
       - name: Setup sentry env
       - name: Setup sentry env
         uses: ./.github/actions/setup-sentry
         uses: ./.github/actions/setup-sentry

+ 2 - 2
.github/workflows/check-if-migration-is-required.yml

@@ -32,9 +32,9 @@ jobs:
         uses: actions/cache@v2
         uses: actions/cache@v2
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
+          key: ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}-${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-pip-
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}
 
 
       - name: Setup sentry env
       - name: Setup sentry env
         uses: ./.github/actions/setup-sentry
         uses: ./.github/actions/setup-sentry

+ 3 - 2
.github/workflows/command-line-test.yml

@@ -42,9 +42,10 @@ jobs:
         if: steps.changes.outputs.backend == 'true'
         if: steps.changes.outputs.backend == 'true'
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
+          key: |
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}-${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-pip-
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}
 
 
       - name: Setup sentry env
       - name: Setup sentry env
         uses: ./.github/actions/setup-sentry
         uses: ./.github/actions/setup-sentry

+ 3 - 2
.github/workflows/development-environment.yml

@@ -64,9 +64,10 @@ jobs:
           path: |
           path: |
             ${{ steps.pip.outputs.pip-cache-dir }}
             ${{ steps.pip.outputs.pip-cache-dir }}
             ~/.pyenv
             ~/.pyenv
-          key: ${{ matrix.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('**/requirements-*.txt') }}
+          key: |
+            devenv-${{ matrix.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('requirements-*.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ matrix.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
+            devenv-${{ matrix.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
 
 
       - name: Get yarn cache directory path
       - name: Get yarn cache directory path
         id: yarn-cache-dir-path
         id: yarn-cache-dir-path

+ 3 - 2
.github/workflows/migrations.yml

@@ -66,9 +66,10 @@ jobs:
         uses: actions/cache@v2
         uses: actions/cache@v2
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
+          key: |
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}-${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-pip-
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}
 
 
       - name: Setup sentry env
       - name: Setup sentry env
         uses: ./.github/actions/setup-sentry
         uses: ./.github/actions/setup-sentry

+ 3 - 2
.github/workflows/plugins-test.yml

@@ -42,9 +42,10 @@ jobs:
         if: steps.changes.outputs.plugins == 'true'
         if: steps.changes.outputs.plugins == 'true'
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
+          key: |
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}-${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-pip-
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}
 
 
       - name: Setup sentry env
       - name: Setup sentry env
         uses: ./.github/actions/setup-sentry
         uses: ./.github/actions/setup-sentry

+ 3 - 2
.github/workflows/relay-integration-test.yml

@@ -47,9 +47,10 @@ jobs:
         if: steps.changes.outputs.backend == 'true'
         if: steps.changes.outputs.backend == 'true'
         with:
         with:
           path: ${{ steps.pip.outputs.pip-cache-dir }}
           path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
+          key: |
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}-${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
           restore-keys: |
           restore-keys: |
-            ${{ runner.os }}-pip-
+            ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ secrets.PIP_CACHE_VERSION }}
 
 
       - name: Setup sentry env
       - name: Setup sentry env
         uses: ./.github/actions/setup-sentry
         uses: ./.github/actions/setup-sentry

Некоторые файлы не были показаны из-за большого количества измененных файлов