Installs ucacher (Earthly Universal Caching) in a GHA job
98
8 commits
updated Dec 12, 2024
This action installs Earthly ucacher.
Read our new blog post about ucacher here
ucacherucacher is a CLI tool that tracks which files are accessed by commands, skips unnecessary executions, and restores cached outputs when possible, resulting in significantly reduced execution times.
It brings:
ucacherAdd ucacher to your GitHub Actions workflow:
steps:
- uses: earthly/setup-ucacher@main
...
To cache a command, simply wrap it with ucacher:
steps:
...
- run: ucacher <your_command>
ucacher detects if the command’s output is unaffected by files changed. If so, it skips execution and restores the cached output files instantly.ucacher worksucacher utilizes ptrace to monitor files read (inputs) and written (outputs) by a command. When the command completes successfully, it uploads output files to persistent storage (e.g., GitHub Actions cache) along with some build metadata, in particular the hashes of all input files at the time they were read.
On subsequent runs, ucacher checks for matching initial conditions (input files content, arguments, environment variables, system architecture, etc.). If they match, it skips execution and restores the cached output files instead.
Suppose the following steps on a node-js project, that run the unit tests of the client and server application components:
steps:
...
- uses: earthly/setup-ucacher@main
...
- run: ucacher yarn test --client
- run: ucacher yarn test --server
and the workflow already run for that branch. Now, if a change in server-impl.js is pushed, then:
ucacher yarn test --client would return the output from a compatible past execution right away, since that file is not used in the client tests.ucacher yarn test --server would execute or return a cached result, depending on whether a compatible past execution is found (command already run for that file contents).The reason why ucacher determines that this file isn’t used is indirect, not by explicitly checking it, but by finding a previous execution whose input file contents that match the current filesystem state. This indicates that this file (or potentially other files) is irrelevant to this specific command instance.
To improve caching performance, certain files and environment variables can be ignored so that changes to them won’t prevent cache hits.
.ucacherignorePlace a .ucacherignore file in the root directory to define file patterns to ignore. Each line is a glob pattern that ucacher will use to filter out files.
.git/**/*
node_modules/**/*
/tmp/**/*
.ucacherignore.envDefine environment variable patterns to ignore in .ucacherignore.env:
GITHUB_TOKEN
ACTIONS_RUNTIME_TOKEN
GITHUB_PATH
GITHUB_OUTPUT
GITHUB_ENV
Complete example here: .ucacherignore.env
This prevents environment changes that don’t impact command output from invalidating the cache.
actions/cache is the official GitHub Action designed to cache dependencies and build outputs in GitHub Actions workflows. Here it is how they compare to each other:
| Feature | actions/cache | ucacher |
|---|---|---|
| Output restore | File-based | Command-based |
| Skipping | Manual via if + cache-hit | Automatic |
| Keying | Manual, broad scope | Automatic, only relevant files |
| Persistence | GitHub cache | GitHub cache, S3, Minio (upcoming) |
| Scope | Step | Command |
ucacher offers a more automated, precise, and efficient alternative to actions/cache in GitHub Actions by tracking file-level dependencies and automating caching and skipping at the command level.
Unlike actions/cache, which requires manual setup with defined paths and keys, ucacher eliminates human errors and dynamically determines when commands should be skipped or re-executed based on actual file changes.
This results in finer-grain caching, better resource optimization, and significant time savings, especially in complex workflows like monorepos or matrix builds, where broad cache keys in actions/cache often lead to inefficiencies like unnecessarily invalidating unrelated steps, redundant execution of unchanged tasks and manual configuration errors.
github-tokenThis token is used by ucacher to overwrite the Github Actions cache entry where the build metadata is stored. It requires write permissions for the actions scope in the GitHub REST API.
If omitted, the GITHUB_TOKEN of the job is used. This token should have enough permission by default. If that is not case, please refer to the official GHA documentation for guidance on modifying its permissions.
yarn test) into smaller shards to maximize cache hit chances when only a subset of source files change.ucacher to track inputs and outputs accurately..ucacherignore and .ucacherignore.env to exclude irrelevant files and variables from tracking.amd64.ucacher is free to use; it may become open-source in the future.ucacher collects limited runtime metrics for maintenance, such as repository and organization names, commit author, and ucacher-specific errors. Source code or environment data is never collected.ucacher?(in chronological order)
Using
ucacher? Send a PR adding your repo at the end of the previous list
Please give us feedback to keep improving it by opening an issue in this repo. In particular, we'd like to know:
ucacher missing some file accesses?Thanks!
8 commits
Installs ucacher (Earthly Universal Caching) in a GHA job
98
8 commits
updated Dec 12, 2024
This action installs Earthly ucacher.
Read our new blog post about ucacher here
ucacherucacher is a CLI tool that tracks which files are accessed by commands, skips unnecessary executions, and restores cached outputs when possible, resulting in significantly reduced execution times.
It brings:
ucacherAdd ucacher to your GitHub Actions workflow:
steps:
- uses: earthly/setup-ucacher@main
...
To cache a command, simply wrap it with ucacher:
steps:
...
- run: ucacher <your_command>
ucacher detects if the command’s output is unaffected by files changed. If so, it skips execution and restores the cached output files instantly.ucacher worksucacher utilizes ptrace to monitor files read (inputs) and written (outputs) by a command. When the command completes successfully, it uploads output files to persistent storage (e.g., GitHub Actions cache) along with some build metadata, in particular the hashes of all input files at the time they were read.
On subsequent runs, ucacher checks for matching initial conditions (input files content, arguments, environment variables, system architecture, etc.). If they match, it skips execution and restores the cached output files instead.
Suppose the following steps on a node-js project, that run the unit tests of the client and server application components:
steps:
...
- uses: earthly/setup-ucacher@main
...
- run: ucacher yarn test --client
- run: ucacher yarn test --server
and the workflow already run for that branch. Now, if a change in server-impl.js is pushed, then:
ucacher yarn test --client would return the output from a compatible past execution right away, since that file is not used in the client tests.ucacher yarn test --server would execute or return a cached result, depending on whether a compatible past execution is found (command already run for that file contents).The reason why ucacher determines that this file isn’t used is indirect, not by explicitly checking it, but by finding a previous execution whose input file contents that match the current filesystem state. This indicates that this file (or potentially other files) is irrelevant to this specific command instance.
To improve caching performance, certain files and environment variables can be ignored so that changes to them won’t prevent cache hits.
.ucacherignorePlace a .ucacherignore file in the root directory to define file patterns to ignore. Each line is a glob pattern that ucacher will use to filter out files.
.git/**/*
node_modules/**/*
/tmp/**/*
.ucacherignore.envDefine environment variable patterns to ignore in .ucacherignore.env:
GITHUB_TOKEN
ACTIONS_RUNTIME_TOKEN
GITHUB_PATH
GITHUB_OUTPUT
GITHUB_ENV
Complete example here: .ucacherignore.env
This prevents environment changes that don’t impact command output from invalidating the cache.
actions/cache is the official GitHub Action designed to cache dependencies and build outputs in GitHub Actions workflows. Here it is how they compare to each other:
| Feature | actions/cache | ucacher |
|---|---|---|
| Output restore | File-based | Command-based |
| Skipping | Manual via if + cache-hit | Automatic |
| Keying | Manual, broad scope | Automatic, only relevant files |
| Persistence | GitHub cache | GitHub cache, S3, Minio (upcoming) |
| Scope | Step | Command |
ucacher offers a more automated, precise, and efficient alternative to actions/cache in GitHub Actions by tracking file-level dependencies and automating caching and skipping at the command level.
Unlike actions/cache, which requires manual setup with defined paths and keys, ucacher eliminates human errors and dynamically determines when commands should be skipped or re-executed based on actual file changes.
This results in finer-grain caching, better resource optimization, and significant time savings, especially in complex workflows like monorepos or matrix builds, where broad cache keys in actions/cache often lead to inefficiencies like unnecessarily invalidating unrelated steps, redundant execution of unchanged tasks and manual configuration errors.
github-tokenThis token is used by ucacher to overwrite the Github Actions cache entry where the build metadata is stored. It requires write permissions for the actions scope in the GitHub REST API.
If omitted, the GITHUB_TOKEN of the job is used. This token should have enough permission by default. If that is not case, please refer to the official GHA documentation for guidance on modifying its permissions.
yarn test) into smaller shards to maximize cache hit chances when only a subset of source files change.ucacher to track inputs and outputs accurately..ucacherignore and .ucacherignore.env to exclude irrelevant files and variables from tracking.amd64.ucacher is free to use; it may become open-source in the future.ucacher collects limited runtime metrics for maintenance, such as repository and organization names, commit author, and ucacher-specific errors. Source code or environment data is never collected.ucacher?(in chronological order)
Using
ucacher? Send a PR adding your repo at the end of the previous list
Please give us feedback to keep improving it by opening an issue in this repo. In particular, we'd like to know:
ucacher missing some file accesses?Thanks!
8 commits