.. | ||
action.yml | ||
README.md |
Restore action
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.
Documentation
Inputs
key
- An explicit key for a cache entry. See creating a cache key.path
- A list of files, directories, and wildcard patterns to restore. See@actions/glob
for supported patterns.restore-keys
- An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key.fail-on-cache-miss
- Fail the workflow if cache entry is not found. Default:false
lookup-only
- If true, only checks if cache entry exists and skips download. Default:false
Outputs
cache-hit
- A boolean value to indicate an exact match was found for the key.cache-primary-key
- Cache primary key passed in the input to use in subsequent steps of the workflow.cache-matched-key
- Key of the cache that was restored, it could either be the primary key on cache-hit or a partial/complete match of one of the restore keys.
Note
cache-hit
will be set totrue
only when cache hit occurs for the exactkey
match. For a partial key match viarestore-keys
or a cache miss, it will be set tofalse
.
Environment Variables
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
Use cases
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.
Only restore cache
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@v4
- uses: actions/cache/restore@v4
id: cache
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: /install.sh
- name: Build
run: /build.sh
- name: Publish package to public
run: /publish.sh
Once the cache is restored, unlike actions/cache
, this action won't run a post step to do post-processing, and the rest of the workflow will run as usual.
Save intermediate private build artifacts
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 actions/cache
or actions/cache/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.
Step 1 - Build the parent module and save it
steps:
- uses: actions/checkout@v4
- name: Build
run: /build-parent-module.sh
- uses: actions/cache/save@v4
id: cache
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Step 2 - Restore the built artifact from cache using the same key and path
steps:
- uses: actions/checkout@v4
- uses: actions/cache/restore@v4
id: cache
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: /install.sh
- name: Build
run: /build-child-module.sh
- name: Publish package to public
run: