File tree Expand file tree Collapse file tree 5 files changed +48
-7
lines changed
tests/utils/github-action-fixtures
already-has-cache/not-replace-bahmutov-npm-install
pending-to-add-cache/replace-bahmutov-npm-install Expand file tree Collapse file tree 5 files changed +48
-7
lines changed Original file line number Diff line number Diff line change
1
+ name : Node.js CI
2
+ " on " :
3
+ push :
4
+ branches :
5
+ - master
6
+ - " dependabot/**"
7
+ pull_request :
8
+ types :
9
+ - opened
10
+ - synchronize
11
+ jobs :
12
+ build :
13
+ runs-on : ubuntu-latest
14
+ steps :
15
+ - uses : bahmutov/npm-install@v1
16
+ - run : npm test
Original file line number Diff line number Diff line change
1
+ name : Node.js CI
2
+ " on " :
3
+ push :
4
+ branches :
5
+ - master
6
+ - " dependabot/**"
7
+ pull_request :
8
+ types :
9
+ - opened
10
+ - synchronize
11
+ jobs :
12
+ build :
13
+ runs-on : ubuntu-latest
14
+ steps :
15
+ - uses : bahmutov/npm-install@v1
16
+ - run : npm test
Original file line number Diff line number Diff line change 1
1
name : Node.js CI
2
- ' on ' :
2
+ " on " :
3
3
push :
4
4
branches :
5
5
- master
Original file line number Diff line number Diff line change 18
18
with :
19
19
node-version : 12.x
20
20
cache : npm
21
- - uses : bahmutov/ npm-install@v1
21
+ - run : npm ci
22
22
- run : npm test
Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ import prettier from "prettier";
3
3
4
4
const { parseDocument } = YAML ;
5
5
6
+ const usesBahmutovNpmInstall = ( hasCache , stepUses ) =>
7
+ hasCache && stepUses && stepUses . includes ( "bahmutov/npm-install" ) ;
8
+
6
9
/**
7
10
* @param {string } cache
8
11
*
@@ -27,11 +30,15 @@ export function getAddCacheToSetupNodeFunction(cache) {
27
30
28
31
for ( const { value : job } of jobs . items ) {
29
32
const steps = job . get ( "steps" ) ;
33
+ let jobHasCache = false ;
30
34
for ( const step of steps . items ) {
31
35
const stepUses = step . get ( "uses" ) ;
32
36
const stepWith = step . get ( "with" ) ;
33
37
34
- if (
38
+ if ( usesBahmutovNpmInstall ( jobHasCache , stepUses ) ) {
39
+ step . set ( "run" , "npm ci" ) ;
40
+ step . delete ( "uses" )
41
+ } else if (
35
42
stepUses &&
36
43
stepUses . includes ( "actions/setup-node" ) &&
37
44
( ! stepWith || ! stepWith . get ( "cache" ) )
@@ -47,13 +54,15 @@ export function getAddCacheToSetupNodeFunction(cache) {
47
54
}
48
55
49
56
cacheAdded = true ;
57
+ jobHasCache = true ;
50
58
}
51
59
}
52
60
}
53
61
54
- return cacheAdded ? prettier . format (
55
- yamlDocument . toString ( { lineWidth : 0 } ) , {
56
- parser : 'yaml'
57
- } ) : null ;
62
+ return cacheAdded
63
+ ? prettier . format ( yamlDocument . toString ( { lineWidth : 0 } ) , {
64
+ parser : "yaml" ,
65
+ } )
66
+ : null ;
58
67
} ;
59
68
}
You can’t perform that action at this time.
0 commit comments