Skip to content

Commit

Permalink
Don't post to the download cache when environment caching (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jobovy authored May 12, 2022
1 parent 18d8ee1 commit d7eeccc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/test_caching.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
uses: ./
with:
cache-downloads: true
cache-downloads-key: download-downloadkey-${{ github.sha }}-${{ github.run_attempt }}

- name: test environment name
run: |
Expand All @@ -45,6 +46,7 @@ jobs:
uses: ./
with:
cache-downloads: true
cache-downloads-key: download-downloadkey-${{ github.sha }}-${{ github.run_attempt }}

- name: test environment name
run: |
Expand All @@ -64,6 +66,7 @@ jobs:
uses: ./
with:
cache-env: true
cache-env-key: env-envkey-${{ github.sha }}-${{ github.run_attempt }}

- name: test environment name
run: |
Expand All @@ -84,6 +87,7 @@ jobs:
uses: ./
with:
cache-env: true
cache-env-key: env-envkey-${{ github.sha }}-${{ github.run_attempt }}

- name: test environment name
run: |
Expand All @@ -106,6 +110,52 @@ jobs:
with:
cache-env: true
cache-env-always-update: true
cache-env-key: env-envkey-${{ github.sha }}-${{ github.run_attempt }}

- name: test environment name
run: |
python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'testenv'"
test_download_and_env1:
name: Test download+env cache 1/2
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2

- name: install mamba
uses: ./
with:
cache-downloads: true
cache-env: true
cache-downloads-key: download-env-downloadkey-${{ github.sha }}-${{ github.run_attempt }}
cache-env-key: download-env-envkey-${{ github.sha }}-${{ github.run_attempt }}

- name: test environment name
run: |
python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'testenv'"
test_download_and_env2:
name: Test download+env cache 2/2
needs: [test_download_and_env1]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2

- name: install mamba
uses: ./
with:
cache-downloads: true
cache-env: true
cache-downloads-key: download-env-downloadkey-${{ github.sha }}-${{ github.run_attempt }}
cache-env-key: download-env-envkey-${{ github.sha }}-${{ github.run_attempt }}

- name: test environment name
run: |
Expand Down
5 changes: 3 additions & 2 deletions dist/main/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ channel_priority: strict
envCacheHit = await tryRestoreCache(...envCacheArgs)
}

if (!envCacheHit || inputs.cacheEnvAlwaysUpdate) {
const shouldTryDownloadCache = !envCacheHit || inputs.cacheEnvAlwaysUpdate
if (shouldTryDownloadCache) {
// Try to restore the download cache.
if (inputs.cacheDownloads) {
const key = inputs.cacheDownloadsKey || `${MAMBA_PLATFORM}-${process.arch} ${today()}`
Expand Down Expand Up @@ -335,7 +336,7 @@ Write-Host "Profile already exists and new content added"
core.info(`Contents of ${PATHS.bashprofile}:\n${fs.readFileSync(PATHS.bashprofile)}`)

// Save cache on workflow success
if (inputs.cacheDownloads && !downloadCacheHit) {
if (shouldTryDownloadCache && inputs.cacheDownloads && !downloadCacheHit) {
saveCacheOnPost(...downloadCacheArgs)
}
if (inputs.cacheEnv && !envCacheHit) {
Expand Down

0 comments on commit d7eeccc

Please sign in to comment.