Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit
- Loading branch information
Josh Gross
committed
Oct 30, 2019
1 parent
551cf17
commit 37c4544
Showing
20 changed files
with
6,242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Test Cache Action | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- run: npm ci | ||
|
||
- name: Prettier Format Check | ||
run: npm run format-check | ||
|
||
- name: Build & Test | ||
run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
__tests__/runner/* | ||
|
||
# comment out in distribution branches | ||
dist/ | ||
|
||
node_modules/ | ||
lib/ | ||
|
||
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# next.js build output | ||
.next | ||
|
||
# nuxt.js build output | ||
.nuxt | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"printWidth": 80, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"trailingComma": "none", | ||
"bracketSpacing": true, | ||
"arrowParens": "avoid", | ||
"parser": "typescript" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Jest Test", | ||
"program": "${workspaceFolder}/node_modules/jest/bin/jest", | ||
"args": ["--runInBand", "--config=${workspaceFolder}/jest.config.js"], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## Contributing | ||
|
||
[fork]: https://github.com/actions/cache/fork | ||
[pr]: https://github.com/actions/cache/compare | ||
[style]: https://github.com/styleguide/js | ||
[code-of-conduct]: CODE_OF_CONDUCT.md | ||
|
||
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. | ||
|
||
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE). | ||
|
||
Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms. | ||
|
||
## Submitting a pull request | ||
|
||
1. [Fork][fork] and clone the repository | ||
2. Configure and install the dependencies: `npm install` | ||
3. Make sure the tests pass on your machine: `npm run test` | ||
4. Create a new branch: `git checkout -b my-branch-name` | ||
5. Make your change, add tests, and make sure the tests still pass | ||
6. Push to your fork and [submit a pull request][pr] | ||
7. Pat your self on the back and wait for your pull request to be reviewed and merged. | ||
|
||
Here are a few things you can do that will increase the likelihood of your pull request being accepted: | ||
|
||
- Write tests. | ||
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. | ||
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). | ||
|
||
## Resources | ||
|
||
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) | ||
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) | ||
- [GitHub Help](https://help.github.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 GitHub, Inc. and contributors | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,133 @@ | ||
# cache | ||
|
||
This GitHub Action allows caching dependencies and build outputs to improve workflow execution time. | ||
|
||
## Usage | ||
|
||
### Pre-requisites | ||
Create a workflow `.yml` file in your repositories `.github/workflows` directory. An [example workflow](#example-workflow) is available below. For more information, reference the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file). | ||
|
||
### Inputs | ||
|
||
* `path` - A directory to store and save the cache | ||
* `key` - An explicit key for restoring and saving the cache | ||
* `restore-keys` - An ordered list of keys to use for restoring the cache if no cache hit occurred for key | ||
|
||
### Outputs | ||
|
||
* `cache-hit` - A boolean value to indicate an exact match was found for the key | ||
|
||
> See [Skipping steps based on cache-hit](#Skipping-steps-based-on-cache-hit) for info on using this output | ||
### Example workflow | ||
|
||
```yaml | ||
name: Example Caching with npm | ||
|
||
on: push | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Cache node_modules | ||
uses: actions/cache@preview | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-node | ||
|
||
- name: Install Dependencies | ||
run: npm install | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
- name: Test | ||
run: npm run test | ||
``` | ||
## Ecosystem Examples | ||
|
||
### 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 | ||
|
||
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 | ||
|
||
Using the `cache-hit` output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. | ||
|
||
Example: | ||
```yaml | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- uses: actions/cache@preview | ||
id: cache | ||
with: | ||
path: path/to/dependencies | ||
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles')}} | ||
|
||
- name: Install Dependencies | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
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`) | ||
## 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. | ||
|
||
## License | ||
The scripts and documentation in this project are released under the [MIT License](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as core from "@actions/core"; | ||
|
||
import { Inputs } from "../src/constants"; | ||
import run from "../src/restore"; | ||
import * as testUtils from "../src/utils/testUtils"; | ||
|
||
test("restore with no path", async () => { | ||
const failedMock = jest.spyOn(core, "setFailed"); | ||
await run(); | ||
expect(failedMock).toHaveBeenCalledWith( | ||
"Input required and not supplied: path" | ||
); | ||
}); | ||
|
||
test("restore with no key", async () => { | ||
testUtils.setInput(Inputs.Path, "node_modules"); | ||
const failedMock = jest.spyOn(core, "setFailed"); | ||
await run(); | ||
expect(failedMock).toHaveBeenCalledWith( | ||
"Input required and not supplied: key" | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: 'Cache' | ||
description: 'Cache dependencies and build outputs to improve workflow execution time' | ||
author: 'GitHub' | ||
inputs: | ||
path: | ||
description: 'A directory to store and save the cache' | ||
required: true | ||
key: | ||
description: 'An explicit key for restoring and saving the cache' | ||
required: true | ||
restore-keys: | ||
description: 'An ordered list of keys to use for restoring the cache if no cache hit occurred for key' | ||
required: false | ||
outputs: | ||
cache-hit: | ||
description: 'A boolean value to indicate an exact match was found for the primary key' | ||
runs: | ||
using: 'node12' | ||
main: 'dist/restore/index.js' | ||
post: 'dist/save/index.js' | ||
post-if: 'success()' | ||
branding: | ||
icon: 'archive' | ||
color: 'gray-dark' |
Oops, something went wrong.