@actions/cache 1.0.5 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +8 -8
- package/README.md +44 -44
- package/lib/cache.d.ts +26 -26
- package/lib/cache.js +164 -146
- package/lib/cache.js.map +1 -1
- package/lib/internal/cacheHttpClient.d.ts +8 -8
- package/lib/internal/cacheHttpClient.js +215 -214
- package/lib/internal/cacheHttpClient.js.map +1 -1
- package/lib/internal/cacheUtils.d.ts +11 -11
- package/lib/internal/cacheUtils.js +169 -169
- package/lib/internal/constants.d.ts +12 -12
- package/lib/internal/constants.js +23 -23
- package/lib/internal/downloadUtils.d.ts +74 -74
- package/lib/internal/downloadUtils.js +229 -229
- package/lib/internal/downloadUtils.js.map +1 -1
- package/lib/internal/requestUtils.d.ts +7 -7
- package/lib/internal/requestUtils.js +118 -118
- package/lib/internal/tar.d.ts +4 -3
- package/lib/internal/tar.js +163 -124
- package/lib/internal/tar.js.map +1 -1
- package/lib/options.d.ts +56 -56
- package/lib/options.js +61 -61
- package/package.json +55 -55
package/LICENSE.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright 2019 GitHub
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright 2019 GitHub
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
9
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
# `@actions/cache`
|
|
2
|
-
|
|
3
|
-
> Functions necessary for caching dependencies and build outputs to improve workflow execution time.
|
|
4
|
-
|
|
5
|
-
See ["Caching dependencies to speed up workflows"](https://help.github.com/github/automating-your-workflow-with-github-actions/caching-dependencies-to-speed-up-workflows) for how caching works.
|
|
6
|
-
|
|
7
|
-
Note that GitHub will remove any cache entries that have not been accessed in over 7 days. There is no limit on the number of caches you can store, but the total size of all caches in a repository is limited to
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
This package is used by the v2+ versions of our first party cache action. You can find an example implementation in the cache repo [here](https://github.com/actions/cache).
|
|
12
|
-
|
|
13
|
-
####
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
const cache = require('@actions/cache');
|
|
19
|
-
const paths = [
|
|
20
|
-
'node_modules',
|
|
21
|
-
'packages/*/node_modules/'
|
|
22
|
-
]
|
|
23
|
-
const key = 'npm-foobar-d5ea0750'
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
'
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
```
|
|
44
|
-
|
|
1
|
+
# `@actions/cache`
|
|
2
|
+
|
|
3
|
+
> Functions necessary for caching dependencies and build outputs to improve workflow execution time.
|
|
4
|
+
|
|
5
|
+
See ["Caching dependencies to speed up workflows"](https://help.github.com/github/automating-your-workflow-with-github-actions/caching-dependencies-to-speed-up-workflows) for how caching works.
|
|
6
|
+
|
|
7
|
+
Note that GitHub will remove any cache entries that have not been accessed in over 7 days. There is no limit on the number of caches you can store, but the total size of all caches in a repository is limited to 10 GB. If you exceed this limit, GitHub will save your cache but will begin evicting caches until the total size is less than 10 GB.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
This package is used by the v2+ versions of our first party cache action. You can find an example implementation in the cache repo [here](https://github.com/actions/cache).
|
|
12
|
+
|
|
13
|
+
#### Save Cache
|
|
14
|
+
|
|
15
|
+
Saves a cache containing the files in `paths` using the `key` provided. The files would be compressed using zstandard compression algorithm if zstd is installed, otherwise gzip is used. Function returns the cache id if the cache was saved succesfully and throws an error if cache upload fails.
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const cache = require('@actions/cache');
|
|
19
|
+
const paths = [
|
|
20
|
+
'node_modules',
|
|
21
|
+
'packages/*/node_modules/'
|
|
22
|
+
]
|
|
23
|
+
const key = 'npm-foobar-d5ea0750'
|
|
24
|
+
const cacheId = await cache.saveCache(paths, key)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Restore Cache
|
|
28
|
+
|
|
29
|
+
Restores a cache based on `key` and `restoreKeys` to the `paths` provided. Function returns the cache key for cache hit and returns undefined if cache not found.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const cache = require('@actions/cache');
|
|
33
|
+
const paths = [
|
|
34
|
+
'node_modules',
|
|
35
|
+
'packages/*/node_modules/'
|
|
36
|
+
]
|
|
37
|
+
const key = 'npm-foobar-d5ea0750'
|
|
38
|
+
const restoreKeys = [
|
|
39
|
+
'npm-foobar-',
|
|
40
|
+
'npm-'
|
|
41
|
+
]
|
|
42
|
+
const cacheKey = await cache.restoreCache(paths, key, restoreKeys)
|
|
43
|
+
```
|
|
44
|
+
|
package/lib/cache.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { DownloadOptions, UploadOptions } from './options';
|
|
2
|
-
export declare class ValidationError extends Error {
|
|
3
|
-
constructor(message: string);
|
|
4
|
-
}
|
|
5
|
-
export declare class ReserveCacheError extends Error {
|
|
6
|
-
constructor(message: string);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Restores cache from keys
|
|
10
|
-
*
|
|
11
|
-
* @param paths a list of file paths to restore from the cache
|
|
12
|
-
* @param primaryKey an explicit key for restoring the cache
|
|
13
|
-
* @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key
|
|
14
|
-
* @param downloadOptions cache download options
|
|
15
|
-
* @returns string returns the key for the cache hit, otherwise returns undefined
|
|
16
|
-
*/
|
|
17
|
-
export declare function restoreCache(paths: string[], primaryKey: string, restoreKeys?: string[], options?: DownloadOptions): Promise<string | undefined>;
|
|
18
|
-
/**
|
|
19
|
-
* Saves a list of files with the specified key
|
|
20
|
-
*
|
|
21
|
-
* @param paths a list of file paths to be cached
|
|
22
|
-
* @param key an explicit key for restoring the cache
|
|
23
|
-
* @param options cache upload options
|
|
24
|
-
* @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
|
|
25
|
-
*/
|
|
26
|
-
export declare function saveCache(paths: string[], key: string, options?: UploadOptions): Promise<number>;
|
|
1
|
+
import { DownloadOptions, UploadOptions } from './options';
|
|
2
|
+
export declare class ValidationError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class ReserveCacheError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Restores cache from keys
|
|
10
|
+
*
|
|
11
|
+
* @param paths a list of file paths to restore from the cache
|
|
12
|
+
* @param primaryKey an explicit key for restoring the cache
|
|
13
|
+
* @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key
|
|
14
|
+
* @param downloadOptions cache download options
|
|
15
|
+
* @returns string returns the key for the cache hit, otherwise returns undefined
|
|
16
|
+
*/
|
|
17
|
+
export declare function restoreCache(paths: string[], primaryKey: string, restoreKeys?: string[], options?: DownloadOptions): Promise<string | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Saves a list of files with the specified key
|
|
20
|
+
*
|
|
21
|
+
* @param paths a list of file paths to be cached
|
|
22
|
+
* @param key an explicit key for restoring the cache
|
|
23
|
+
* @param options cache upload options
|
|
24
|
+
* @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
|
|
25
|
+
*/
|
|
26
|
+
export declare function saveCache(paths: string[], key: string, options?: UploadOptions): Promise<number>;
|
package/lib/cache.js
CHANGED
|
@@ -1,147 +1,165 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12
|
-
if (mod && mod.__esModule) return mod;
|
|
13
|
-
var result = {};
|
|
14
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
15
|
-
result["default"] = mod;
|
|
16
|
-
return result;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
const core = __importStar(require("@actions/core"));
|
|
20
|
-
const path = __importStar(require("path"));
|
|
21
|
-
const utils = __importStar(require("./internal/cacheUtils"));
|
|
22
|
-
const cacheHttpClient = __importStar(require("./internal/cacheHttpClient"));
|
|
23
|
-
const tar_1 = require("./internal/tar");
|
|
24
|
-
class ValidationError extends Error {
|
|
25
|
-
constructor(message) {
|
|
26
|
-
super(message);
|
|
27
|
-
this.name = 'ValidationError';
|
|
28
|
-
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.ValidationError = ValidationError;
|
|
32
|
-
class ReserveCacheError extends Error {
|
|
33
|
-
constructor(message) {
|
|
34
|
-
super(message);
|
|
35
|
-
this.name = 'ReserveCacheError';
|
|
36
|
-
Object.setPrototypeOf(this, ReserveCacheError.prototype);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.ReserveCacheError = ReserveCacheError;
|
|
40
|
-
function checkPaths(paths) {
|
|
41
|
-
if (!paths || paths.length === 0) {
|
|
42
|
-
throw new ValidationError(`Path Validation Error: At least one directory or file path is required`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function checkKey(key) {
|
|
46
|
-
if (key.length > 512) {
|
|
47
|
-
throw new ValidationError(`Key Validation Error: ${key} cannot be larger than 512 characters.`);
|
|
48
|
-
}
|
|
49
|
-
const regex = /^[^,]*$/;
|
|
50
|
-
if (!regex.test(key)) {
|
|
51
|
-
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Restores cache from keys
|
|
56
|
-
*
|
|
57
|
-
* @param paths a list of file paths to restore from the cache
|
|
58
|
-
* @param primaryKey an explicit key for restoring the cache
|
|
59
|
-
* @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key
|
|
60
|
-
* @param downloadOptions cache download options
|
|
61
|
-
* @returns string returns the key for the cache hit, otherwise returns undefined
|
|
62
|
-
*/
|
|
63
|
-
function restoreCache(paths, primaryKey, restoreKeys, options) {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
checkPaths(paths);
|
|
66
|
-
restoreKeys = restoreKeys || [];
|
|
67
|
-
const keys = [primaryKey, ...restoreKeys];
|
|
68
|
-
core.debug('Resolved Keys:');
|
|
69
|
-
core.debug(JSON.stringify(keys));
|
|
70
|
-
if (keys.length > 10) {
|
|
71
|
-
throw new ValidationError(`Key Validation Error: Keys are limited to a maximum of 10.`);
|
|
72
|
-
}
|
|
73
|
-
for (const key of keys) {
|
|
74
|
-
checkKey(key);
|
|
75
|
-
}
|
|
76
|
-
const compressionMethod = yield utils.getCompressionMethod();
|
|
77
|
-
// path are needed to compute version
|
|
78
|
-
const cacheEntry = yield cacheHttpClient.getCacheEntry(keys, paths, {
|
|
79
|
-
compressionMethod
|
|
80
|
-
});
|
|
81
|
-
if (!(cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.archiveLocation)) {
|
|
82
|
-
// Cache not found
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
const archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod));
|
|
86
|
-
core.debug(`Archive Path: ${archivePath}`);
|
|
87
|
-
try {
|
|
88
|
-
// Download the cache from the cache entry
|
|
89
|
-
yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, archivePath, options);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
core.debug(
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
core.debug(`
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12
|
+
if (mod && mod.__esModule) return mod;
|
|
13
|
+
var result = {};
|
|
14
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
15
|
+
result["default"] = mod;
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
const core = __importStar(require("@actions/core"));
|
|
20
|
+
const path = __importStar(require("path"));
|
|
21
|
+
const utils = __importStar(require("./internal/cacheUtils"));
|
|
22
|
+
const cacheHttpClient = __importStar(require("./internal/cacheHttpClient"));
|
|
23
|
+
const tar_1 = require("./internal/tar");
|
|
24
|
+
class ValidationError extends Error {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = 'ValidationError';
|
|
28
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ValidationError = ValidationError;
|
|
32
|
+
class ReserveCacheError extends Error {
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = 'ReserveCacheError';
|
|
36
|
+
Object.setPrototypeOf(this, ReserveCacheError.prototype);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ReserveCacheError = ReserveCacheError;
|
|
40
|
+
function checkPaths(paths) {
|
|
41
|
+
if (!paths || paths.length === 0) {
|
|
42
|
+
throw new ValidationError(`Path Validation Error: At least one directory or file path is required`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function checkKey(key) {
|
|
46
|
+
if (key.length > 512) {
|
|
47
|
+
throw new ValidationError(`Key Validation Error: ${key} cannot be larger than 512 characters.`);
|
|
48
|
+
}
|
|
49
|
+
const regex = /^[^,]*$/;
|
|
50
|
+
if (!regex.test(key)) {
|
|
51
|
+
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Restores cache from keys
|
|
56
|
+
*
|
|
57
|
+
* @param paths a list of file paths to restore from the cache
|
|
58
|
+
* @param primaryKey an explicit key for restoring the cache
|
|
59
|
+
* @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key
|
|
60
|
+
* @param downloadOptions cache download options
|
|
61
|
+
* @returns string returns the key for the cache hit, otherwise returns undefined
|
|
62
|
+
*/
|
|
63
|
+
function restoreCache(paths, primaryKey, restoreKeys, options) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
checkPaths(paths);
|
|
66
|
+
restoreKeys = restoreKeys || [];
|
|
67
|
+
const keys = [primaryKey, ...restoreKeys];
|
|
68
|
+
core.debug('Resolved Keys:');
|
|
69
|
+
core.debug(JSON.stringify(keys));
|
|
70
|
+
if (keys.length > 10) {
|
|
71
|
+
throw new ValidationError(`Key Validation Error: Keys are limited to a maximum of 10.`);
|
|
72
|
+
}
|
|
73
|
+
for (const key of keys) {
|
|
74
|
+
checkKey(key);
|
|
75
|
+
}
|
|
76
|
+
const compressionMethod = yield utils.getCompressionMethod();
|
|
77
|
+
// path are needed to compute version
|
|
78
|
+
const cacheEntry = yield cacheHttpClient.getCacheEntry(keys, paths, {
|
|
79
|
+
compressionMethod
|
|
80
|
+
});
|
|
81
|
+
if (!(cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.archiveLocation)) {
|
|
82
|
+
// Cache not found
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod));
|
|
86
|
+
core.debug(`Archive Path: ${archivePath}`);
|
|
87
|
+
try {
|
|
88
|
+
// Download the cache from the cache entry
|
|
89
|
+
yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, archivePath, options);
|
|
90
|
+
if (core.isDebug()) {
|
|
91
|
+
yield tar_1.listTar(archivePath, compressionMethod);
|
|
92
|
+
}
|
|
93
|
+
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath);
|
|
94
|
+
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
|
95
|
+
yield tar_1.extractTar(archivePath, compressionMethod);
|
|
96
|
+
core.info('Cache restored successfully');
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
// Try to delete the archive to save space
|
|
100
|
+
try {
|
|
101
|
+
yield utils.unlinkFile(archivePath);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
core.debug(`Failed to delete archive: ${error}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return cacheEntry.cacheKey;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
exports.restoreCache = restoreCache;
|
|
111
|
+
/**
|
|
112
|
+
* Saves a list of files with the specified key
|
|
113
|
+
*
|
|
114
|
+
* @param paths a list of file paths to be cached
|
|
115
|
+
* @param key an explicit key for restoring the cache
|
|
116
|
+
* @param options cache upload options
|
|
117
|
+
* @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
|
|
118
|
+
*/
|
|
119
|
+
function saveCache(paths, key, options) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
checkPaths(paths);
|
|
122
|
+
checkKey(key);
|
|
123
|
+
const compressionMethod = yield utils.getCompressionMethod();
|
|
124
|
+
core.debug('Reserving Cache');
|
|
125
|
+
const cacheId = yield cacheHttpClient.reserveCache(key, paths, {
|
|
126
|
+
compressionMethod
|
|
127
|
+
});
|
|
128
|
+
if (cacheId === -1) {
|
|
129
|
+
throw new ReserveCacheError(`Unable to reserve cache with key ${key}, another job may be creating this cache.`);
|
|
130
|
+
}
|
|
131
|
+
core.debug(`Cache ID: ${cacheId}`);
|
|
132
|
+
const cachePaths = yield utils.resolvePaths(paths);
|
|
133
|
+
core.debug('Cache Paths:');
|
|
134
|
+
core.debug(`${JSON.stringify(cachePaths)}`);
|
|
135
|
+
const archiveFolder = yield utils.createTempDirectory();
|
|
136
|
+
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
|
|
137
|
+
core.debug(`Archive Path: ${archivePath}`);
|
|
138
|
+
try {
|
|
139
|
+
yield tar_1.createTar(archiveFolder, cachePaths, compressionMethod);
|
|
140
|
+
if (core.isDebug()) {
|
|
141
|
+
yield tar_1.listTar(archivePath, compressionMethod);
|
|
142
|
+
}
|
|
143
|
+
const fileSizeLimit = 10 * 1024 * 1024 * 1024; // 10GB per repo limit
|
|
144
|
+
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath);
|
|
145
|
+
core.debug(`File Size: ${archiveFileSize}`);
|
|
146
|
+
if (archiveFileSize > fileSizeLimit) {
|
|
147
|
+
throw new Error(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the 10GB limit, not saving cache.`);
|
|
148
|
+
}
|
|
149
|
+
core.debug(`Saving Cache (ID: ${cacheId})`);
|
|
150
|
+
yield cacheHttpClient.saveCache(cacheId, archivePath, options);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
// Try to delete the archive to save space
|
|
154
|
+
try {
|
|
155
|
+
yield utils.unlinkFile(archivePath);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
core.debug(`Failed to delete archive: ${error}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return cacheId;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
exports.saveCache = saveCache;
|
|
147
165
|
//# sourceMappingURL=cache.js.map
|
package/lib/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AACrC,2CAA4B;AAC5B,6DAA8C;AAC9C,4EAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AACrC,2CAA4B;AAC5B,6DAA8C;AAC9C,4EAA6D;AAC7D,wCAA6D;AAG7D,MAAa,eAAgB,SAAQ,KAAK;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AgB,CAAC,iBAAiB,CAAC,CAC1C,CAAA;QAED,IAAI,CAAC,KAAK,CAAC,iBAAiB,WAAW,EAAE,CAAC,CAAA;QAE1C,IAAI;YACF,MAAM,eAAS,CAAC,aAAa,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAA;YAC7D,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE;gBAClB,MAAM,aAAO,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAA;aAC9C;YAED,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA,CAAC,sBAAsB;YACpE,MAAM,eAAe,GAAG,KAAK,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAA;YACpE,IAAI,CAAC,KAAK,CAAC,cAAc,eAAe,EAAE,CAAC,CAAA;YAC3C,IAAI,eAAe,GAAG,aAAa,EAAE;gBACnC,MAAM,IAAI,KAAK,CACb,kBAAkB,IAAI,CAAC,KAAK,CAC1B,eAAe,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAChC,QAAQ,eAAe,+CAA+C,CACxE,CAAA;aACF;YAED,IAAI,CAAC,KAAK,CAAC,qBAAqB,OAAO,GAAG,CAAC,CAAA;YAC3C,MAAM,eAAe,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;SAC/D;gBAAS;YACR,0CAA0C;YAC1C,IAAI;gBACF,MAAM,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;aACpC;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,KAAK,CAAC,6BAA6B,KAAK,EAAE,CAAC,CAAA;aACjD;SACF;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CAAA;AA9DD,8BA8DC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CompressionMethod } from './constants';
|
|
2
|
-
import { ArtifactCacheEntry, InternalCacheOptions } from './contracts';
|
|
3
|
-
import { DownloadOptions, UploadOptions } from '../options';
|
|
4
|
-
export declare function getCacheVersion(paths: string[], compressionMethod?: CompressionMethod): string;
|
|
5
|
-
export declare function getCacheEntry(keys: string[], paths: string[], options?: InternalCacheOptions): Promise<ArtifactCacheEntry | null>;
|
|
6
|
-
export declare function downloadCache(archiveLocation: string, archivePath: string, options?: DownloadOptions): Promise<void>;
|
|
7
|
-
export declare function reserveCache(key: string, paths: string[], options?: InternalCacheOptions): Promise<number>;
|
|
8
|
-
export declare function saveCache(cacheId: number, archivePath: string, options?: UploadOptions): Promise<void>;
|
|
1
|
+
import { CompressionMethod } from './constants';
|
|
2
|
+
import { ArtifactCacheEntry, InternalCacheOptions } from './contracts';
|
|
3
|
+
import { DownloadOptions, UploadOptions } from '../options';
|
|
4
|
+
export declare function getCacheVersion(paths: string[], compressionMethod?: CompressionMethod): string;
|
|
5
|
+
export declare function getCacheEntry(keys: string[], paths: string[], options?: InternalCacheOptions): Promise<ArtifactCacheEntry | null>;
|
|
6
|
+
export declare function downloadCache(archiveLocation: string, archivePath: string, options?: DownloadOptions): Promise<void>;
|
|
7
|
+
export declare function reserveCache(key: string, paths: string[], options?: InternalCacheOptions): Promise<number>;
|
|
8
|
+
export declare function saveCache(cacheId: number, archivePath: string, options?: UploadOptions): Promise<void>;
|