Skip to content

Commit efdd8bb

Browse files
authored
feat: support yarn (#15)
* feat: support yarn if yarn.lock file is found * add note about yarn lock and debugging
1 parent cbaadb6 commit efdd8bb

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ jobs:
137137
wait-on: http://localhost:8080
138138
```
139139

140+
## Notes
141+
142+
### Installation
143+
144+
This action installs local dependencies using lock files. If `yarn.lock` file is found, the install uses `yarn --frozen-lockfile` command. Otherwise it expects to find `package-lock.json` and install using `npm ci` command.
145+
146+
### Debugging
147+
148+
You can see verbose messages from GitHub Actions by setting the following secrets (from [Debugging Actions Guide](https://github.com/actions/toolkit/blob/master/docs/action-debugging.md#step-debug-logs))
149+
150+
```
151+
ACTIONS_RUNNER_DEBUG: true
152+
ACTIONS_STEP_DEBUG: true
153+
```
154+
140155
## More information
141156
142157
- [Building actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/building-actions) docs

dist/index.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,16 +1143,23 @@ const exec = __webpack_require__(986)
11431143
const hasha = __webpack_require__(309)
11441144
const execa = __webpack_require__(955)
11451145
const { restoreCache, saveCache } = __webpack_require__(211)
1146+
const fs = __webpack_require__(747)
11461147

1147-
const packageLockHash = hasha.fromFileSync('./package-lock.json')
1148+
const useYarn = fs.existsSync('yarn.lock')
1149+
const lockFilename = useYarn ? 'yarn.lock' : 'package-lock.json'
1150+
const lockHash = hasha.fromFileSync(lockFilename)
11481151
const platformAndArch = `${process.platform}-${process.arch}`
11491152

11501153
const NPM_CACHE = (() => {
1151-
const o = {
1152-
inputPath: '~/.npm',
1153-
restoreKeys: `npm-${platformAndArch}-`
1154+
const o = {}
1155+
if (useYarn) {
1156+
o.inputPath = '~/.cache/yarn'
1157+
o.restoreKeys = `yarn-${platformAndArch}-`
1158+
} else {
1159+
o.inputPath = '~/.npm'
1160+
o.restoreKeys = `npm-${platformAndArch}-`
11541161
}
1155-
o.primaryKey = o.restoreKeys + packageLockHash
1162+
o.primaryKey = o.restoreKeys + lockHash
11561163
return o
11571164
})()
11581165

@@ -1161,7 +1168,7 @@ const CYPRESS_BINARY_CACHE = (() => {
11611168
inputPath: '~/.cache/Cypress',
11621169
restoreKeys: `cypress-${platformAndArch}-`
11631170
}
1164-
o.primaryKey = o.restoreKeys + packageLockHash
1171+
o.primaryKey = o.restoreKeys + lockHash
11651172
return o
11661173
})()
11671174

@@ -1197,10 +1204,16 @@ const saveCachedCypressBinary = () => {
11971204
}
11981205

11991206
const install = () => {
1200-
console.log('installing NPM dependencies')
12011207
// prevent lots of progress messages during install
12021208
core.exportVariable('CI', '1')
1203-
return exec.exec('npm ci')
1209+
1210+
if (useYarn) {
1211+
console.log('installing NPM dependencies using Yarn')
1212+
return exec.exec('yarn --frozen-lockfile')
1213+
} else {
1214+
console.log('installing NPM dependencies')
1215+
return exec.exec('npm ci')
1216+
}
12041217
}
12051218

12061219
const verifyCypressBinary = () => {

index.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ const exec = require('@actions/exec')
44
const hasha = require('hasha')
55
const execa = require('execa')
66
const { restoreCache, saveCache } = require('cache/lib/index')
7+
const fs = require('fs')
78

8-
const packageLockHash = hasha.fromFileSync('./package-lock.json')
9+
const useYarn = fs.existsSync('yarn.lock')
10+
const lockFilename = useYarn ? 'yarn.lock' : 'package-lock.json'
11+
const lockHash = hasha.fromFileSync(lockFilename)
912
const platformAndArch = `${process.platform}-${process.arch}`
1013

1114
const NPM_CACHE = (() => {
12-
const o = {
13-
inputPath: '~/.npm',
14-
restoreKeys: `npm-${platformAndArch}-`
15+
const o = {}
16+
if (useYarn) {
17+
o.inputPath = '~/.cache/yarn'
18+
o.restoreKeys = `yarn-${platformAndArch}-`
19+
} else {
20+
o.inputPath = '~/.npm'
21+
o.restoreKeys = `npm-${platformAndArch}-`
1522
}
16-
o.primaryKey = o.restoreKeys + packageLockHash
23+
o.primaryKey = o.restoreKeys + lockHash
1724
return o
1825
})()
1926

@@ -22,7 +29,7 @@ const CYPRESS_BINARY_CACHE = (() => {
2229
inputPath: '~/.cache/Cypress',
2330
restoreKeys: `cypress-${platformAndArch}-`
2431
}
25-
o.primaryKey = o.restoreKeys + packageLockHash
32+
o.primaryKey = o.restoreKeys + lockHash
2633
return o
2734
})()
2835

@@ -58,10 +65,16 @@ const saveCachedCypressBinary = () => {
5865
}
5966

6067
const install = () => {
61-
console.log('installing NPM dependencies')
6268
// prevent lots of progress messages during install
6369
core.exportVariable('CI', '1')
64-
return exec.exec('npm ci')
70+
71+
if (useYarn) {
72+
console.log('installing NPM dependencies using Yarn')
73+
return exec.exec('yarn --frozen-lockfile')
74+
} else {
75+
console.log('installing NPM dependencies')
76+
return exec.exec('npm ci')
77+
}
6578
}
6679

6780
const verifyCypressBinary = () => {

0 commit comments

Comments
 (0)