From dde38e29938190e764ae0e3987e29ae4a27aa785 Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Wed, 11 Oct 2023 15:24:54 +0200 Subject: [PATCH] Add root prefix to cache key (#158) --- .github/workflows/test-cache.yml | 40 ++++++++++++++++++++++++++++++++ dist/index.js | 3 ++- src/cache.ts | 3 ++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-cache.yml b/.github/workflows/test-cache.yml index 741d401..70c810b 100644 --- a/.github/workflows/test-cache.yml +++ b/.github/workflows/test-cache.yml @@ -87,6 +87,46 @@ jobs: python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'env-name'" + test-env-changing-root-path1: + name: Test env cache with changing root path 1/2 + timeout-minutes: 10 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + environment-file: test/environment.yml + cache-environment-key: env-root-path-key-${{ github.sha }}-${{ github.run_attempt }} + micromamba-root-path: ~/micromamba + - name: test environment name + run: | + python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'env-name'" + + test-env-changing-root-path2: + name: Test env cache with changing root path 2/2 + timeout-minutes: 10 + needs: test-env-changing-root-path1 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + environment-file: test/environment.yml + cache-environment-key: env-root-path-key-${{ github.sha }}-${{ github.run_attempt }} + micromamba-root-path: ~/micromamba2 + - name: test environment name + run: | + python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'env-name'" + + test-env-then-download1: name: Test env then download 1/2 timeout-minutes: 10 diff --git a/dist/index.js b/dist/index.js index c0522d2..fd2000b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65435,7 +65435,8 @@ var generateEnvironmentKey = (prefix2) => { const arch3 = `-${getCondaArch()}`; const envName = options.environmentName ? `-${options.environmentName}` : ""; const createArgs = options.createArgs ? `-args-${sha256Short(JSON.stringify(options.createArgs))}` : ""; - const key = `${prefix2}${arch3}${envName}${createArgs}`; + const rootPrefix = `-root-${sha256Short(options.micromambaRootPath)}`; + const key = `${prefix2}${arch3}${envName}${createArgs}${rootPrefix}`; if (options.environmentFile) { return fs4.readFile(options.environmentFile, "utf-8").then((content) => { const keyWithFileSha = `${key}-file-${sha256(content)}`; diff --git a/src/cache.ts b/src/cache.ts index d59f4ec..fc0db99 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -39,7 +39,8 @@ const generateEnvironmentKey = (prefix: string) => { const arch = `-${getCondaArch()}` const envName = options.environmentName ? `-${options.environmentName}` : '' const createArgs = options.createArgs ? `-args-${sha256Short(JSON.stringify(options.createArgs))}` : '' - const key = `${prefix}${arch}${envName}${createArgs}` + const rootPrefix = `-root-${sha256Short(options.micromambaRootPath)}` + const key = `${prefix}${arch}${envName}${createArgs}${rootPrefix}` if (options.environmentFile) { return fs.readFile(options.environmentFile, 'utf-8').then((content) => { const keyWithFileSha = `${key}-file-${sha256(content)}`