Skip to content

Commit

Permalink
fix: saveCache shouldn't error on existing cache, warn instead (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
agilgur5 authored Aug 14, 2020
1 parent a7743cb commit 39a1dfc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/example-basic.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: example-basic
on: [push]
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/example-subfolders.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: example-subfolders
on: [push]
on: [push, pull_request]
jobs:
separate-actions:
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/example-without-lock-file.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: example-without-lock-file
on: [push]
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/example-yarn.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: example-yarn
on: [push]
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: main
on: [push]
on: [push, pull_request]

jobs:
build-and-test:
Expand Down
14 changes: 13 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 39a1dfc

Please sign in to comment.