Code Monkey home page Code Monkey logo

action-local-cache's Introduction

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

# .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@2
        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.

Caching strategy

Define how you want your cache to be used. move is the default strategy:

Usage Description Observations
strategy: move Moves cache on job start, moves back on job end Uses the filesystem move syscalls, cache saving and restoration is instant. Does not work across disks/remote shares.
strategy: copy Recursiverly copies cache on job start, refreshes cache on job end Works across disks/remote shares.
strategy: copy-immutable Recursiverly copies cache on job start, does not refresh cache on job end Works across disks/remote shares. Faster to use if the contents will never change (e.g. installing node dependencies)

Refer to push.yaml for examples of how to use the above strategies.

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:

~/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/copy 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/copied back to the working directory and the cache-output variable will be set to true.

After all steps complete the folder will be moved/copied back to the cache dir and so on.

LICENSE

MIT, see LICENSE

action-local-cache's People

Contributors

stefanmaric avatar onaips avatar liasece avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.