From 0d68c5dc39cb026328b2fe8cccce089e543af011 Mon Sep 17 00:00:00 2001 From: Alessio Pagliarulo Date: Thu, 29 Oct 2026 14:54:18 -0400 Subject: [PATCH] ci: make backend env cache deterministic Two caches (mamba env and poetry venv) restored into the same env folder, and the venv cache used restore-keys. On nextjs this mixed conda's charset-normalizer 3.5.2 with poetry's 3.1.0, so the same commit passed on the PR and failed on push (charset_normalizer.md has no CharInfo). Use one cache keyed on environment.yml and poetry.lock with no partial matches, and always run poetry install. --- .github/workflows/backend.yml | 68 ++++++++--------------------------- 1 file changed, 15 insertions(+), 53 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index e25365e7..5c40f5d3 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -25,39 +25,20 @@ jobs: use-mamba: true activate-environment: dlp - - name: Cache Mamba env - id: cached-mamba-env - uses: actions/cache@v3 - env: - # Increase this value to reset cache if etc/example-environment.yml has not changed - CACHE_NUMBER: 0 - with: - path: /usr/share/miniconda3/envs/ - key: mamba-${{ runner.os }}-${{env.CACHE_NUMBER }}-${{hashFiles('**/training/environment.yml') }} - - - name: Update environment - run: mamba env update -n dlp -f - training/environment.yml - if: steps.cached-mamba-env.outputs.cache-hit != 'true' - - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - name: Load cached venv - id: cached-poetry-dependencies + # One cache, keyed on both dependency files, no restore-keys: a hit is exactly the env these files built. + - name: Cache dlp env + id: cached-env uses: actions/cache@v3 with: path: /usr/share/miniconda3/envs/dlp - key: training-venv-${{ runner.os }}-${{ hashFiles('**/training/poetry.lock') }} - restore-keys: training-venv-${{ runner.os }}- + key: dlp-env-${{ runner.os }}-1-${{ hashFiles('training/environment.yml', 'training/poetry.lock') }} - #--------------------------------------------------- - # install dependencies if cache does not exist - #--------------------------------------------------- + - name: Update environment + if: steps.cached-env.outputs.cache-hit != 'true' + run: mamba env update -n dlp -f training/environment.yml - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: pwd && cd training && poetry install --no-interaction --no-root && poetry env info -p + run: cd training && poetry install --no-interaction --no-root shell: bash -el {0} - name: Add Poetry env to PATH @@ -106,38 +87,19 @@ jobs: use-mamba: true activate-environment: dlp - - name: Cache Mamba env - id: cached-mamba-env + # One cache, keyed on both dependency files, no restore-keys: a hit is exactly the env these files built. + - name: Cache dlp env + id: cached-env uses: actions/cache@v3 - env: - # Increase this value to reset cache if etc/example-environment.yml has not changed - CACHE_NUMBER: 0 with: - path: /usr/share/miniconda3/envs/ - key: mamba-${{ runner.os }}-${{env.CACHE_NUMBER }}-${{hashFiles('**/training/environment.yml') }} + path: /usr/share/miniconda3/envs/dlp + key: dlp-env-${{ runner.os }}-1-${{ hashFiles('training/environment.yml', 'training/poetry.lock') }} - name: Update environment - run: mamba env update -n dlp -f - training/environment.yml - if: steps.cached-mamba-env.outputs.cache-hit != 'true' + if: steps.cached-env.outputs.cache-hit != 'true' + run: mamba env update -n dlp -f training/environment.yml - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v3 - with: - path: /usr/share/miniconda3/envs/dlp - key: training-venv-${{ runner.os }}-${{ hashFiles('**/training/poetry.lock') }} - restore-keys: training-venv-${{ runner.os }}- - - #---------------------------------------------- - # install dependencies if cache does not exist - #---------------------------------------------- - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' run: cd training && poetry install --no-interaction --no-root shell: bash -el {0}