The restore action restores a cache. It works similarly to the cache action except that it doesn't have a post step to save the cache. This action provides granular ability to restore a cache without having to save it. It accepts the same set of inputs as the cache action.
| name | description | required | default |
|---|---|---|---|
primary-key |
|
true |
"" |
restore-prefixes-first-match |
|
false |
"" |
restore-prefixes-all-matches |
|
false |
"" |
lookup-only |
|
false |
false |
fail-on |
|
false |
"" |
nix |
|
false |
true |
save |
|
false |
true |
paths |
|
false |
"" |
paths-macos |
|
false |
"" |
paths-linux |
|
false |
"" |
backend |
Choose an implementation of the
|
false |
actions |
token |
|
false |
${{ github.token }} |
| name | description |
|---|---|
primary-key |
|
hit |
|
hit-primary-key |
|
hit-first-match |
|
restored-key |
|
restored-keys |
|
SEGMENT_DOWNLOAD_TIMEOUT_MINS- Segment download timeout (in minutes, default10) to abort download of the segment if not completed in the defined number of minutes. Read more
As this is a newly introduced action to give users more control in their workflows, below are some use cases where one can use this action.
If you are using separate jobs to create and save your cache(s) to be reused by other jobs in a repository, this action will take care of your cache restoring needs.
steps:
- uses: actions/checkout@v6
- uses: nix-community/cache-nix-action@v7
id: cache
with:
primary-key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
paths: path/to/dependencies
- name: Install Dependencies
if: steps.cache.outputs.hit-primary-key != 'true'
run: /install.sh
- name: Build
run: /build.sh
- name: Publish package to public
run: /publish.shOnce the cache is restored, unlike nix-community/cache-nix-action, this action won't run a post step to do post-processing, and the rest of the workflow will run as usual.
In case of multi-module projects, where the built artifact of one project needs to be reused in subsequent child modules, the need to rebuild the parent module again and again with every build can be eliminated. The nix-community/cache-nix-action or nix-community/cache-nix-action/save action can be used to build and save the parent module artifact once, and it can be restored multiple times while building the child modules.
steps:
- uses: actions/checkout@v6
- name: Build
run: /build-parent-module.sh
- uses: nix-community/cache-nix-action@v7
id: cache
with:
primary-key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
paths: path/to/dependenciessteps:
- uses: actions/checkout@v6
- uses: nix-community/cache-nix-action@v7
id: cache
with:
primary-key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
paths: path/to/dependencies
- name: Install Dependencies
if: steps.cache.outputs.hit-primary-key != 'true'
run: /install.sh
- name: Build
run: /build-child-module.sh
- name: Publish package to public
run: /publish.shYou can use fail-on: miss to exit a workflow on a cache miss. This way you can restrict your workflow to only build when there is a hit-primary-key.
To fail if there is no cache hit for the primary key, leave restore-prefixes-first-match empty!
steps:
- uses: actions/checkout@v6
- uses: nix-community/cache-nix-action@v7
id: cache
with:
primary-key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
paths: path/to/dependencies
fail-on-cache-miss: true
- name: Build
run: /build.shUsually you may want to use the same primary-key with both actions/cache/restore and nix-community/cache-nix-action/save actions. To achieve this, use outputs from the restore action to reuse the same primary key (or the key of the cache that was restored).
The outputs primary-key and restored-key can be used to check if the restored cache is same as the given primary key. Alternatively, the hit-primary-key output can also be used to check if the restored was a complete match or a partially restored cache.
It is very important to use the same primary-key and paths that were used by either nix-community/cache-nix-action or nix-community/cache-nix-action/save while saving the cache. Learn more about cache key naming and versioning here.