namespacelabs/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.
The action works by linking the listed directories to directories in the mounted cache volume (using bind-mounts on Linux and symbolic links on macOS). The content written to the cached directories will be transparently stored on the mounted cache volume. This way the action does not need to spend time explicitly downloading and uploading cache content to remote locations.
Prerequisites
In order to use nscloud-cache-action, you need to ensure that a cache volume is attached to the GitHub Actions job.
Check out the Cache Volumes guide
for details.
It is important to run the cache action after the checkout action in the workflow sequence. Checkout action automatically wipes the workspace directory, so it would remove the cached content and prevent new content from being stored on the cache volume.
Examples
name: Tests
jobs:
tests:
runs-on: namespace-profile-my-profile
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v6
with:
cache: false # Skip remote GitHub caching
- name: Set up Go cache
uses: namespacelabs/nscloud-cache-action@v1
with:
cache: go
- name: Go tests
run: go test ./...Options
cache
string A list caching modes to enable. Currently supported languages/frameworks are:
Cache mode apt caches downloaded APT packages on the attached Cache Volume.
The apt-config executable must be available before namespacelabs/nscloud-cache-action is called.
- name: Set up apt cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: apt
Cache mode bun caches downloaded packages on the attached Cache Volume.
To enable bun cache mode, the executable must be available before namespacelabs/nscloud-cache-action is called.
When using oven-sh/setup-bun, no additional configuration is needed:
- name: Setup Bunuses: oven-sh/setup-bun@v2
Now you can cache bun packages across runs.
- name: Set up bun cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: bun
Cache mode cocoapods caches CocoaPods cache on the attached Cache Volume.
This mode caches ./Pods and ~/Library/Caches/CocoaPods.
- name: Set up cocoapods cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: cocoapods
Cache mode composer caches downloaded packages which Composer retains in a global Cache, on the attached Cache Volume.
To enable composer cache mode, the executable must be available before namespacelabs/nscloud-cache-action is called.
When using shivammathur/setup-php, no additional configuration is needed:
- name: Setup PHPuses: shivammathur/setup-php@v2with:php-version: '8.3'
Composer stores zip archives of downloaded PHP packages in a global cache. The cache action retains this global cache on the attached Cache Volume.
- name: Set up composer cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: composer
Cache mode deno caches downloaded packages on the attached Cache Volume.
To enable deno cache mode, the executable must be available before namespacelabs/nscloud-cache-action is called.
When using denoland/setup-deno, disable its built-in cache:
- name: Setup Denouses: denoland/setup-deno@v2with:cache: false
Now you can cache Deno packages across runs. The cache action stores the Deno cache directory (from deno info --json) on the attached Cache Volume.
- name: Set up deno cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: deno
Cache mode go caches Go modules and Go build artifacts on the attached Cache Volume.
To enable go cache mode, the executable must be available before namespacelabs/nscloud-cache-action is called.
When using actions/setup-go, disable its built-in cache:
- name: Setup Gouses: actions/setup-go@v5with:go-version-file: go.modcache: false
Now you can cache Go modules and build artifacts across runs. The cache action stores GOCACHE and GOMODCACHE on the attached Cache Volume.
- name: Set up go cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: go
Cache mode golangci-lint caches analysis results on the attached Cache Volume. Combine this with the go cache mode, as GolangCI-Lint will make use of the Go build cache to speed up things further.
To enable golangci-lint cache mode, the golangci-lint executable must be available before namespacelabs/nscloud-cache-action is called.
Typically you achieve this by first installing golangci-lint:
- name: Setup golangci-lintuses: golangci/golangci-lint-action@v8with:version: 2.8install-only: trueskip-cache: true
Next, setup the cache:
- name: Set up golangci-lint cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: golangci-lint
To finish you can either call golangci-lint manually, or through the action (skipping the install step):
- name: Setup golangci-lintuses: golangci/golangci-lint-action@v8with:version: 2.8install-mode: none
Cache mode gradle caches Gradle build artifacts on the attached Cache Volume.
When using actions/setup-java, disable its built-in cache:
- name: Setup Javauses: actions/setup-java@v5with:distribution: temurinjava-version: '21'cache: ''
Now you can cache Gradle build artifacts across runs. The cache action stores ~/.gradle/caches and ~/.gradle/wrapper on the attached Cache Volume.
- name: Set up gradle cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: gradle
Cache mode brew retains Homebrew artifact downloads across runs.
The brew executable must be available before namespacelabs/nscloud-cache-action is called.
This is available by default on macOS runners.
- name: Set up brew cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: brew
Cache mode maven caches Maven artifacts on the attached Cache Volume.
When using actions/setup-java, disable its built-in cache:
- name: Setup Javauses: actions/setup-java@v5with:distribution: temurinjava-version: '21'cache: ''
Now you can cache Maven artifacts across runs. The cache action stores ~/.m2/repository on the attached Cache Volume, which contains remote downloads and temporary build artifacts.
- name: Set up maven cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: maven
Cache mode mise caches downloaded tools on the attached Cache Volume.
First setup the cache before installing Mise:
- name: Set up mise cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: mise
Now setup Mise and install packages, making sure to disable its built-in cache:
- name: Setup miseuses: jdx/mise-action@v2with:cache: false
Cache mode nix caches the Nix store and user cache on the attached Cache Volume.
First setup the cache before installing Nix:
- name: Set up nix cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: nix
Now install Nix. The /nix store will already be mounted from the cache:
- name: Install Nixuses: cachix/install-nix-action@v31with:extra_nix_config: |access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}system-features = kvm nixos-test
Cache mode playwright stores the downloaded browsers on the attached Cache Volume.
The cache action detects the browser cache directory automatically based on the platform.
- name: Set up playwright cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: playwright
See the example repo for a working example.
Cache mode pnpm caches downloaded packages on the attached Cache Volume.
To enable pnpm cache mode, the executable must be available before namespacelabs/nscloud-cache-action is called.
When using pnpm/action-setup, no additional configuration is needed:
- name: Setup pnpmuses: pnpm/action-setup@v4
Now you can cache pnpm packages across runs.
- name: Set up pnpm cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: pnpm
Cache mode poetry caches downloaded packages on the attached Cache Volume.
To enable poetry cache mode, the executable must be available before namespacelabs/nscloud-cache-action is called.
One way of achieving that is via pipx:
- name: Install Poetryrun: pipx install poetry
Now you can cache Poetry packages across runs.
- name: Set up poetry cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: poetry
Cache mode python retains the pip cache directory across runs.
The pip executable is available by default on GitHub runners.
- name: Set up python cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: python
Cache mode ruby caches Bundler packages on the attached Cache Volume.
When using ruby/setup-ruby, disable its built-in cache:
- name: Setup Rubyuses: ruby/setup-ruby@v1with:ruby-version: '3.2'bundler-cache: false
Now you can cache Bundler packages across runs.
- name: Set up ruby cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: ruby
Cache mode rust caches Cargo registry, git dependencies, and build artifacts on the attached Cache Volume.
When using actions-rust-lang/setup-rust-toolchain, disable its built-in cache:
- name: Setup Rustuses: actions-rust-lang/setup-rust-toolchain@v1with:cache: false
Now you can cache Rust packages across runs.
- name: Set up rust cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: rust
Cache mode swiftpm caches Swift Package Manager build artifacts and module cache on the attached Cache Volume.
The cache action stores ./.build, ~/Library/Caches/org.swift.swiftpm, and ~/Library/org.swift.swiftpm on the attached Cache Volume.
- name: Set up swiftpm cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: swiftpm
Cache mode uv caches downloaded packages on the attached Cache Volume.
To enable uv cache mode, the executable must be available before namespacelabs/nscloud-cache-action is called.
When using astral-sh/setup-uv, disable its built-in cache:
- name: Setup uvuses: astral-sh/setup-uv@v5with:enable-cache: false
Now you can cache uv packages across runs.
- name: Set up uv cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: uv
Cache mode xcode caches Xcode's DerivedData and Compilation Cache on the attached Cache Volume.
The xcodebuild executable is available by default on macOS runners. This cache mode also enables Xcode's Compilation Cache feature.
- name: Set up xcode cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: xcode
To enable yarn cache mode, the executable must be available before namespacelabs/nscloud-cache-action is called.
You can enable Yarn using Corepack (included with Node.js), making sure to not set a cache value:
- name: Setup Nodeuses: actions/setup-node@v4with:node-version: '22'cache: ''- name: Enable Corepackrun: corepack enable
Yarn stores every package in a global cache. The cache action retains this global cache on the attached Cache Volume. The cache location is detected automatically based on Yarn version (v1 uses yarn cache dir, v2+ uses yarn config get cacheFolder).
- name: Set up yarn cacheuses: namespacelabs/nscloud-cache-action@v1with:cache: yarn
You can enable multiple caching modes and can also add additional paths to the cache using path.
- name: Set up Go and Rust cache
uses: namespacelabs/nscloud-cache-action@v1
with:
cache: |
go
rustpath
string A list of files, directories, to cache and restore. ~ is resolved to $HOME. Can be used in concert with cache.
- name: Set up Go cache
uses: namespacelabs/nscloud-cache-action@v1
with:
path: |
/home/runner/.cache/go-build
/home/runner/go/pkg/modNote: Contents of ${{ runner.temp }} cannot be cached as this directory is emptied at the beginning and end of each job.
fail-on-cache-miss
boolean If enabled, fail the workflow if the path is not found on the cache volume.
Advanced: Running GitHub Jobs in Containers
We recommend using a separate profile for your workflows that run in containers.
GitHub Actions run as user runner by default. Running in a container can change the user. Sharing caches from different users may lead to permission errors when accessing the cache.
When using containers to run GitHub Jobs, extra configuration is required to make the cache action work correctly.
- The Cache Volume path
/cachemust be mounted into the container. - The env var
NSC_CACHE_PATHmust be set. - Container needs to have
SYS_ADMINcapability, so that the cache action has permissions to call themountcommand. - The
sudo,mkdirandchownbinaries must be available in the container image, or must be installed.
This action relies on specific properties of the environment and may require tuning to work with images that significantly diverge from Ubuntu. Please reach out to us at support@namespace.so for assistance.
See the following snippet for a working example.
name: NPM tests on Playwright
jobs:
tests:
runs-on: namespace-profile-my-profile-for-containers
container:
image: mcr.microsoft.com/playwright:v1.39.0
env:
NSC_CACHE_PATH: ${{ env.NSC_CACHE_PATH }} # env.NSC_CACHE_PATH contains the path to Cache Volume directory, that is `/cache`.
volumes:
- /cache:/cache # Where the Cache Volume is mounted.
options: --cap-add=SYS_ADMIN # Required to by nscloud-cache-action to call `mount`.
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install sudo
run: |
apt-get update -y && apt-get install -y sudo
- name: Setup PNPM cache
uses: namespacelabs/nscloud-cache-action@v1
with:
cache: pnpm
- name: Install dependencies and run tests
run: |
pnpm install
pnpm run test