Giter VIP home page Giter VIP 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/[email protected]
        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:

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

action-local-cache's People

Contributors

stefanmaric 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.