(writeStreams: WriteStreams, expanded: {[key: string]: string})
| 1387 | } |
| 1388 | |
| 1389 | private async copyCacheOut (writeStreams: WriteStreams, expanded: {[key: string]: string}) { |
| 1390 | if (this.argv.mountCache && this.imageName(expanded)) return; |
| 1391 | if ((!this.imageName(expanded) && !this.argv.shellIsolation) || this.cache.length === 0) return; |
| 1392 | |
| 1393 | const cwd = this.argv.cwd; |
| 1394 | const stateDir = this.argv.stateDir; |
| 1395 | const cachePath = this.imageName(expanded) ? "/cache" : "../../cache"; |
| 1396 | |
| 1397 | let time, endTime; |
| 1398 | for (const [index, c] of this.cache.entries()) { |
| 1399 | if (!["push", "pull-push"].includes(c.policy)) return; |
| 1400 | if ("on_success" === c.when && this.jobStatus !== "success") return; |
| 1401 | if ("on_failure" === c.when && this.jobStatus === "success") return; |
| 1402 | const cacheName = await this.getUniqueCacheName(cwd, expanded, index); |
| 1403 | |
| 1404 | let paths = ""; |
| 1405 | for (const path of c.paths) { |
| 1406 | if (!Utils.isSubpath(path, this.argv.cwd, this.argv.cwd)) continue; |
| 1407 | |
| 1408 | paths += " ./" + Utils.expandText(path, expanded).replace(`${expanded.CI_PROJECT_DIR}/`, ""); |
| 1409 | } |
| 1410 | |
| 1411 | time = process.hrtime(); |
| 1412 | let cmd = "shopt -s globstar nullglob dotglob\n"; |
| 1413 | cmd += `mkdir -p ${Utils.safeBashString(cachePath + "/" + cacheName)}\n`; |
| 1414 | cmd += `rsync -Ra ${paths} ${Utils.safeBashString(cachePath + "/" + cacheName + "/.")} || true\n`; |
| 1415 | |
| 1416 | await Mutex.exclusive(cacheName, async () => { |
| 1417 | await this.copyOut(cmd, stateDir, "cache", []); |
| 1418 | }); |
| 1419 | endTime = process.hrtime(time); |
| 1420 | |
| 1421 | for (const __path of c.paths) { |
| 1422 | const _path = Utils.expandText(__path, expanded); |
| 1423 | if (!Utils.isSubpath(_path, this.argv.cwd, this.argv.cwd)) { |
| 1424 | writeStreams.stdout(chalk`{yellow WARNING: processPath: artifact path is not a subpath of project directory: ${_path}}\n`); |
| 1425 | continue; |
| 1426 | } |
| 1427 | |
| 1428 | let path = _path; |
| 1429 | if (isGlob(path) && !path.endsWith("*")) { |
| 1430 | path = `${path}/**`; |
| 1431 | } |
| 1432 | |
| 1433 | let numOfFiles = globbySync(path, { |
| 1434 | dot: true, |
| 1435 | onlyFiles: false, |
| 1436 | cwd: `${this.argv.cwd}/${stateDir}/cache/${cacheName}`, |
| 1437 | }).length; |
| 1438 | |
| 1439 | if (numOfFiles == 0) { |
| 1440 | writeStreams.stdout(chalk`{yellow WARNING: ${path}: no matching files. Ensure that the artifact path is relative to the working directory}\n`); |
| 1441 | continue; |
| 1442 | } |
| 1443 | |
| 1444 | if (!isGlob(path)) numOfFiles++; // add one because the pattern itself is a folder |
| 1445 | |
| 1446 | writeStreams.stdout(`${_path}: found ${numOfFiles} artifact files and directories\n`); |
no test coverage detected