Skip to content

Commit c63b1d0

Browse files
authoredJan 10, 2023
feat: build opt-out for cache-node-modules action (#1070)
I've used this action several times and did not know that it was also calling `npm run build`. The build step can increase a workflow's runtime and complexity, and I usually don't want to do that. I think it's useful, but since there was already support for `inputs.build`, I think it's unnecessary. An opt-out (since we don't want to break existing users) will help me out a lot.
1 parent 1007bc6 commit c63b1d0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
 

‎actions/cache-node-modules/action.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ inputs:
77
build:
88
description: 'Extra commands to run if nothing is cached'
99
required: false
10+
default: 'echo'
11+
build_on_cache_fail:
12+
description: 'Whether you want to run `npm run --if-present build` if there is no cache
13+
require: false
14+
default: 'true' # defaulting to true to not break any existing users.
1015
cache_name:
1116
description: 'Cache name'
1217
required: false
@@ -31,8 +36,11 @@ runs:
3136
${{ inputs.directories }}
3237
key: ${{ runner.os }}-build-${{ inputs.cache_name }}-${{ github.sha }}
3338
- if: steps.cache.outputs.cache-hit != 'true'
34-
run: |
35-
npm install
36-
npm run --if-present build
37-
${{ inputs.build }}
39+
run: npm install
40+
shell: bash
41+
- if: steps.cache.outputs.cache-hit != 'true' && ${{ inputs.build_on_cache_fail }} == 'true'
42+
run: npm run --if-present build
43+
shell: bash
44+
- if: steps.cache.outputs.cache-hit != 'true' && ${{ inputs.build }} != 'echo'
45+
run: ${{ inputs.build }}
3846
shell: bash

0 commit comments

Comments
 (0)
Please sign in to comment.