From 5d5dbebd87f7b9358c403c7a66651fa92b310105 Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Sat, 13 May 2023 15:44:09 +0200 Subject: [PATCH] Fix caching bug (1.4.1) (#69) --- .github/workflows/label.yml | 3 +-- .github/workflows/test-cache.yml | 46 ++++++++++++++++++++++++++++++-- dist/post.js | 5 ++++ package.json | 2 +- src/cache.ts | 5 ++++ 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index daf04d8..fea6860 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -14,7 +14,6 @@ jobs: repo-token: "${{ secrets.GITHUB_TOKEN }}" - uses: mheap/github-action-required-labels@v4 with: - labels: | - "bug, enhancement, ci, documentation, dependencies, ignore-for-release" + labels: bug,enhancement,ci,documentation,dependencies,ignore-for-release mode: minimum count: 1 diff --git a/.github/workflows/test-cache.yml b/.github/workflows/test-cache.yml index 07dc175..353510b 100644 --- a/.github/workflows/test-cache.yml +++ b/.github/workflows/test-cache.yml @@ -32,7 +32,7 @@ jobs: test-download2: name: Test download cache 2/2 timeout-minutes: 10 - needs: [test-download1] + needs: test-download1 runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -69,7 +69,7 @@ jobs: test-env2: name: Test env cache 2/2 timeout-minutes: 10 - needs: [test-env1] + needs: test-env1 runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -85,3 +85,45 @@ jobs: 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 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v3 + - uses: ./ + with: + environment-file: test/environment.yml + cache-environment-key: env-then-download-env-${{ github.sha }}-${{ github.run_attempt }} + - name: test environment name + run: | + python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'env-name'" + + test-env-then-download2: + name: Test env then download 2/2 + timeout-minutes: 10 + needs: test-env-then-download1 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v3 + - uses: ./ + with: + # Since the environment is cached, there will be no downloaded packages in $MAMBA_ROOT_PREFIX/pkgs. + # The caching should not fail because of this. + environment-file: test/environment.yml + cache-environment-key: env-then-download-env-${{ github.sha }}-${{ github.run_attempt }} + cache-downloads-key: env-then-download-download-${{ github.sha }}-${{ github.run_attempt }} + - name: test environment name + run: | + python -c "import os; env = os.path.basename(os.environ['CONDA_PREFIX']); assert env == 'env-name'" + test -d $MAMBA_ROOT_PREFIX + ! test -d $MAMBA_ROOT_PREFIX/pkgs diff --git a/dist/post.js b/dist/post.js index 2e68d1f..a6caf0a 100644 --- a/dist/post.js +++ b/dist/post.js @@ -61671,6 +61671,7 @@ var rcFileDict = { // src/cache.ts var import_path2 = __toESM(require("path")); var fs4 = __toESM(require("fs/promises")); +var import_fs = require("fs"); var cache = __toESM(require_cache()); var coreDefault4 = __toESM(require_core()); var core4 = process.env.MOCKING ? coreMocked : coreDefault4; @@ -61710,6 +61711,10 @@ var saveCacheDownloads = () => { } const cachePath = import_path2.default.join(options.micromambaRootPath, "pkgs"); const cacheDownloadsKey = generateDownloadsKey(options.cacheDownloadsKey); + if (!(0, import_fs.existsSync)(cachePath)) { + core4.debug(`Cache folder \`${cachePath}\` doesn't exist, skipping cache saving.`); + return Promise.resolve(); + } return trimPkgsCacheFolder(cachePath).then(() => { core4.startGroup(`Saving cache for \`${cachePath}\` ...`); return saveCache2(cachePath, cacheDownloadsKey); diff --git a/package.json b/package.json index dbfc7a0..c3fa1db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-micromamba", - "version": "1.4.0", + "version": "1.4.1", "private": true, "description": "Action to setup micromamba", "scripts": { diff --git a/src/cache.ts b/src/cache.ts index 4e0d557..d59f4ec 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,5 +1,6 @@ import path from 'path' import * as fs from 'fs/promises' +import { existsSync } from 'fs' import * as cache from '@actions/cache' import * as coreDefault from '@actions/core' import { coreMocked } from './mocking' @@ -117,6 +118,10 @@ export const saveCacheDownloads = () => { } const cachePath = path.join(options.micromambaRootPath, 'pkgs') const cacheDownloadsKey = generateDownloadsKey(options.cacheDownloadsKey) + if (!existsSync(cachePath)) { + core.debug(`Cache folder \`${cachePath}\` doesn't exist, skipping cache saving.`) + return Promise.resolve() + } return trimPkgsCacheFolder(cachePath) .then(() => { core.startGroup(`Saving cache for \`${cachePath}\` ...`)