1
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-02 04:57:46 +02:00
cache/engineering fiston data cash flow
2024-03-20 13:08:19 +02:00

5997 lines
209 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Attachment engineering tshingombe data microsoft alu skill.docx added.
None selected
Skip to content
Using Gmail with screen readers
27 of 4,479
[t5h2i0tadi/engineering-tshing-binair-archfile-] Run failed at startup: CodeQL - main (671f5fc)
Inbox
tshingombe <notifications@github.com>
Mar 19, 2024, 9:49PM (15 hours ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-, Ci
GitHub
[t5h2i0tadi/engineering-tshing-binair-archfile-] CodeQL workflow run
CodeQL: No jobs were run
View workflow run
You are receiving this because you are subscribed to this thread.
Manage your GitHub Actions notifications
GitHub, Inc. ・88 Colin P Kelly Jr Street ・San Francisco, CA 94107
tshingombe fiston
12:53PM (12 minutes ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
tshingombe fiston
12:54PM (11 minutes ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-
Skip to content
tshingombe-engineering /
engin-data-exam-tshingomb
Settings
Creating a new workflow file in engin-data-exam-tshingomb
Breadcrumbs
engin-data-exam-tshingomb
/.github
/workflows
/
in
main
Indent mode
Indent sizeLine wrap mode
Editing blank.yml file contents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Use Control + Shift + m to toggle the tab key moving focus. Alternatively, use esc then tab to move to the next interactive element on the page.
Use Control + Space to trigger autocomplete in most situations.
Help Panel navigation
Marketplace
Documentation
/ Cache
Cache
By actions
v4.0.2
4.2k
Cache artifacts like dependencies and build outputs to improve workflow execution time
View full Marketplace listing
Installation
Copy and paste the following snippet into your .yml file.
Version: v4.0.2
- name: Cache
uses: actions/cache@v4.0.2
with:
# A list of files, directories, and wildcard patterns to cache and restore
path:
# An explicit key for restoring and saving the cache
key:
# An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.
restore-keys: # optional
# The chunk size used to split up large files during upload, in bytes
upload-chunk-size: # optional
# An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms
enableCrossOsArchive: # optional, default is false
# Fail the workflow if cache entry is not found
fail-on-cache-miss: # optional, default is false
# Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache
lookup-only: # optional, default is false
# Run the post step to save the cache even if another step before fails
save-always: # optional, default is false
Code
Issues
Pull requests
Actions
Projects
Security
Insights
tshingombe fiston
12:55PM (10 minutes ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-
Skip to content
Marketplace
Actions
Cache
GitHub Action
Cache
v4.0.2 Latest version
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
Verified creator
GitHub has verified that this action was created by actions.
Learn more about verified Actions.
Stars
Contributors
@vsvipul @kotewar @joshmgross @dhadka @lvpx @Phantsure @aiqiaoy @bishal-pdMSFT @takost @bethanyj28 @t-dedah @magnetikonline
Categories
Dependency management Utilities
Links
actions/cache Open issues 92 Pull requests 41
Report abuse
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
tshingombe fiston
12:58PM (7 minutes ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-
Skip to content
actions /
cache
Insights
Owner avatar cache Public
actions/cache
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
t
Add file
Folders and files
Name
Last commit message
Last commit date
Latest commit
bethanyj28bethanyj28
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss
0c45773 ·
History
.devcontainer
GA for granular cache (#1035)
.github
add release action
.licenses/npm
licensed cache
.vscode
Initial commit
__tests__
Add test case for process exit
dist
Fix fail-on-cache-miss not working
restore
Update "only-" actions to node20
save
Update "only-" actions to node20
src
Fix fail-on-cache-miss not working
.eslintrc.json
Update eslint and prettier
.gitattributes
Fix line ending for windows test
.gitignore
test e2e during workflow (#185)
.licensed.yml
Add Licensed to attribute third party licenses
.prettierrc.json
Initial commit
CODE_OF_CONDUCT.md
Fix repo name in contact email (#41)
CONTRIBUTING.md
Update contributing.md
LICENSE
Initial commit
README.md
Update examples
RELEASES.md
Bump version
action.yml
Merge branch 'main' into main
caching-strategies.md
Fixing paths for OSes (#1101)
examples.md
Clarify that macos-latest image has bazelisk
jest.config.js
Resolve dependabot alerts
package-lock.json
Bump version
package.json
Bump version
tips-and-workarounds.md
Merge branch 'main' into pdotl-patch-1
tsconfig.json
Initial commit
Repository files navigation
Security
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
About
Cache dependencies and build outputs in GitHub Actions
Resources
Readme
License
MIT license
Code of conduct
Code of conduct
Security policy
Security policy
Activity
Custom properties
Stars
4.2k stars
Watchers
85 watching
Forks
1.1k forks
Report repository
Releases 51
v4.0.2 Latest
Mar 19, 2024
+ 50 releases
Packages
No packages published
Used by 905k
@remomax
@linhh-phv
@thibs12
@NeptuneX-Aggregator
@tnikFi
@skyrych
@VincentKobz
@kanandev2024
+ 905,172
Contributors 131
@vsvipul
@kotewar
@joshmgross
@dhadka
@lvpx
@Phantsure
@aiqiaoy
@bishal-pdMSFT
@takost
@bethanyj28
@t-dedah
@magnetikonline
@ashwinsangem
@konradpabjan
+ 117 contributors
Deployments 2
releaseNewActionVersion March 19, 2024 17:55
Languages
JavaScript 0.9%
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
actions/cache: Cache dependencies and build outputs in GitHub Actions
Code
Issues 92
Pull requests 41
Discussions
Actions
Security
README
Code of conduct
MIT license
TypeScript 97.9%
Shell 1.2%
On Wed, Mar 20, 2024 at 12:55PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
Marketplace
Actions
Cache
GitHub Action
Cache
v4.0.2 Latest version
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
Verified creator
GitHub has verified that this action was created by actions.
Learn more about verified Actions.
Stars
Contributors
@vsvipul @kotewar @joshmgross @dhadka @lvpx @Phantsure @aiqiaoy @bishal-pdMSFT @takost @bethanyj28 @t-dedah @magnetikonline
Categories
Dependency management Utilities
Links
actions/cache Open issues 92 Pull requests 41
Report abuse
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
On Wed, Mar 20, 2024 at 12:54PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
tshingombe-engineering /
engin-data-exam-tshingomb
Settings
Creating a new workflow file in engin-data-exam-tshingomb
Breadcrumbs
engin-data-exam-tshingomb
/.github
/workflows
/
in
main
Indent mode
Indent sizeLine wrap mode
Editing blank.yml file contents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
Use Control + Shift + m to toggle the tab key moving focus. Alternatively, use esc then tab to move to the next interactive element on the page.
Use Control + Space to trigger autocomplete in most situations.
Help Panel navigation
Marketplace
Documentation
/ Cache
Cache
By actions
v4.0.2
4.2k
Cache artifacts like dependencies and build outputs to improve workflow execution time
View full Marketplace listing
Installation
Copy and paste the following snippet into your .yml file.
Version: v4.0.2
- name: Cache
uses: actions/cache@v4.0.2
with:
# A list of files, directories, and wildcard patterns to cache and restore
path:
# An explicit key for restoring and saving the cache
key:
# An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.
restore-keys: # optional
# The chunk size used to split up large files during upload, in bytes
upload-chunk-size: # optional
# An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms
enableCrossOsArchive: # optional, default is false
# Fail the workflow if cache entry is not found
fail-on-cache-miss: # optional, default is false
# Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache
lookup-only: # optional, default is false
# Run the post step to save the cache even if another step before fails
save-always: # optional, default is false
Code
Issues
Pull requests
Actions
Projects
Security
Insights
On Wed, Mar 20, 2024 at 12:53PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
On Tue, Mar 19, 2024 at 9:49PM tshingombe <notifications@github.com> wrote:
GitHub
[t5h2i0tadi/engineering-tshing-binair-archfile-] CodeQL workflow run
CodeQL: No jobs were run
View workflow run
You are receiving this because you are subscribed to this thread.
Manage your GitHub Actions notifications
GitHub, Inc. ・88 Colin P Kelly Jr Street ・San Francisco, CA 94107
...
[Message clipped] View entire message
tshingombe fiston
12:59PM (6 minutes ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-
# Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
>Two other actions are available in addition to the primary `cache` action:
>* [Restore action](./restore/README.md)
>* [Save action](./save/README.md)
[![Tests](https://github.com/actions/cache/actions/workflows/workflow.yml/badge.svg)](https://github.com/actions/cache/actions/workflows/workflow.yml)
## Documentation
See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows).
## What's New
### v4
* Updated to node 20
* Added a `save-always` flag to save the cache even if a prior step fails
### v3
* Added support for caching in GHES 3.5+.
* Fixed download issue for files > 2GB during restore.
* Updated the minimum runner version support from node 12 -> node 16.
* Fixed avoiding empty cache save when no files are available for caching.
* Fixed tar creation error while trying to create tar with path as `~/` home folder on `ubuntu-latest`.
* Fixed zstd failing on amazon linux 2.0 runners.
* Fixed cache not working with github workspace directory or current directory.
* Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
* Fix zstd not working for windows on gnu tar in issues.
* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 10 minutes.
* New actions are available for granular control over caches - [restore](restore/action.yml) and [save](save/action.yml).
* Support cross-os caching as an opt-in feature. See [Cross OS caching](./tips-and-workarounds.md#cross-os-cache) for more info.
* Added option to fail job on cache miss. See [Exit workflow on cache miss](./restore/README.md#exit-workflow-on-cache-miss) for more info.
* Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
* Added option to lookup cache without downloading it.
* Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the [v2 README.md](https://github.com/actions/cache/blob/v2/README.md) for older updates.
## Usage
### Pre-requisites
Create a workflow `.yml` file in your repository's `.github/workflows` directory. An [example workflow](#example-cache-workflow) is available below. For more information, see the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file).
If you are using this inside a container, a POSIX-compliant `tar` needs to be included and accessible from the execution path.
If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are required for [Cross-OS caching](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache) to work. They are also recommended to be installed in general so the performance is on par with `hosted` Windows runners.
### Inputs
* `key` - An explicit key for a cache entry. See [creating a cache key](#creating-a-cache-key).
* `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/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.
* `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: `false`
* `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. Does not change save cache behavior. Default: `false`
#### Environment Variables
* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `10`) to abort download of the segment if not completed in the defined number of minutes. [Read more](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout)
### Outputs
* `cache-hit` - A boolean value to indicate an exact match was found for the key.
> **Note** `cache-hit` will only be set to `true` when a cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`.
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output
### Cache scopes
The cache is scoped to the key, [version](#cache-version), and branch. The default branch cache is available to other branches.
See [Matching a cache key](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) for more info.
### Example cache workflow
#### Restoring and saving cache using a single action
```yaml
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
```
The `cache` action provides a `cache-hit` output which is set to `true` when the cache is restored using the primary `key` and `false` when the cache is restored using `restore-keys` or no cache is restored.
#### Using a combination of restore and save actions
```yaml
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
```
> **Note**
> You must use the `cache` or `restore` action in your workflow before you need to use the files that might be restored from the cache. If the provided `key` matches an existing cache, a new cache is not created and if the provided `key` doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
## Caching Strategies
With the introduction of the `restore` and `save` actions, a lot of caching use cases can now be achieved. Please see the [caching strategies](./caching-strategies.md) document for understanding how you can use the actions strategically to achieve the desired goal.
## Implementation Examples
Every programming language and framework has its own way of caching.
See [Examples](examples.md) for a list of `actions/cache` implementations for use with:
* [C# - NuGet](./examples.md#c---nuget)
* [Clojure - Lein Deps](./examples.md#clojure---lein-deps)
* [D - DUB](./examples.md#d---dub)
* [Deno](./examples.md#deno)
* [Elixir - Mix](./examples.md#elixir---mix)
* [Go - Modules](./examples.md#go---modules)
* [Haskell - Cabal](./examples.md#haskell---cabal)
* [Haskell - Stack](./examples.md#haskell---stack)
* [Java - Gradle](./examples.md#java---gradle)
* [Java - Maven](./examples.md#java---maven)
* [Node - npm](./examples.md#node---npm)
* [Node - Lerna](./examples.md#node---lerna)
* [Node - Yarn](./examples.md#node---yarn)
* [OCaml/Reason - esy](./examples.md#ocamlreason---esy)
* [PHP - Composer](./examples.md#php---composer)
* [Python - pip](./examples.md#python---pip)
* [Python - pipenv](./examples.md#python---pipenv)
* [R - renv](./examples.md#r---renv)
* [Ruby - Bundler](./examples.md#ruby---bundler)
* [Rust - Cargo](./examples.md#rust---cargo)
* [Scala - SBT](./examples.md#scala---sbt)
* [Swift, Objective-C - Carthage](./examples.md#swift-objective-c---carthage)
* [Swift, Objective-C - CocoaPods](./examples.md#swift-objective-c---cocoapods)
* [Swift - Swift Package Manager](./examples.md#swift---swift-package-manager)
* [Swift - Mint](./examples.md#swift---mint)
## Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
```yaml
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
```yaml
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
```
See [Using contexts to create cache keys](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#using-contexts-to-create-cache-keys)
## Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
## Skipping steps based on cache-hit
Using the `cache-hit` output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the `hash` of the package file.
Example:
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
```
> **Note** The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`)
## Cache Version
Cache version is a hash [generated](https://github.com/actions/toolkit/blob/500d0b42fee2552ae9eeb5933091fe2fbf14e72d/packages/cache/src/internal/cacheHttpClient.ts#L73-L90) for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the `path` of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a `windows-latest` runner can't be restored on `ubuntu-latest` as cache `Version`s are different.
> Pro tip: The [list caches](https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository) API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
<details>
<summary>Example</summary>
The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
```yaml
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d prime-numbers
- name: Cache Numbers
id: cache-numbers
uses: actions/cache@v4
with:
path: numbers
key: primes
- name: Generate Numbers
if: steps.cache-numbers.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d numbers
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes -d prime-numbers
```
</details>
## Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
* [Cache segment restore timeout](./tips-and-workarounds.md#cache-segment-restore-timeout)
* [Update a cache](./tips-and-workarounds.md#update-a-cache)
* [Use cache across feature branches](./tips-and-workarounds.md#use-cache-across-feature-branches)
* [Cross OS cache](./tips-and-workarounds.md#cross-os-cache)
* [Force deletion of caches overriding default cache eviction policy](./tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy)
### Windows environment variables
Please note that Windows environment variables (like `%LocalAppData%`) will NOT be expanded by this action. Instead, prefer using `~` in your paths which will expand to the HOME directory. For example, instead of `%LocalAppData%`, use `~\AppData\Local`. For a list of supported default environment variables, see the [Learn GitHub Actions: Variables](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables) page.
## Contributing
We would love for you to contribute to `actions/cache`. Pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
On Wed, Mar 20, 2024 at 12:58PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
actions /
cache
Insights
Owner avatar cache Public
actions/cache
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
t
Add file
Folders and files
Name
Last commit message
Last commit date
Latest commit
bethanyj28bethanyj28
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss
0c45773 ·
History
.devcontainer
GA for granular cache (#1035)
.github
add release action
.licenses/npm
licensed cache
.vscode
Initial commit
__tests__
Add test case for process exit
dist
Fix fail-on-cache-miss not working
restore
Update "only-" actions to node20
save
Update "only-" actions to node20
src
Fix fail-on-cache-miss not working
.eslintrc.json
Update eslint and prettier
.gitattributes
Fix line ending for windows test
.gitignore
test e2e during workflow (#185)
.licensed.yml
Add Licensed to attribute third party licenses
.prettierrc.json
Initial commit
CODE_OF_CONDUCT.md
Fix repo name in contact email (#41)
CONTRIBUTING.md
Update contributing.md
LICENSE
Initial commit
README.md
Update examples
RELEASES.md
Bump version
action.yml
Merge branch 'main' into main
caching-strategies.md
Fixing paths for OSes (#1101)
examples.md
Clarify that macos-latest image has bazelisk
jest.config.js
Resolve dependabot alerts
package-lock.json
Bump version
package.json
Bump version
tips-and-workarounds.md
Merge branch 'main' into pdotl-patch-1
tsconfig.json
Initial commit
Repository files navigation
Security
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
About
Cache dependencies and build outputs in GitHub Actions
Resources
Readme
License
MIT license
Code of conduct
Code of conduct
Security policy
Security policy
Activity
Custom properties
Stars
4.2k stars
Watchers
85 watching
Forks
1.1k forks
Report repository
Releases 51
v4.0.2 Latest
Mar 19, 2024
+ 50 releases
Packages
No packages published
Used by 905k
@remomax
@linhh-phv
@thibs12
@NeptuneX-Aggregator
@tnikFi
@skyrych
@VincentKobz
@kanandev2024
+ 905,172
Contributors 131
@vsvipul
@kotewar
@joshmgross
@dhadka
@lvpx
@Phantsure
@aiqiaoy
@bishal-pdMSFT
@takost
@bethanyj28
@t-dedah
@magnetikonline
@ashwinsangem
@konradpabjan
+ 117 contributors
Deployments 2
releaseNewActionVersion March 19, 2024 17:55
Languages
JavaScript 0.9%
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
actions/cache: Cache dependencies and build outputs in GitHub Actions
Code
Issues 92
Pull requests 41
Discussions
Actions
Security
README
Code of conduct
MIT license
TypeScript 97.9%
Shell 1.2%
On Wed, Mar 20, 2024 at 12:55PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
Marketplace
Actions
Cache
GitHub Action
Cache
v4.0.2 Latest version
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
Verified creator
GitHub has verified that this action was created by actions.
Learn more about verified Actions.
Stars
Contributors
@vsvipul @kotewar @joshmgross @dhadka @lvpx @Phantsure @aiqiaoy @bishal-pdMSFT @takost @bethanyj28 @t-dedah @magnetikonline
Categories
Dependency management Utilities
Links
actions/cache Open issues 92 Pull requests 41
Report abuse
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
On Wed, Mar 20, 2024 at 12:54PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
tshingombe-engineering /
engin-data-exam-tshingomb
Settings
Creating a new workflow file in engin-data-exam-tshingomb
Breadcrumbs
engin-data-exam-tshingomb
/.github
/workflows
/
in
main
Indent mode
Indent sizeLine wrap mode
Editing blank.yml file contents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
Use Control + Shift + m to toggle the tab key moving focus. Alternatively, use esc then tab to move to the next interactive element on the page.
Use Control + Space to trigger autocomplete in most situations.
Help Panel navigation
Marketplace
Documentation
/ Cache
Cache
By actions
v4.0.2
4.2k
Cache artifacts like dependencies and build outputs to improve workflow execution time
View full Marketplace listing
Installation
Copy and paste the following snippet into your .yml file.
Version: v4.0.2
- name: Cache
uses: actions/cache@v4.0.2
with:
# A list of files, directories, and wildcard patterns to cache and restore
path:
# An explicit key for restoring and saving the cache
key:
# An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.
restore-keys: # optional
# The chunk size used to split up large files during upload, in bytes
upload-chunk-size: # optional
# An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms
enableCrossOsArchive: # optional, default is false
# Fail the workflow if cache entry is not found
fail-on-cache-miss: # optional, default is false
# Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache
lookup-only: # optional, default is false
# Run the post step to save the cache even if another step before fails
save-always: # optional, default is false
Code
Issues
Pull requests
Actions
Projects
Security
Insights
On Wed, Mar 20, 2024 at 12:53PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
On Tue, Mar 19, 2024 at 9:49PM tshingombe <notifications@github.com> wrote:
GitHub
[t5h2i0tadi/engineering-tshing-binair-archfile-] CodeQL workflow run
CodeQL: No jobs were run
View workflow run
You are receiving this because you are subscribed to this thread.
Manage your GitHub Actions notifications
GitHub, Inc. ・88 Colin P Kelly Jr Street ・San Francisco, CA 94107
...
[Message clipped] View entire message
tshingombe fiston
1:00PM (5 minutes ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-
Skip to content
actions /
cache
Insights
Comparing changes
Choose two branches to see whats changed or to start a new pull request. If you need to, you can also
or learn more about diff comparisons.
...
Able to merge. These branches can be automatically merged.
Discuss and review the changes in this comparison with others. Learn about pull requests
1 contributor
Commits on Mar 20, 2024
Update README.md
@t5h2i0tadi
t5h2i0tadi committed Mar 20, 2024
Showing
with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion 2 README.md
@@ -14,7 +14,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
## What's New
## What's New
### v4
### v4 g
* Updated to node 20
* Updated to node 20
* Added a `save-always` flag to save the cache even if a prior step fails
* Added a `save-always` flag to save the cache even if a prior step fails
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
Comparing actions:main...t5h2i0tadi:patch-1 · actions/cache
Code
Issues 92
Pull requests 41
Discussions
Actions
Security
1 commit
1 file changed
On Wed, Mar 20, 2024 at 12:59PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
# Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
>Two other actions are available in addition to the primary `cache` action:
>* [Restore action](./restore/README.md)
>* [Save action](./save/README.md)
[![Tests](https://github.com/actions/cache/actions/workflows/workflow.yml/badge.svg)](https://github.com/actions/cache/actions/workflows/workflow.yml)
## Documentation
See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows).
## What's New
### v4
* Updated to node 20
* Added a `save-always` flag to save the cache even if a prior step fails
### v3
* Added support for caching in GHES 3.5+.
* Fixed download issue for files > 2GB during restore.
* Updated the minimum runner version support from node 12 -> node 16.
* Fixed avoiding empty cache save when no files are available for caching.
* Fixed tar creation error while trying to create tar with path as `~/` home folder on `ubuntu-latest`.
* Fixed zstd failing on amazon linux 2.0 runners.
* Fixed cache not working with github workspace directory or current directory.
* Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
* Fix zstd not working for windows on gnu tar in issues.
* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 10 minutes.
* New actions are available for granular control over caches - [restore](restore/action.yml) and [save](save/action.yml).
* Support cross-os caching as an opt-in feature. See [Cross OS caching](./tips-and-workarounds.md#cross-os-cache) for more info.
* Added option to fail job on cache miss. See [Exit workflow on cache miss](./restore/README.md#exit-workflow-on-cache-miss) for more info.
* Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
* Added option to lookup cache without downloading it.
* Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the [v2 README.md](https://github.com/actions/cache/blob/v2/README.md) for older updates.
## Usage
### Pre-requisites
Create a workflow `.yml` file in your repository's `.github/workflows` directory. An [example workflow](#example-cache-workflow) is available below. For more information, see the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file).
If you are using this inside a container, a POSIX-compliant `tar` needs to be included and accessible from the execution path.
If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are required for [Cross-OS caching](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache) to work. They are also recommended to be installed in general so the performance is on par with `hosted` Windows runners.
### Inputs
* `key` - An explicit key for a cache entry. See [creating a cache key](#creating-a-cache-key).
* `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/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.
* `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: `false`
* `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. Does not change save cache behavior. Default: `false`
#### Environment Variables
* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `10`) to abort download of the segment if not completed in the defined number of minutes. [Read more](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout)
### Outputs
* `cache-hit` - A boolean value to indicate an exact match was found for the key.
> **Note** `cache-hit` will only be set to `true` when a cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`.
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output
### Cache scopes
The cache is scoped to the key, [version](#cache-version), and branch. The default branch cache is available to other branches.
See [Matching a cache key](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) for more info.
### Example cache workflow
#### Restoring and saving cache using a single action
```yaml
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
```
The `cache` action provides a `cache-hit` output which is set to `true` when the cache is restored using the primary `key` and `false` when the cache is restored using `restore-keys` or no cache is restored.
#### Using a combination of restore and save actions
```yaml
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
```
> **Note**
> You must use the `cache` or `restore` action in your workflow before you need to use the files that might be restored from the cache. If the provided `key` matches an existing cache, a new cache is not created and if the provided `key` doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
## Caching Strategies
With the introduction of the `restore` and `save` actions, a lot of caching use cases can now be achieved. Please see the [caching strategies](./caching-strategies.md) document for understanding how you can use the actions strategically to achieve the desired goal.
## Implementation Examples
Every programming language and framework has its own way of caching.
See [Examples](examples.md) for a list of `actions/cache` implementations for use with:
* [C# - NuGet](./examples.md#c---nuget)
* [Clojure - Lein Deps](./examples.md#clojure---lein-deps)
* [D - DUB](./examples.md#d---dub)
* [Deno](./examples.md#deno)
* [Elixir - Mix](./examples.md#elixir---mix)
* [Go - Modules](./examples.md#go---modules)
* [Haskell - Cabal](./examples.md#haskell---cabal)
* [Haskell - Stack](./examples.md#haskell---stack)
* [Java - Gradle](./examples.md#java---gradle)
* [Java - Maven](./examples.md#java---maven)
* [Node - npm](./examples.md#node---npm)
* [Node - Lerna](./examples.md#node---lerna)
* [Node - Yarn](./examples.md#node---yarn)
* [OCaml/Reason - esy](./examples.md#ocamlreason---esy)
* [PHP - Composer](./examples.md#php---composer)
* [Python - pip](./examples.md#python---pip)
* [Python - pipenv](./examples.md#python---pipenv)
* [R - renv](./examples.md#r---renv)
* [Ruby - Bundler](./examples.md#ruby---bundler)
* [Rust - Cargo](./examples.md#rust---cargo)
* [Scala - SBT](./examples.md#scala---sbt)
* [Swift, Objective-C - Carthage](./examples.md#swift-objective-c---carthage)
* [Swift, Objective-C - CocoaPods](./examples.md#swift-objective-c---cocoapods)
* [Swift - Swift Package Manager](./examples.md#swift---swift-package-manager)
* [Swift - Mint](./examples.md#swift---mint)
## Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
```yaml
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
```yaml
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
```
See [Using contexts to create cache keys](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#using-contexts-to-create-cache-keys)
## Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
## Skipping steps based on cache-hit
Using the `cache-hit` output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the `hash` of the package file.
Example:
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
```
> **Note** The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`)
## Cache Version
Cache version is a hash [generated](https://github.com/actions/toolkit/blob/500d0b42fee2552ae9eeb5933091fe2fbf14e72d/packages/cache/src/internal/cacheHttpClient.ts#L73-L90) for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the `path` of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a `windows-latest` runner can't be restored on `ubuntu-latest` as cache `Version`s are different.
> Pro tip: The [list caches](https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository) API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
<details>
<summary>Example</summary>
The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
```yaml
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d prime-numbers
- name: Cache Numbers
id: cache-numbers
uses: actions/cache@v4
with:
path: numbers
key: primes
- name: Generate Numbers
if: steps.cache-numbers.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d numbers
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes -d prime-numbers
```
</details>
## Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
* [Cache segment restore timeout](./tips-and-workarounds.md#cache-segment-restore-timeout)
* [Update a cache](./tips-and-workarounds.md#update-a-cache)
* [Use cache across feature branches](./tips-and-workarounds.md#use-cache-across-feature-branches)
* [Cross OS cache](./tips-and-workarounds.md#cross-os-cache)
* [Force deletion of caches overriding default cache eviction policy](./tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy)
### Windows environment variables
Please note that Windows environment variables (like `%LocalAppData%`) will NOT be expanded by this action. Instead, prefer using `~` in your paths which will expand to the HOME directory. For example, instead of `%LocalAppData%`, use `~\AppData\Local`. For a list of supported default environment variables, see the [Learn GitHub Actions: Variables](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables) page.
## Contributing
We would love for you to contribute to `actions/cache`. Pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
On Wed, Mar 20, 2024 at 12:58PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
actions /
cache
Insights
Owner avatar cache Public
actions/cache
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
t
Add file
Folders and files
Name
Last commit message
Last commit date
Latest commit
bethanyj28bethanyj28
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss
0c45773 ·
History
.devcontainer
GA for granular cache (#1035)
.github
add release action
.licenses/npm
licensed cache
.vscode
Initial commit
__tests__
Add test case for process exit
dist
Fix fail-on-cache-miss not working
restore
Update "only-" actions to node20
save
Update "only-" actions to node20
src
Fix fail-on-cache-miss not working
.eslintrc.json
Update eslint and prettier
.gitattributes
Fix line ending for windows test
.gitignore
test e2e during workflow (#185)
.licensed.yml
Add Licensed to attribute third party licenses
.prettierrc.json
Initial commit
CODE_OF_CONDUCT.md
Fix repo name in contact email (#41)
CONTRIBUTING.md
Update contributing.md
LICENSE
Initial commit
README.md
Update examples
RELEASES.md
Bump version
action.yml
Merge branch 'main' into main
caching-strategies.md
Fixing paths for OSes (#1101)
examples.md
Clarify that macos-latest image has bazelisk
jest.config.js
Resolve dependabot alerts
package-lock.json
Bump version
package.json
Bump version
tips-and-workarounds.md
Merge branch 'main' into pdotl-patch-1
tsconfig.json
Initial commit
Repository files navigation
Security
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
About
Cache dependencies and build outputs in GitHub Actions
Resources
Readme
License
MIT license
Code of conduct
Code of conduct
Security policy
Security policy
Activity
Custom properties
Stars
4.2k stars
Watchers
85 watching
Forks
1.1k forks
Report repository
Releases 51
v4.0.2 Latest
Mar 19, 2024
+ 50 releases
Packages
No packages published
Used by 905k
@remomax
@linhh-phv
@thibs12
@NeptuneX-Aggregator
@tnikFi
@skyrych
@VincentKobz
@kanandev2024
+ 905,172
Contributors 131
@vsvipul
@kotewar
@joshmgross
@dhadka
@lvpx
@Phantsure
@aiqiaoy
@bishal-pdMSFT
@takost
@bethanyj28
@t-dedah
@magnetikonline
@ashwinsangem
@konradpabjan
+ 117 contributors
Deployments 2
releaseNewActionVersion March 19, 2024 17:55
Languages
JavaScript 0.9%
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
actions/cache: Cache dependencies and build outputs in GitHub Actions
Code
Issues 92
Pull requests 41
Discussions
Actions
Security
README
Code of conduct
MIT license
TypeScript 97.9%
Shell 1.2%
On Wed, Mar 20, 2024 at 12:55PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
Marketplace
Actions
Cache
GitHub Action
Cache
v4.0.2 Latest version
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
Verified creator
GitHub has verified that this action was created by actions.
Learn more about verified Actions.
Stars
Contributors
@vsvipul @kotewar @joshmgross @dhadka @lvpx @Phantsure @aiqiaoy @bishal-pdMSFT @takost @bethanyj28 @t-dedah @magnetikonline
Categories
Dependency management Utilities
Links
actions/cache Open issues 92 Pull requests 41
Report abuse
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
On Wed, Mar 20, 2024 at 12:54PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
tshingombe-engineering /
engin-data-exam-tshingomb
Settings
Creating a new workflow file in engin-data-exam-tshingomb
Breadcrumbs
engin-data-exam-tshingomb
/.github
/workflows
/
in
main
Indent mode
Indent sizeLine wrap mode
Editing blank.yml file contents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
Use Control + Shift + m to toggle the tab key moving focus. Alternatively, use esc then tab to move to the next interactive element on the page.
Use Control + Space to trigger autocomplete in most situations.
Help Panel navigation
Marketplace
Documentation
/ Cache
Cache
By actions
v4.0.2
4.2k
Cache artifacts like dependencies and build outputs to improve workflow execution time
View full Marketplace listing
Installation
Copy and paste the following snippet into your .yml file.
Version: v4.0.2
- name: Cache
uses: actions/cache@v4.0.2
with:
# A list of files, directories, and wildcard patterns to cache and restore
path:
# An explicit key for restoring and saving the cache
key:
# An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.
restore-keys: # optional
# The chunk size used to split up large files during upload, in bytes
upload-chunk-size: # optional
# An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms
enableCrossOsArchive: # optional, default is false
# Fail the workflow if cache entry is not found
fail-on-cache-miss: # optional, default is false
# Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache
lookup-only: # optional, default is false
# Run the post step to save the cache even if another step before fails
save-always: # optional, default is false
Code
Issues
Pull requests
Actions
Projects
Security
Insights
On Wed, Mar 20, 2024 at 12:53PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
On Tue, Mar 19, 2024 at 9:49PM tshingombe <notifications@github.com> wrote:
GitHub
[t5h2i0tadi/engineering-tshing-binair-archfile-] CodeQL workflow run
CodeQL: No jobs were run
View workflow run
You are receiving this because you are subscribed to this thread.
Manage your GitHub Actions notifications
GitHub, Inc. ・88 Colin P Kelly Jr Street ・San Francisco, CA 94107
...
[Message clipped] View entire message
tshingombe fiston
1:02PM (4 minutes ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-
Skip to content
actions /
cache
Insights
Actions: actions/cache
Actions
All workflows
Showing runs from all workflows
1,190 workflow runs
Close inactive issues Close inactive issues #819: Scheduled
main
March 20, 2024 10:30
13s
cache restore on versions 3 and 4 not working Assign issue #174: Issue #1361 opened by mark-jordanovic-lewis
March 19, 2024 19:19
13s
v4.0.2 Release new action version #2: Release v4.0.2 released by bethanyj28
March 19, 2024 17:55
10m 24s
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss Code scanning - action #1974: Commit 0c45773 pushed by bethanyj28
v4.0.2
March 19, 2024 17:55
2m 56s
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss Check dist/ #509: Commit 0c45773 pushed by bethanyj28
main
March 19, 2024 15:31
44s
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss Licensed #908: Commit 0c45773 pushed by bethanyj28
main
March 19, 2024 15:31
26s
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss Tests #1219: Commit 0c45773 pushed by bethanyj28
main
March 19, 2024 15:31
1m 38s
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss Code scanning - action #1973: Commit 0c45773 pushed by bethanyj28
main
March 19, 2024 15:31
4m 6s
Close inactive issues Close inactive issues #818: Scheduled
main
March 19, 2024 10:30
15s
Fix fail-on-cache-miss not working Check dist/ #508: Pull request #1327 synchronize by cdce8p
cdce8p:fix-fail-on-cache-miss
March 19, 2024 10:29
45s
Fix fail-on-cache-miss not working Licensed #907: Pull request #1327 synchronize by cdce8p
cdce8p:fix-fail-on-cache-miss
March 19, 2024 10:29
28s
Fix fail-on-cache-miss not working Tests #1218: Pull request #1327 synchronize by cdce8p
cdce8p:fix-fail-on-cache-miss
March 19, 2024 10:29
1m 30s
Fix fail-on-cache-miss not working Code scanning - action #1972: Pull request #1327 synchronize by cdce8p
cdce8p:fix-fail-on-cache-miss
March 19, 2024 10:29
2m 18s
Close inactive issues Close inactive issues #817: Scheduled
main
March 18, 2024 10:30
17s
Code scanning - action Code scanning - action #1971: Scheduled
main
March 17, 2024 21:00
3m 12s
Close inactive issues Close inactive issues #816: Scheduled
main
March 17, 2024 10:30
13s
Close inactive issues Close inactive issues #815: Scheduled
main
March 16, 2024 10:30
16s
Hhiih Assign issue #173: Issue #1360 opened by Ghoifuoffigccty
March 16, 2024 09:16
12s
Close inactive issues Close inactive issues #814: Scheduled
main
March 15, 2024 10:31
17s
Close inactive issues Close inactive issues #813: Scheduled
main
March 14, 2024 10:30
17s
Running actions/cache in a composite action and setting the path via input does not save the cache Assign issue #172: Issue #1359 opened by dreinhardt-terminus
March 13, 2024 23:19
13s
Close inactive issues Close inactive issues #812: Scheduled
main
March 13, 2024 10:30
12s
Close inactive issues Close inactive issues #811: Scheduled
main
March 12, 2024 10:30
13s
Cache Hit / Miss Rate Information Assign issue #171: Issue #1357 opened by edhgoose
March 11, 2024 11:56
12s
Close inactive issues Close inactive issues #810: Scheduled
main
March 11, 2024 10:30
13s
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
Workflow runs · actions/cache
Code
Issues 92
Pull requests 41
Discussions
Actions
Security
Workflows
Management
On Wed, Mar 20, 2024 at 1:00PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
actions /
cache
Insights
Comparing changes
Choose two branches to see whats changed or to start a new pull request. If you need to, you can also
or learn more about diff comparisons.
...
Able to merge. These branches can be automatically merged.
Discuss and review the changes in this comparison with others. Learn about pull requests
1 contributor
Commits on Mar 20, 2024
Update README.md
@t5h2i0tadi
t5h2i0tadi committed Mar 20, 2024
Showing
with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion 2 README.md
@@ -14,7 +14,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
## What's New
## What's New
### v4
### v4 g
* Updated to node 20
* Updated to node 20
* Added a `save-always` flag to save the cache even if a prior step fails
* Added a `save-always` flag to save the cache even if a prior step fails
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
Comparing actions:main...t5h2i0tadi:patch-1 · actions/cache
Code
Issues 92
Pull requests 41
Discussions
Actions
Security
1 commit
1 file changed
On Wed, Mar 20, 2024 at 12:59PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
# Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
>Two other actions are available in addition to the primary `cache` action:
>* [Restore action](./restore/README.md)
>* [Save action](./save/README.md)
[![Tests](https://github.com/actions/cache/actions/workflows/workflow.yml/badge.svg)](https://github.com/actions/cache/actions/workflows/workflow.yml)
## Documentation
See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows).
## What's New
### v4
* Updated to node 20
* Added a `save-always` flag to save the cache even if a prior step fails
### v3
* Added support for caching in GHES 3.5+.
* Fixed download issue for files > 2GB during restore.
* Updated the minimum runner version support from node 12 -> node 16.
* Fixed avoiding empty cache save when no files are available for caching.
* Fixed tar creation error while trying to create tar with path as `~/` home folder on `ubuntu-latest`.
* Fixed zstd failing on amazon linux 2.0 runners.
* Fixed cache not working with github workspace directory or current directory.
* Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
* Fix zstd not working for windows on gnu tar in issues.
* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 10 minutes.
* New actions are available for granular control over caches - [restore](restore/action.yml) and [save](save/action.yml).
* Support cross-os caching as an opt-in feature. See [Cross OS caching](./tips-and-workarounds.md#cross-os-cache) for more info.
* Added option to fail job on cache miss. See [Exit workflow on cache miss](./restore/README.md#exit-workflow-on-cache-miss) for more info.
* Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
* Added option to lookup cache without downloading it.
* Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the [v2 README.md](https://github.com/actions/cache/blob/v2/README.md) for older updates.
## Usage
### Pre-requisites
Create a workflow `.yml` file in your repository's `.github/workflows` directory. An [example workflow](#example-cache-workflow) is available below. For more information, see the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file).
If you are using this inside a container, a POSIX-compliant `tar` needs to be included and accessible from the execution path.
If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are required for [Cross-OS caching](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache) to work. They are also recommended to be installed in general so the performance is on par with `hosted` Windows runners.
### Inputs
* `key` - An explicit key for a cache entry. See [creating a cache key](#creating-a-cache-key).
* `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/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.
* `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: `false`
* `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. Does not change save cache behavior. Default: `false`
#### Environment Variables
* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `10`) to abort download of the segment if not completed in the defined number of minutes. [Read more](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout)
### Outputs
* `cache-hit` - A boolean value to indicate an exact match was found for the key.
> **Note** `cache-hit` will only be set to `true` when a cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`.
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output
### Cache scopes
The cache is scoped to the key, [version](#cache-version), and branch. The default branch cache is available to other branches.
See [Matching a cache key](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) for more info.
### Example cache workflow
#### Restoring and saving cache using a single action
```yaml
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
```
The `cache` action provides a `cache-hit` output which is set to `true` when the cache is restored using the primary `key` and `false` when the cache is restored using `restore-keys` or no cache is restored.
#### Using a combination of restore and save actions
```yaml
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
```
> **Note**
> You must use the `cache` or `restore` action in your workflow before you need to use the files that might be restored from the cache. If the provided `key` matches an existing cache, a new cache is not created and if the provided `key` doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
## Caching Strategies
With the introduction of the `restore` and `save` actions, a lot of caching use cases can now be achieved. Please see the [caching strategies](./caching-strategies.md) document for understanding how you can use the actions strategically to achieve the desired goal.
## Implementation Examples
Every programming language and framework has its own way of caching.
See [Examples](examples.md) for a list of `actions/cache` implementations for use with:
* [C# - NuGet](./examples.md#c---nuget)
* [Clojure - Lein Deps](./examples.md#clojure---lein-deps)
* [D - DUB](./examples.md#d---dub)
* [Deno](./examples.md#deno)
* [Elixir - Mix](./examples.md#elixir---mix)
* [Go - Modules](./examples.md#go---modules)
* [Haskell - Cabal](./examples.md#haskell---cabal)
* [Haskell - Stack](./examples.md#haskell---stack)
* [Java - Gradle](./examples.md#java---gradle)
* [Java - Maven](./examples.md#java---maven)
* [Node - npm](./examples.md#node---npm)
* [Node - Lerna](./examples.md#node---lerna)
* [Node - Yarn](./examples.md#node---yarn)
* [OCaml/Reason - esy](./examples.md#ocamlreason---esy)
* [PHP - Composer](./examples.md#php---composer)
* [Python - pip](./examples.md#python---pip)
* [Python - pipenv](./examples.md#python---pipenv)
* [R - renv](./examples.md#r---renv)
* [Ruby - Bundler](./examples.md#ruby---bundler)
* [Rust - Cargo](./examples.md#rust---cargo)
* [Scala - SBT](./examples.md#scala---sbt)
* [Swift, Objective-C - Carthage](./examples.md#swift-objective-c---carthage)
* [Swift, Objective-C - CocoaPods](./examples.md#swift-objective-c---cocoapods)
* [Swift - Swift Package Manager](./examples.md#swift---swift-package-manager)
* [Swift - Mint](./examples.md#swift---mint)
## Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
```yaml
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
```yaml
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
```
See [Using contexts to create cache keys](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#using-contexts-to-create-cache-keys)
## Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
## Skipping steps based on cache-hit
Using the `cache-hit` output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the `hash` of the package file.
Example:
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
```
> **Note** The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`)
## Cache Version
Cache version is a hash [generated](https://github.com/actions/toolkit/blob/500d0b42fee2552ae9eeb5933091fe2fbf14e72d/packages/cache/src/internal/cacheHttpClient.ts#L73-L90) for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the `path` of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a `windows-latest` runner can't be restored on `ubuntu-latest` as cache `Version`s are different.
> Pro tip: The [list caches](https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository) API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
<details>
<summary>Example</summary>
The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
```yaml
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d prime-numbers
- name: Cache Numbers
id: cache-numbers
uses: actions/cache@v4
with:
path: numbers
key: primes
- name: Generate Numbers
if: steps.cache-numbers.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d numbers
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes -d prime-numbers
```
</details>
## Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
* [Cache segment restore timeout](./tips-and-workarounds.md#cache-segment-restore-timeout)
* [Update a cache](./tips-and-workarounds.md#update-a-cache)
* [Use cache across feature branches](./tips-and-workarounds.md#use-cache-across-feature-branches)
* [Cross OS cache](./tips-and-workarounds.md#cross-os-cache)
* [Force deletion of caches overriding default cache eviction policy](./tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy)
### Windows environment variables
Please note that Windows environment variables (like `%LocalAppData%`) will NOT be expanded by this action. Instead, prefer using `~` in your paths which will expand to the HOME directory. For example, instead of `%LocalAppData%`, use `~\AppData\Local`. For a list of supported default environment variables, see the [Learn GitHub Actions: Variables](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables) page.
## Contributing
We would love for you to contribute to `actions/cache`. Pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
On Wed, Mar 20, 2024 at 12:58PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
actions /
cache
Insights
Owner avatar cache Public
actions/cache
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
t
Add file
Folders and files
Name
Last commit message
Last commit date
Latest commit
bethanyj28bethanyj28
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss
0c45773 ·
History
.devcontainer
GA for granular cache (#1035)
.github
add release action
.licenses/npm
licensed cache
.vscode
Initial commit
__tests__
Add test case for process exit
dist
Fix fail-on-cache-miss not working
restore
Update "only-" actions to node20
save
Update "only-" actions to node20
src
Fix fail-on-cache-miss not working
.eslintrc.json
Update eslint and prettier
.gitattributes
Fix line ending for windows test
.gitignore
test e2e during workflow (#185)
.licensed.yml
Add Licensed to attribute third party licenses
.prettierrc.json
Initial commit
CODE_OF_CONDUCT.md
Fix repo name in contact email (#41)
CONTRIBUTING.md
Update contributing.md
LICENSE
Initial commit
README.md
Update examples
RELEASES.md
Bump version
action.yml
Merge branch 'main' into main
caching-strategies.md
Fixing paths for OSes (#1101)
examples.md
Clarify that macos-latest image has bazelisk
jest.config.js
Resolve dependabot alerts
package-lock.json
Bump version
package.json
Bump version
tips-and-workarounds.md
Merge branch 'main' into pdotl-patch-1
tsconfig.json
Initial commit
Repository files navigation
Security
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
About
Cache dependencies and build outputs in GitHub Actions
Resources
Readme
License
MIT license
Code of conduct
Code of conduct
Security policy
Security policy
Activity
Custom properties
Stars
4.2k stars
Watchers
85 watching
Forks
1.1k forks
Report repository
Releases 51
v4.0.2 Latest
Mar 19, 2024
+ 50 releases
Packages
No packages published
Used by 905k
@remomax
@linhh-phv
@thibs12
@NeptuneX-Aggregator
@tnikFi
@skyrych
@VincentKobz
@kanandev2024
+ 905,172
Contributors 131
@vsvipul
@kotewar
@joshmgross
@dhadka
@lvpx
@Phantsure
@aiqiaoy
@bishal-pdMSFT
@takost
@bethanyj28
@t-dedah
@magnetikonline
@ashwinsangem
@konradpabjan
+ 117 contributors
Deployments 2
releaseNewActionVersion March 19, 2024 17:55
Languages
JavaScript 0.9%
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
actions/cache: Cache dependencies and build outputs in GitHub Actions
Code
Issues 92
Pull requests 41
Discussions
Actions
Security
README
Code of conduct
MIT license
TypeScript 97.9%
Shell 1.2%
On Wed, Mar 20, 2024 at 12:55PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
Marketplace
Actions
Cache
GitHub Action
Cache
v4.0.2 Latest version
Cache action
This action allows caching dependencies and build outputs to improve workflow execution time.
Two other actions are available in addition to the primary cache action:
Restore action
Save action
Tests
Documentation
See "Caching dependencies to speed up workflows".
What's New
v4
Updated to node 20
Added a save-always flag to save the cache even if a prior step fails
v3
Added support for caching in GHES 3.5+.
Fixed download issue for files > 2GB during restore.
Updated the minimum runner version support from node 12 -> node 16.
Fixed avoiding empty cache save when no files are available for caching.
Fixed tar creation error while trying to create tar with path as ~/ home folder on ubuntu-latest.
Fixed zstd failing on amazon linux 2.0 runners.
Fixed cache not working with github workspace directory or current directory.
Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
Fix zstd not working for windows on gnu tar in issues.
Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable SEGMENT_DOWNLOAD_TIMEOUT_MINS. Default is 10 minutes.
New actions are available for granular control over caches - restore and save.
Support cross-os caching as an opt-in feature. See Cross OS caching for more info.
Added option to fail job on cache miss. See Exit workflow on cache miss for more info.
Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners
Added option to lookup cache without downloading it.
Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
See the v2 README.md for older updates.
Usage
Pre-requisites
Create a workflow .yml file in your repository's .github/workflows directory. An example workflow is available below. For more information, see the GitHub Help Documentation for Creating a workflow file.
If you are using this inside a container, a POSIX-compliant tar needs to be included and accessible from the execution path.
If you are using a self-hosted Windows runner, GNU tar and zstd are required for Cross-OS caching to work. They are also recommended to be installed in general so the performance is on par with hosted Windows runners.
Inputs
key - An explicit key for a cache entry. See creating a cache key.
path - A list of files, directories, and wildcard patterns to cache and 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.
enableCrossOsArchive - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
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. Does not change save cache behavior. Default: false
Environment Variables
SEGMENT_DOWNLOAD_TIMEOUT_MINS - Segment download timeout (in minutes, default 10) to abort download of the segment if not completed in the defined number of minutes. Read more
Outputs
cache-hit - A boolean value to indicate an exact match was found for the key.
Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example cache workflow
Restoring and saving cache using a single action
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
The cache action provides a cache-hit output which is set to true when the cache is restored using the primary key and false when the cache is restored using restore-keys or no cache is restored.
Using a combination of restore and save actions
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-primes
.
. //intermediate workflow steps
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
Note You must use the cache or restore action in your workflow before you need to use the files that might be restored from the cache. If the provided key matches an existing cache, a new cache is not created and if the provided key doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
Caching Strategies
With the introduction of the restore and save actions, a lot of caching use cases can now be achieved. Please see the caching strategies document for understanding how you can use the actions strategically to achieve the desired goal.
Implementation Examples
Every programming language and framework has its own way of caching.
See Examples for a list of actions/cache implementations for use with:
C# - NuGet
Clojure - Lein Deps
D - DUB
Deno
Elixir - Mix
Go - Modules
Haskell - Cabal
Haskell - Stack
Java - Gradle
Java - Maven
Node - npm
Node - Lerna
Node - Yarn
OCaml/Reason - esy
PHP - Composer
Python - pip
Python - pipenv
R - renv
Ruby - Bundler
Rust - Cargo
Scala - SBT
Swift, Objective-C - Carthage
Swift, Objective-C - CocoaPods
Swift - Swift Package Manager
Swift - Mint
Creating a cache key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles function allows you to create a new cache when dependencies change.
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
See Using contexts to create cache keys
Cache Limits
A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.
Skipping steps based on cache-hit
Using the cache-hit output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install missing/updated dependencies in case of a partial key match when the key is dependent on the hash of the package file.
Example:
steps:
- uses: actions/checkout@v3
- uses: actions/cache@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
Note The id defined in actions/cache must match the id in the if statement (i.e. steps.[ID].outputs.cache-hit)
Cache Version
Cache version is a hash generated for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.
Pro tip: The list caches API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
Example The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
Known practices and workarounds
There are a number of community practices/workarounds to fulfill specific requirements. You may choose to use them if they suit your use case. Note these are not necessarily the only solution or even a recommended solution.
Cache segment restore timeout
Update a cache
Use cache across feature branches
Cross OS cache
Force deletion of caches overriding default cache eviction policy
Windows environment variables
Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to the HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see the Learn GitHub Actions: Variables page.
Contributing
We would love for you to contribute to actions/cache. Pull requests are welcome! Please see the CONTRIBUTING.md for more information.
License
The scripts and documentation in this project are released under the MIT License
Verified creator
GitHub has verified that this action was created by actions.
Learn more about verified Actions.
Stars
Contributors
@vsvipul @kotewar @joshmgross @dhadka @lvpx @Phantsure @aiqiaoy @bishal-pdMSFT @takost @bethanyj28 @t-dedah @magnetikonline
Categories
Dependency management Utilities
Links
actions/cache Open issues 92 Pull requests 41
Report abuse
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
On Wed, Mar 20, 2024 at 12:54PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
Skip to content
tshingombe-engineering /
engin-data-exam-tshingomb
Settings
Creating a new workflow file in engin-data-exam-tshingomb
Breadcrumbs
engin-data-exam-tshingomb
/.github
/workflows
/
in
main
Indent mode
Indent sizeLine wrap mode
Editing blank.yml file contents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
Use Control + Shift + m to toggle the tab key moving focus. Alternatively, use esc then tab to move to the next interactive element on the page.
Use Control + Space to trigger autocomplete in most situations.
Help Panel navigation
Marketplace
Documentation
/ Cache
Cache
By actions
v4.0.2
4.2k
Cache artifacts like dependencies and build outputs to improve workflow execution time
View full Marketplace listing
Installation
Copy and paste the following snippet into your .yml file.
Version: v4.0.2
- name: Cache
uses: actions/cache@v4.0.2
with:
# A list of files, directories, and wildcard patterns to cache and restore
path:
# An explicit key for restoring and saving the cache
key:
# An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.
restore-keys: # optional
# The chunk size used to split up large files during upload, in bytes
upload-chunk-size: # optional
# An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms
enableCrossOsArchive: # optional, default is false
# Fail the workflow if cache entry is not found
fail-on-cache-miss: # optional, default is false
# Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache
lookup-only: # optional, default is false
# Run the post step to save the cache even if another step before fails
save-always: # optional, default is false
Code
Issues
Pull requests
Actions
Projects
Security
Insights
On Wed, Mar 20, 2024 at 12:53PM tshingombe fiston <tshingombefiston@gmail.com> wrote:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
On Tue, Mar 19, 2024 at 9:49PM tshingombe <notifications@github.com> wrote:
GitHub
[t5h2i0tadi/engineering-tshing-binair-archfile-] CodeQL workflow run
CodeQL: No jobs were run
View workflow run
You are receiving this because you are subscribed to this thread.
Manage your GitHub Actions notifications
GitHub, Inc. ・88 Colin P Kelly Jr Street ・San Francisco, CA 94107
...
[Message clipped] View entire message
tshingombe fiston
1:03PM (2 minutes ago)
to t5h2i0tadi/engineering-tshing-binair-archfile-
Skip to content
actions /
cache
Insights
Actions: actions/cache
Actions
Caches
Showing caches from all workflows. Learn more about managing caches.
16 caches
codeql-trap-1-2.16.4-javascript-0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 87 MB cached March 19, 2024 06:34
main
Last used March 19, 2024 08:56
node-cache-Windows-npm-406f79a9138a96d98486e00bf340617c9a5915a3f7107682f8ac70d9540a19d5 29 MB cached March 19, 2024 06:33
main
Last used March 19, 2024 06:33
node-cache-macOS-npm-406f79a9138a96d98486e00bf340617c9a5915a3f7107682f8ac70d9540a19d5 29 MB cached March 19, 2024 06:32
main
Last used March 19, 2024 06:32
node-cache-Linux-npm-406f79a9138a96d98486e00bf340617c9a5915a3f7107682f8ac70d9540a19d5 29 MB cached March 19, 2024 06:32
main
Last used March 19, 2024 06:32
test-Windows-8343936870 367 Bytes cached March 19, 2024 06:32
main
Last used March 19, 2024 06:32
test-proxy-8343936870 286 Bytes cached March 19, 2024 06:32
main
Last used March 19, 2024 06:32
test-macOS-8343936870 382 Bytes cached March 19, 2024 06:32
main
Last used March 19, 2024 06:32
test-Linux-8343936870 368 Bytes cached March 19, 2024 06:32
main
Last used March 19, 2024 06:32
node-cache-Windows-npm-406f79a9138a96d98486e00bf340617c9a5915a3f7107682f8ac70d9540a19d5 29 MB cached March 19, 2024 01:31
refs/pull/1327/merge
Last used March 19, 2024 01:31
node-cache-macOS-npm-406f79a9138a96d98486e00bf340617c9a5915a3f7107682f8ac70d9540a19d5 29 MB cached March 19, 2024 01:30
refs/pull/1327/merge
Last used March 19, 2024 01:30
codeql-trap-1-2.16.4-javascript-ab5e6d0c87105b4c9c2047343972218f562e4319 87 MB cached March 17, 2024 12:02
main
Last used March 19, 2024 01:30
node-cache-Linux-npm-406f79a9138a96d98486e00bf340617c9a5915a3f7107682f8ac70d9540a19d5 29 MB cached March 19, 2024 01:30
refs/pull/1327/merge
Last used March 19, 2024 01:30
test-Windows-8339832816 336 Bytes cached March 19, 2024 01:30
refs/pull/1327/merge
Last used March 19, 2024 01:30
test-proxy-8339832816 284 Bytes cached March 19, 2024 01:30
refs/pull/1327/merge
Last used March 19, 2024 01:30
test-Linux-8339832816 391 Bytes cached March 19, 2024 01:30
refs/pull/1327/merge
Last used March 19, 2024 01:30
test-macOS-8339832816 415 Bytes cached March 19, 2024 01:30
refs/pull/1327/merge
Last used March 19, 2024 01:30
Footer
© 2024 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
Workflow runs · actions/cache
Code
Issues 92
Pull requests 41
Discussions
Actions
Security
Workflows
Management
...
[Message clipped] View entire message