Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
WIP: Bootstrap action-local-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaric committed Nov 27, 2020
0 parents commit 943244b
Show file tree
Hide file tree
Showing 21 changed files with 9,511 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: https://editorconfig.org/

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
51 changes: 51 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": [
"plugin:@typescript-eslint/recommended",
"@stefanmaric/eslint-config-munchies-base",
"@stefanmaric/eslint-config-munchies-node",
"@stefanmaric/eslint-config-munchies-modern",
"@stefanmaric/eslint-config-munchies-modules",
"@stefanmaric/eslint-config-munchies-gourmet",
"plugin:import/typescript"
],
"env": {
"es6": true,
"node": true
},
"overrides": [
{
"env": {
"jest": true,
"jest/globals": true
},
"extends": ["plugin:jest/recommended"],
"files": ["__tests__/**/*"]
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"project": "./tsconfig.json"
},
"root": true,
"rules": {
"@typescript-eslint/member-delimiter-style": ["error", {
"multiline": {
"delimiter": "none",
"requireLast": false
},
"singleline": {
"delimiter": "semi",
"requireLast": false
}
}],
"node/no-unsupported-features/es-syntax": "off"
},
"settings": {
"node": {
"tryExtensions": [".js", ".json", ".ts"]
}
}
}
98 changes: 98 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Dependency directory
node_modules

# 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/

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
__tests__/runner/*
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "always",
"printWidth": 100,
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2020 Masterworks

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.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Local Cache Github Action

This github action allows you to save and restore files across job runs directly in the runner's file system.

It is intended to be used with runners with persisted storage. Don't use this action if you're using Github-hosted runners or self-hosted runners in ephemeral instances (like docker containers that are launched on demand when a workflow starts and are terminated when the job finishes).


## Usage

```yaml
# .github/workflows/my-workflow.yml
jobs:
my_job:

steps:
- uses: actions/checkout@v2

- name: Local cache for API dependencies
id: api-cache
uses: MasterworksIO/action-local-cache@main
with:
path: './api/node_modules/'
key: 'api-dependencies-v1'

- name: Install dependencies
run: cd api/ && npm install
if: steps.api-cache.outputs.cache-hit != 'true'

- name: Do your stuff
run: npm run build
```
The `key` param is optional and you can use it to invalidate cache.

# How it works

The first time `action-local-cache` is used in a runner it will take the given path and create a folder structure inside the `$RUNNER_TOOL_CACHE` dir (usually `_work/_tool` inside the runner's workspace), prefixing the user/org name, repo name, and key.

For example, when running the usage example above inside a workflow for the `MasterworksIO/product` repo, this empty folder will be created:

```shell
~/runner/_work/_tool/MasterworksIO/product/api-dependencies-v1/
```

Since there's no `api/node_modules/` dir inside, the restore step is skipped and the `cache-hit` output variable will be set to `false`; because of that, the next step which install the dependencies will run.

After the job is successfully completed, `action-local-cache` will take the `api/node_modules` dir generated by the install dependencies step and move it to the previously created dir structure before the runner workspace is wiped.

On a next run under the same runner instance, the cache will be moved back to the working directory and the `cache-output` variable will be set to `true`.

After all steps complete the folder will be moved back to the cache dir and so on. Since it is using the filesystem move syscalls, cache saving and restoration is instant.

# LICENSE

MIT, see [LICENSE](./LICENSE)
3 changes: 3 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test('test runs', () => {
console.log('TODO')
})
17 changes: 17 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'local-cache'
description: "A Github Action to save and restore files across job runs directly in the runner's file system"
inputs:
key:
description: 'An explicit key for versioning the cache'
required: false
path:
description: 'The file or folder to be cached'
required: true
outputs:
cache-hit:
description: 'A boolean value to indicate if cache was found and restored'
runs:
using: 'node12'
main: 'dist/main/index.js'
post: 'dist/post/index.js'
post-if: success()
Loading

0 comments on commit 943244b

Please sign in to comment.