mirror of
https://code.forgejo.org/actions/cache.git
synced 2024-12-27 04:55:55 +00:00
Preview v0.0.2 Release (#50)
* Create CODE_OF_CONDUCT.md * Update workflow (#1) * Run workflow on linux, mac, and windows * Add status badge * Use npm install instead * Bump typescript version * Use node 12.x * Add Ruby Gem example (#4) * Add Cocoapods example (#5) * Add Carthage example (#10) * Move examples to their own page (#13) * Minor typo in README (#15) from `steps.[ID].outupts.cache-hit` to `steps.[ID].outputs.cache-hit` * Update README.md * Prevent commands from executing during tests (#21) * Prevent commands from executing during tests * Add newline at end of file * Drop all commands from output * Link to NuGet lock files documentation (#20) * Add trailing dash to Maven fallback key (#19) * Fix README.md (#25) `restore-keys` had incorrect indentation. * Exclude documentation from CI tests (#28) * Ignore all .md files * Add note about time-based eviction to README (#30) * Fix typo in error message (#29) * Time based eviction interval is 1 week (#34) * Remove cache checksum debug - close #24 (#26) * Remove cache checksum debug - close #24 * Remove cache checksum debug on save * Fix formatting * Add Go modules example (#18) * Add Go modules example * Fix TOC * Fix repo name in contact email (#41) * Add Elixir Mix example (#42) * Add Elixir Mix example * Fix typo * Add cargo example for Rust project (#8) * Add cargo example * Add hash of Cargo.lock to keys of caches * Move Rust example to examples.md * Stop warning when cache is not found (#40) The cache not being found is a common situation so very visible warning is a little too much. * Bump package version * Release v0.0.2
This commit is contained in:
parent
e7ad80454a
commit
0da99ad140
13 changed files with 290 additions and 109 deletions
15
.github/workflows/workflow.yml
vendored
15
.github/workflows/workflow.yml
vendored
|
@ -1,16 +1,27 @@
|
||||||
name: Test Cache Action
|
name: Tests
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
name: Test on ${{ matrix.os }}
|
||||||
|
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
|
||||||
|
|
76
CODE_OF_CONDUCT.md
Normal file
76
CODE_OF_CONDUCT.md
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
# 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
|
63
README.md
63
README.md
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
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"></a>
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Pre-requisites
|
### Pre-requisites
|
||||||
|
@ -33,11 +35,13 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
- name: Cache node_modules
|
- name: Cache node modules
|
||||||
uses: actions/cache@preview
|
uses: actions/cache@preview
|
||||||
with:
|
with:
|
||||||
path: node_modules
|
path: node_modules
|
||||||
key: ${{ runner.os }}-node
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm install
|
run: npm install
|
||||||
|
@ -48,61 +52,14 @@ jobs:
|
||||||
- name: Test
|
- name: Test
|
||||||
run: npm run test
|
run: npm run test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ecosystem Examples
|
## Ecosystem Examples
|
||||||
|
|
||||||
### Node - npm
|
See [Examples](examples.md)
|
||||||
|
|
||||||
```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 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.
|
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. Caches that are not accessed within the last week will also be evicted.
|
||||||
|
|
||||||
## Skipping steps based on cache-hit
|
## Skipping steps based on cache-hit
|
||||||
|
|
||||||
|
@ -124,7 +81,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].outupts.cache-hit`)
|
> Note: The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.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.
|
||||||
|
|
26
dist/restore/index.js
vendored
26
dist/restore/index.js
vendored
|
@ -1475,10 +1475,11 @@ 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1506,7 +1507,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) {
|
||||||
throw new Error(`Cache not found for input keys: ${JSON.stringify(keys)}.`);
|
return null;
|
||||||
}
|
}
|
||||||
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}`);
|
||||||
|
@ -2120,10 +2121,11 @@ 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -2200,7 +2202,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 resole `~` to HOME");
|
throw new Error("Unable to resolve `~` to HOME");
|
||||||
}
|
}
|
||||||
return path.join(home, filePath.slice(1));
|
return path.join(home, filePath.slice(1));
|
||||||
}
|
}
|
||||||
|
@ -2938,10 +2940,11 @@ 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -2989,9 +2992,13 @@ function run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
const cacheEntry = yield cacheHttpClient.getCacheEntry(keys);
|
||||||
|
if (!cacheEntry) {
|
||||||
|
core.info(`Cache not found for input keys: ${JSON.stringify(keys)}.`);
|
||||||
|
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
|
||||||
|
@ -3015,13 +3022,6 @@ function run() {
|
||||||
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);
|
||||||
|
|
20
dist/save/index.js
vendored
20
dist/save/index.js
vendored
|
@ -1475,10 +1475,11 @@ 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1506,7 +1507,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) {
|
||||||
throw new Error(`Cache not found for input keys: ${JSON.stringify(keys)}.`);
|
return null;
|
||||||
}
|
}
|
||||||
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}`);
|
||||||
|
@ -2120,10 +2121,11 @@ 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -2200,7 +2202,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 resole `~` to HOME");
|
throw new Error("Unable to resolve `~` to HOME");
|
||||||
}
|
}
|
||||||
return path.join(home, filePath.slice(1));
|
return path.join(home, filePath.slice(1));
|
||||||
}
|
}
|
||||||
|
@ -2832,10 +2834,11 @@ 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -2895,13 +2898,6 @@ function run() {
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
142
examples.md
Normal file
142
examples.md
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
# Examples
|
||||||
|
|
||||||
|
- [Node - npm](#node---npm)
|
||||||
|
- [Node - Yarn](#node---yarn)
|
||||||
|
- [C# - Nuget](#c---nuget)
|
||||||
|
- [Java - Gradle](#java---gradle)
|
||||||
|
- [Java - Maven](#java---maven)
|
||||||
|
- [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
|
||||||
|
- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods)
|
||||||
|
- [Ruby - Gem](#ruby---gem)
|
||||||
|
- [Go - Modules](#go---modules)
|
||||||
|
- [Elixir - Mix](#elixir---mix)
|
||||||
|
- [Rust - Cargo](#rust---cargo)
|
||||||
|
|
||||||
|
## Node - npm
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: node_modules
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ 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
|
||||||
|
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
|
||||||
|
```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: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-gradle-
|
||||||
|
```
|
||||||
|
|
||||||
|
## Java - Maven
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: ~/.m2/repository
|
||||||
|
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-maven-
|
||||||
|
```
|
||||||
|
|
||||||
|
## Swift, Objective-C - Carthage
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: Carthage
|
||||||
|
key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-carthage-
|
||||||
|
```
|
||||||
|
|
||||||
|
## Swift, Objective-C - CocoaPods
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: Pods
|
||||||
|
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pods-
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ruby - Gem
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: vendor/bundle
|
||||||
|
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-gem-
|
||||||
|
```
|
||||||
|
|
||||||
|
## Go - Modules
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
```
|
||||||
|
|
||||||
|
## Elixir - Mix
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: deps
|
||||||
|
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-mix-
|
||||||
|
```
|
||||||
|
|
||||||
|
## Rust - Cargo
|
||||||
|
|
||||||
|
```
|
||||||
|
- name: Cache cargo registry
|
||||||
|
uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: ~/.cargo/registry
|
||||||
|
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
- name: Cache cargo index
|
||||||
|
uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: ~/.cargo/git
|
||||||
|
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
- name: Cache cargo build
|
||||||
|
uses: actions/cache@preview
|
||||||
|
with:
|
||||||
|
path: target
|
||||||
|
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
```
|
|
@ -9,3 +9,12 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -4975,9 +4975,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"version": "3.5.3",
|
"version": "3.6.4",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.4.tgz",
|
||||||
"integrity": "sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==",
|
"integrity": "sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"uglify-js": {
|
"uglify-js": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"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.5.1"
|
"typescript": "^3.6.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { ArtifactCacheEntry } from "./contracts";
|
||||||
|
|
||||||
export async function getCacheEntry(
|
export async function getCacheEntry(
|
||||||
keys: string[]
|
keys: string[]
|
||||||
): Promise<ArtifactCacheEntry> {
|
): Promise<ArtifactCacheEntry | null> {
|
||||||
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,9 +28,7 @@ export async function getCacheEntry(
|
||||||
getRequestOptions()
|
getRequestOptions()
|
||||||
);
|
);
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
throw new Error(
|
return null;
|
||||||
`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}`);
|
||||||
|
|
|
@ -49,14 +49,20 @@ async function run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
|
||||||
|
if (!cacheEntry) {
|
||||||
|
core.info(
|
||||||
|
`Cache not found for input keys: ${JSON.stringify(keys)}.`
|
||||||
|
);
|
||||||
|
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);
|
||||||
|
|
||||||
|
@ -94,13 +100,6 @@ async function run() {
|
||||||
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);
|
||||||
|
|
|
@ -66,13 +66,6 @@ async function run() {
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 resole `~` to HOME");
|
throw new Error("Unable to resolve `~` to HOME");
|
||||||
}
|
}
|
||||||
return path.join(home, filePath.slice(1));
|
return path.join(home, filePath.slice(1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue