Compare commits

..

1 Commits

Author SHA1 Message Date
e7ad80454a Release preview version 2019-10-30 14:50:22 -04:00
13 changed files with 128 additions and 320 deletions

View File

@ -1,27 +1,16 @@
name: Tests name: Test Cache Action
on: on:
pull_request: pull_request:
push: push:
branches: branches:
- master - master
paths-ignore:
- '**.md'
jobs: jobs:
test: test:
name: Test on ${{ matrix.os }} runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm ci - run: npm ci
- name: Prettier Format Check - name: Prettier Format Check

View File

@ -1,76 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at opensource+actions/cache@github.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

View File

@ -2,12 +2,6 @@
This GitHub Action allows caching dependencies and build outputs to improve workflow execution time. This GitHub Action allows caching dependencies and build outputs to improve workflow execution time.
<a href="https://github.com/actions/cache"><img alt="GitHub Actions status" src="https://github.com/actions/cache/workflows/Tests/badge.svg?branch=master&event=push"></a>
## Documentation
See ["Caching dependencies to speed up workflows"](https://help.github.com/github/automating-your-workflow-with-github-actions/caching-dependencies-to-speed-up-workflows).
## Usage ## Usage
### Pre-requisites ### Pre-requisites
@ -39,13 +33,11 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: Cache node modules - name: Cache node_modules
uses: actions/cache@v1 uses: actions/cache@preview
with: with:
path: node_modules path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} key: ${{ runner.os }}-node
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies - name: Install Dependencies
run: npm install run: npm install
@ -56,14 +48,61 @@ jobs:
- name: Test - name: Test
run: npm run test run: npm run test
``` ```
## Ecosystem Examples ## Ecosystem Examples
See [Examples](examples.md) ### Node - npm
```yaml
- uses: actions/cache@preview
with:
path: node_modules
key: ${{ runner.os }}-node
```
### Node - Yarn
```yaml
- uses: actions/cache@preview
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
restore-keys: |
${{ runner.os }}-yarn-
```
### C# - Nuget
```yaml
- uses: actions/cache@preview
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
```
### Java - Gradle
```yaml
- uses: actions/cache@preview
with:
path: ~/.gradle/caches
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle') }}
restore-keys: |
gradle-${{ runner.os }}-
```
### Java - Maven
```yaml
- uses: actions/cache@preview
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven
```
## Cache Limits ## Cache Limits
Individual caches are limited to 400MB and a repository can have up to 2GB of caches. Once the 2GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted. Individual caches are limited to 200MB and a repository can have up to 2GB of caches. Once the 2GB limit is reached, older caches will be evicted based on when the cache was last accessed.
## Skipping steps based on cache-hit ## Skipping steps based on cache-hit
@ -74,7 +113,7 @@ Example:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: actions/cache@v1 - uses: actions/cache@preview
id: cache id: cache
with: with:
path: path/to/dependencies path: path/to/dependencies
@ -85,7 +124,7 @@ steps:
run: /install.sh run: /install.sh
``` ```
> Note: The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`) > Note: The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outupts.cache-hit`)
## Contributing ## Contributing
We would love for you to contribute to `@actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. We would love for you to contribute to `@actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

33
dist/restore/index.js vendored
View File

@ -1475,11 +1475,10 @@ exports.debug = debug; // for test
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
@ -1507,7 +1506,7 @@ function getCacheEntry(keys) {
]); ]);
const response = yield restClient.get(resource, getRequestOptions()); const response = yield restClient.get(resource, getRequestOptions());
if (response.statusCode === 204) { if (response.statusCode === 204) {
return null; throw new Error(`Cache not found for input keys: ${JSON.stringify(keys)}.`);
} }
if (response.statusCode !== 200) { if (response.statusCode !== 200) {
throw new Error(`Cache service responded with ${response.statusCode}`); throw new Error(`Cache service responded with ${response.statusCode}`);
@ -2121,11 +2120,10 @@ exports.createType3Message = createType3Message;
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
@ -2202,7 +2200,7 @@ function resolvePath(filePath) {
if (filePath[0] === "~") { if (filePath[0] === "~") {
const home = os.homedir(); const home = os.homedir();
if (!home) { if (!home) {
throw new Error("Unable to resolve `~` to HOME"); throw new Error("Unable to resole `~` to HOME");
} }
return path.join(home, filePath.slice(1)); return path.join(home, filePath.slice(1));
} }
@ -2940,11 +2938,10 @@ module.exports = require("fs");
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
@ -2972,10 +2969,7 @@ function run() {
core.debug(`Cache Path: ${cachePath}`); core.debug(`Cache Path: ${cachePath}`);
const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
core.saveState(constants_1.State.CacheKey, primaryKey); core.saveState(constants_1.State.CacheKey, primaryKey);
const restoreKeys = core const restoreKeys = core.getInput(constants_1.Inputs.RestoreKeys).split("\n");
.getInput(constants_1.Inputs.RestoreKeys)
.split("\n")
.filter(x => x !== "");
const keys = [primaryKey, ...restoreKeys]; const keys = [primaryKey, ...restoreKeys];
core.debug("Resolved Keys:"); core.debug("Resolved Keys:");
core.debug(JSON.stringify(keys)); core.debug(JSON.stringify(keys));
@ -2995,13 +2989,9 @@ function run() {
} }
} }
try { try {
const cacheEntry = yield cacheHttpClient.getCacheEntry(keys);
if (!cacheEntry) {
core.info(`Cache not found for input keys: ${keys.join(", ")}.`);
return;
}
let archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz"); let archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz");
core.debug(`Archive Path: ${archivePath}`); core.debug(`Archive Path: ${archivePath}`);
const cacheEntry = yield cacheHttpClient.getCacheEntry(keys);
// Store the cache result // Store the cache result
utils.setCacheState(cacheEntry); utils.setCacheState(cacheEntry);
// Download the cache from the cache entry // Download the cache from the cache entry
@ -3024,7 +3014,14 @@ function run() {
yield exec_1.exec(`"${tarPath}"`, args); yield exec_1.exec(`"${tarPath}"`, args);
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheEntry); const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheEntry);
utils.setCacheHitOutput(isExactKeyMatch); utils.setCacheHitOutput(isExactKeyMatch);
core.info(`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`); core.info(`Cache restored from key:${cacheEntry && cacheEntry.cacheKey}`);
try {
core.info("Cache Checksum:");
yield exec_1.exec(`md5sum`, [`${archivePath}`]);
}
catch (error) {
core.debug(`Failed to checkum with ${error}`);
}
} }
catch (error) { catch (error) {
core.warning(error.message); core.warning(error.message);

24
dist/save/index.js vendored
View File

@ -1475,11 +1475,10 @@ exports.debug = debug; // for test
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
@ -1507,7 +1506,7 @@ function getCacheEntry(keys) {
]); ]);
const response = yield restClient.get(resource, getRequestOptions()); const response = yield restClient.get(resource, getRequestOptions());
if (response.statusCode === 204) { if (response.statusCode === 204) {
return null; throw new Error(`Cache not found for input keys: ${JSON.stringify(keys)}.`);
} }
if (response.statusCode !== 200) { if (response.statusCode !== 200) {
throw new Error(`Cache service responded with ${response.statusCode}`); throw new Error(`Cache service responded with ${response.statusCode}`);
@ -2121,11 +2120,10 @@ exports.createType3Message = createType3Message;
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
@ -2202,7 +2200,7 @@ function resolvePath(filePath) {
if (filePath[0] === "~") { if (filePath[0] === "~") {
const home = os.homedir(); const home = os.homedir();
if (!home) { if (!home) {
throw new Error("Unable to resolve `~` to HOME"); throw new Error("Unable to resole `~` to HOME");
} }
return path.join(home, filePath.slice(1)); return path.join(home, filePath.slice(1));
} }
@ -2834,11 +2832,10 @@ function isUnixExecutable(stats) {
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
@ -2889,15 +2886,22 @@ function run() {
const tarPath = yield io.which("tar", true); const tarPath = yield io.which("tar", true);
core.debug(`Tar Path: ${tarPath}`); core.debug(`Tar Path: ${tarPath}`);
yield exec_1.exec(`"${tarPath}"`, args); yield exec_1.exec(`"${tarPath}"`, args);
const fileSizeLimit = 400 * 1024 * 1024; // 400MB const fileSizeLimit = 200 * 1024 * 1024; // 200MB
const archiveFileSize = fs.statSync(archivePath).size; const archiveFileSize = fs.statSync(archivePath).size;
core.debug(`File Size: ${archiveFileSize}`); core.debug(`File Size: ${archiveFileSize}`);
if (archiveFileSize > fileSizeLimit) { if (archiveFileSize > fileSizeLimit) {
core.warning(`Cache size of ${archiveFileSize} bytes is over the 400MB limit, not saving cache.`); core.warning(`Cache size of ${archiveFileSize} bytes is over the 200MB limit, not saving cache.`);
return; return;
} }
const stream = fs.createReadStream(archivePath); const stream = fs.createReadStream(archivePath);
yield cacheHttpClient.saveCache(stream, primaryKey); yield cacheHttpClient.saveCache(stream, primaryKey);
try {
core.info("Cache Checksum:");
yield exec_1.exec(`md5sum`, [`${archivePath}`]);
}
catch (error) {
core.debug(`Failed to checkum with ${error}`);
}
} }
catch (error) { catch (error) {
core.warning(error.message); core.warning(error.message);

View File

@ -1,143 +0,0 @@
# Examples
- [C# - Nuget](#c---nuget)
- [Elixir - Mix](#elixir---mix)
- [Go - Modules](#go---modules)
- [Java - Gradle](#java---gradle)
- [Java - Maven](#java---maven)
- [Node - npm](#node---npm)
- [Node - Yarn](#node---yarn)
- [Ruby - Gem](#ruby---gem)
- [Rust - Cargo](#rust---cargo)
- [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods)
## C# - Nuget
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
```yaml
- uses: actions/cache@v1
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
```
## Elixir - Mix
```yaml
- uses: actions/cache@v1
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
```
## Go - Modules
```yaml
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
```
## Java - Gradle
```yaml
- uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
```
## Java - Maven
```yaml
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
```
## Node - npm
```yaml
- uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
```
## Node - Yarn
```yaml
- uses: actions/cache@v1
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
restore-keys: |
${{ runner.os }}-yarn-
```
## Ruby - Gem
```yaml
- uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gem-
```
## Rust - Cargo
```yaml
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
```
## Swift, Objective-C - Carthage
```yaml
- uses: actions/cache@v1
with:
path: Carthage
key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
restore-keys: |
${{ runner.os }}-carthage-
```
## Swift, Objective-C - CocoaPods
```yaml
- uses: actions/cache@v1
with:
path: Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
```

View File

@ -9,12 +9,3 @@ module.exports = {
}, },
verbose: true verbose: true
} }
const processStdoutWrite = process.stdout.write.bind(process.stdout)
process.stdout.write = (str, encoding, cb) => {
// Core library will directly call process.stdout.write for commands
// We don't want :: commands to be executed by the runner during tests
if (!str.match(/^::/)) {
return processStdoutWrite(str, encoding, cb);
}
}

28
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "cache", "name": "cache",
"version": "1.0.1", "version": "0.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -1105,9 +1105,9 @@
} }
}, },
"commander": { "commander": {
"version": "2.20.3", "version": "2.20.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==",
"dev": true, "dev": true,
"optional": true "optional": true
}, },
@ -2318,9 +2318,9 @@
"dev": true "dev": true
}, },
"handlebars": { "handlebars": {
"version": "4.5.1", "version": "4.4.2",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.1.tgz", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.2.tgz",
"integrity": "sha512-C29UoFzHe9yM61lOsIlCE5/mQVGrnIOrOq7maQl76L7tYPCgC1og0Ajt6uWnX4ZTxBPnjw+CUvawphwCfJgUnA==", "integrity": "sha512-cIv17+GhL8pHHnRJzGu2wwcthL5sb8uDKBHvZ2Dtu5s1YNt0ljbzKbamnc+gr69y7bzwQiBdr5+hOpRd5pnOdg==",
"dev": true, "dev": true,
"requires": { "requires": {
"neo-async": "^2.6.0", "neo-async": "^2.6.0",
@ -4975,19 +4975,19 @@
} }
}, },
"typescript": { "typescript": {
"version": "3.6.4", "version": "3.5.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.4.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.3.tgz",
"integrity": "sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==", "integrity": "sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==",
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {
"version": "3.6.7", "version": "3.6.0",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.7.tgz", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz",
"integrity": "sha512-4sXQDzmdnoXiO+xvmTzQsfIiwrjUCSA95rSP4SEd8tDb51W2TiDOlL76Hl+Kw0Ie42PSItCW8/t6pBNCF2R48A==", "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==",
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"commander": "~2.20.3", "commander": "~2.20.0",
"source-map": "~0.6.1" "source-map": "~0.6.1"
} }
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "cache", "name": "cache",
"version": "1.0.1", "version": "0.0.1",
"private": true, "private": true,
"description": "Cache dependencies and build outputs", "description": "Cache dependencies and build outputs",
"main": "dist/restore/index.js", "main": "dist/restore/index.js",
@ -38,6 +38,6 @@
"jest-circus": "^24.7.1", "jest-circus": "^24.7.1",
"prettier": "1.18.2", "prettier": "1.18.2",
"ts-jest": "^24.0.2", "ts-jest": "^24.0.2",
"typescript": "^3.6.4" "typescript": "^3.5.1"
} }
} }

View File

@ -10,7 +10,7 @@ import { ArtifactCacheEntry } from "./contracts";
export async function getCacheEntry( export async function getCacheEntry(
keys: string[] keys: string[]
): Promise<ArtifactCacheEntry | null> { ): Promise<ArtifactCacheEntry> {
const cacheUrl = getCacheUrl(); const cacheUrl = getCacheUrl();
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || ""; const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
const bearerCredentialHandler = new BearerCredentialHandler(token); const bearerCredentialHandler = new BearerCredentialHandler(token);
@ -28,7 +28,9 @@ export async function getCacheEntry(
getRequestOptions() getRequestOptions()
); );
if (response.statusCode === 204) { if (response.statusCode === 204) {
return null; throw new Error(
`Cache not found for input keys: ${JSON.stringify(keys)}.`
);
} }
if (response.statusCode !== 200) { if (response.statusCode !== 200) {
throw new Error(`Cache service responded with ${response.statusCode}`); throw new Error(`Cache service responded with ${response.statusCode}`);

View File

@ -20,10 +20,7 @@ async function run() {
const primaryKey = core.getInput(Inputs.Key, { required: true }); const primaryKey = core.getInput(Inputs.Key, { required: true });
core.saveState(State.CacheKey, primaryKey); core.saveState(State.CacheKey, primaryKey);
const restoreKeys = core const restoreKeys = core.getInput(Inputs.RestoreKeys).split("\n");
.getInput(Inputs.RestoreKeys)
.split("\n")
.filter(x => x !== "");
const keys = [primaryKey, ...restoreKeys]; const keys = [primaryKey, ...restoreKeys];
core.debug("Resolved Keys:"); core.debug("Resolved Keys:");
@ -52,20 +49,14 @@ async function run() {
} }
try { try {
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
if (!cacheEntry) {
core.info(
`Cache not found for input keys: ${keys.join(", ")}.`
);
return;
}
let archivePath = path.join( let archivePath = path.join(
await utils.createTempDirectory(), await utils.createTempDirectory(),
"cache.tgz" "cache.tgz"
); );
core.debug(`Archive Path: ${archivePath}`); core.debug(`Archive Path: ${archivePath}`);
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
// Store the cache result // Store the cache result
utils.setCacheState(cacheEntry); utils.setCacheState(cacheEntry);
@ -101,8 +92,15 @@ async function run() {
utils.setCacheHitOutput(isExactKeyMatch); utils.setCacheHitOutput(isExactKeyMatch);
core.info( core.info(
`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}` `Cache restored from key:${cacheEntry && cacheEntry.cacheKey}`
); );
try {
core.info("Cache Checksum:");
await exec(`md5sum`, [`${archivePath}`]);
} catch (error) {
core.debug(`Failed to checkum with ${error}`);
}
} catch (error) { } catch (error) {
core.warning(error.message); core.warning(error.message);
utils.setCacheHitOutput(false); utils.setCacheHitOutput(false);

View File

@ -54,18 +54,25 @@ async function run() {
core.debug(`Tar Path: ${tarPath}`); core.debug(`Tar Path: ${tarPath}`);
await exec(`"${tarPath}"`, args); await exec(`"${tarPath}"`, args);
const fileSizeLimit = 400 * 1024 * 1024; // 400MB const fileSizeLimit = 200 * 1024 * 1024; // 200MB
const archiveFileSize = fs.statSync(archivePath).size; const archiveFileSize = fs.statSync(archivePath).size;
core.debug(`File Size: ${archiveFileSize}`); core.debug(`File Size: ${archiveFileSize}`);
if (archiveFileSize > fileSizeLimit) { if (archiveFileSize > fileSizeLimit) {
core.warning( core.warning(
`Cache size of ${archiveFileSize} bytes is over the 400MB limit, not saving cache.` `Cache size of ${archiveFileSize} bytes is over the 200MB limit, not saving cache.`
); );
return; return;
} }
const stream = fs.createReadStream(archivePath); const stream = fs.createReadStream(archivePath);
await cacheHttpClient.saveCache(stream, primaryKey); await cacheHttpClient.saveCache(stream, primaryKey);
try {
core.info("Cache Checksum:");
await exec(`md5sum`, [`${archivePath}`]);
} catch (error) {
core.debug(`Failed to checkum with ${error}`);
}
} catch (error) { } catch (error) {
core.warning(error.message); core.warning(error.message);
} }

View File

@ -72,7 +72,7 @@ export function resolvePath(filePath: string): string {
if (filePath[0] === "~") { if (filePath[0] === "~") {
const home = os.homedir(); const home = os.homedir();
if (!home) { if (!home) {
throw new Error("Unable to resolve `~` to HOME"); throw new Error("Unable to resole `~` to HOME");
} }
return path.join(home, filePath.slice(1)); return path.join(home, filePath.slice(1));
} }