From 1c11d652d7e3ecc680e1e1da87b050a6bcce0eb7 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 14 Aug 2020 01:16:43 -0400 Subject: [PATCH 1/2] hotfix: saveCache shouldn't error on existing cache, warn instead - if your workflow has a race condition where similar jobs with the same cache key run in parallel, one will saveCache first and the next will error out when trying to saveCache - previously this was a warning, but after upgrading to official @actions/cache, it is now an error - this can occur on matrix installs with similar enough environments (e.g. different Node version, same OS) and did occur in workflows here too actually - there's an upstream issue tracking this, so it might actually have a different root cause --- dist/index.js | 14 +++++++++++++- index.js | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2eb06bf..3309dd7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2756,7 +2756,19 @@ const restoreCachedNpm = npmCache => { const saveCachedNpm = npmCache => { console.log('saving NPM modules') - return cache.saveCache(npmCache.inputPaths, npmCache.primaryKey) + + return cache + .saveCache(npmCache.inputPaths, npmCache.primaryKey) + .catch(err => { + // don't throw an error if cache already exists, which may happen due to + // race conditions + if (err.message.includes('Cache already exists')) { + console.warn(err.message) + return -1 + } + // otherwise re-throw + throw err + }) } const hasOption = (name, o) => name in o diff --git a/index.js b/index.js index be99ea5..41aac7c 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,19 @@ const restoreCachedNpm = npmCache => { const saveCachedNpm = npmCache => { console.log('saving NPM modules') - return cache.saveCache(npmCache.inputPaths, npmCache.primaryKey) + + return cache + .saveCache(npmCache.inputPaths, npmCache.primaryKey) + .catch(err => { + // don't throw an error if cache already exists, which may happen due to + // race conditions + if (err.message.includes('Cache already exists')) { + console.warn(err.message) + return -1 + } + // otherwise re-throw + throw err + }) } const hasOption = (name, o) => name in o From 6d63686e34371e34b4cf5070bcb079e1b57ba77b Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 14 Aug 2020 02:22:03 -0400 Subject: [PATCH 2/2] ci: also run all workflows on PRs to ensure they pass - previously only ran on `push`, meaning only for root repo branches, and not PRs from forks - meaning they could be failing unknowingly and it would only be seen _after_ merge - as happened with my previous PR - this should make it run on PRs from forks as well, so failed CI checks should be very visible - (but branch protection needs to be turned on to prevent merging) --- .github/workflows/example-basic.yml | 2 +- .github/workflows/example-subfolders.yml | 2 +- .github/workflows/example-without-lock-file.yml | 2 +- .github/workflows/example-yarn.yml | 2 +- .github/workflows/main.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/example-basic.yml b/.github/workflows/example-basic.yml index 534fdac..6c08b0b 100644 --- a/.github/workflows/example-basic.yml +++ b/.github/workflows/example-basic.yml @@ -1,5 +1,5 @@ name: example-basic -on: [push] +on: [push, pull_request] jobs: test: runs-on: ubuntu-latest diff --git a/.github/workflows/example-subfolders.yml b/.github/workflows/example-subfolders.yml index e3ef36b..6b22481 100644 --- a/.github/workflows/example-subfolders.yml +++ b/.github/workflows/example-subfolders.yml @@ -1,5 +1,5 @@ name: example-subfolders -on: [push] +on: [push, pull_request] jobs: separate-actions: runs-on: ${{ matrix.os }} diff --git a/.github/workflows/example-without-lock-file.yml b/.github/workflows/example-without-lock-file.yml index 1e72540..69e2ca0 100644 --- a/.github/workflows/example-without-lock-file.yml +++ b/.github/workflows/example-without-lock-file.yml @@ -1,5 +1,5 @@ name: example-without-lock-file -on: [push] +on: [push, pull_request] jobs: test: runs-on: ubuntu-latest diff --git a/.github/workflows/example-yarn.yml b/.github/workflows/example-yarn.yml index c1c8267..8c09152 100644 --- a/.github/workflows/example-yarn.yml +++ b/.github/workflows/example-yarn.yml @@ -1,5 +1,5 @@ name: example-yarn -on: [push] +on: [push, pull_request] jobs: test: runs-on: ubuntu-latest diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6bc65c2..ba5b813 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,5 @@ name: main -on: [push] +on: [push, pull_request] jobs: build-and-test: