logo

nscloud-cache-action

Namespace platform provides Cache Volumes feature that allows workflows to share data across invocations.

The action performs necessary wiring to store cacheable workflow data on the attached cache volume.

Howto

  1. Attach a cache volume to the job by adding runner tags to the job definition:

    jobs:
      my-job:
        runs-on:
          - nscloud-{runner profile}-with-cache
          - nscloud-cache-tag-{cache volume tag}
          - nscloud-cache-size-{cache volume size}

    See cache volumes guide for details.

  2. Add a step to mark directories with cacheable data to be stored on the cache volume:

    steps:
      - uses: namespacelabs/nscloud-cache-action@v0
        with:
          use-cache-volume: true # required
          path: { local path to be cached }

Example

name: Tests
jobs:
  tests:
    runs-on:
      - nscloud-ubuntu-22.04-amd64-8x16-with-cache
      - nscloud-cache-size-50gb
      - nscloud-cache-tag-gha-demo-remix
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
 
      - name: Setup npm cache
        uses: namespacelabs/nscloud-cache-action@v0
        with:
          path: |
            ~/.npm
            ./node_modules
          use-cache-volume: true
 
      - name: Install dependencies
        run: npm install
 
      - name: NPM tests
        run: npm run test

Options

path

Required string. A list of files, directories, and wildcard patterns to cache and restore.

use-cache-volume

boolean. If set to true, use the Namespace runner's cache volume to store the cache. If set to false (the default) the action runs in GitHub Action compatibility mode (deprecated).

GitHub Cache Action Compatibility Mode

This mode is DEPRECATED. It is still maintained for the existing customers but will not be enabled for new users.

namespacelabs/nscloud-cache-action can be also used as a drop-in replacement for GitHub cache action that offers improved performance and reliability.

In this mode it does not use Namespace cache volumes feature, but still addresses the recurring problems of downloads and uploads stalling indefinitely.

Prerequisites

In order to use nscloud-cache-action, you need to have access to Namespace. Add a namespacelabs/nscloud-setup step to authenticate with Namespace.

Example

jobs:
  build:
    name: Build Widgets
    runs-on: nscloud
    # These permissions are needed to interact with GitHub's OIDC Token endpoint.
    permissions:
      id-token: write
      contents: read
    steps:
      - uses: actions/checkout@v3
      - uses: namespacelabs/nscloud-setup@v0
 
      - name: Save build output cache
        id: cache-output
        uses: namespacelabs/nscloud-cache-action@v0
        with:
          key: build-output
          path: ./out
 
      - name: Perform expensive build
        run: ./build.sh
        if: steps.cache-output.outputs.cache-hit != 'true'
 
      - name: Observe cached files
        run: ls -l ./out