mirror of
https://github.com/actions/cache.git
synced 2026-06-08 16:50:28 +08:00
Compare commits
4 Commits
yacaovsnc/
...
7dd9af18b0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7dd9af18b0 | ||
|
|
a2ed59d39b | ||
|
|
dc88ab52d7 | ||
|
|
1d78355196 |
22
README.md
22
README.md
@@ -14,6 +14,10 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
|
||||
|
||||
## What's New
|
||||
|
||||
### Unreleased
|
||||
|
||||
* Added the `force-overwrite` flag to force overwrite any existing cache for incremental caching
|
||||
|
||||
### v4
|
||||
|
||||
* Updated to node 20
|
||||
@@ -95,7 +99,7 @@ jobs:
|
||||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: ${{ runner.os }}-primes
|
||||
@@ -126,7 +130,7 @@ jobs:
|
||||
|
||||
- name: Restore cached Primes
|
||||
id: cache-primes-restore
|
||||
uses: actions/cache/restore@v3
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -137,7 +141,7 @@ jobs:
|
||||
.
|
||||
- name: Save Primes
|
||||
id: cache-primes-save
|
||||
uses: actions/cache/save@v3
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -191,7 +195,7 @@ A cache key can include any of the contexts, functions, literals, and operators
|
||||
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@v3
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -209,7 +213,7 @@ Additionally, you can use arbitrary command output in a cache key, such as a dat
|
||||
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
- uses: actions/cache@v3
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
|
||||
@@ -231,7 +235,7 @@ Example:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/cache@v3
|
||||
- uses: actions/cache@v4
|
||||
id: cache
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
@@ -263,7 +267,7 @@ jobs:
|
||||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: primes
|
||||
@@ -274,7 +278,7 @@ jobs:
|
||||
|
||||
- name: Cache Numbers
|
||||
id: cache-numbers
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: numbers
|
||||
key: primes
|
||||
@@ -290,7 +294,7 @@ jobs:
|
||||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: primes
|
||||
|
||||
@@ -29,7 +29,11 @@ inputs:
|
||||
save-always:
|
||||
description: 'Run the post step to save the cache even if another step before fails'
|
||||
default: 'false'
|
||||
required: false
|
||||
required: false
|
||||
force-overwrite:
|
||||
description: 'Delete any previous (incremental) cache before pushing a new cache even if a cache for the primary cache key exists'
|
||||
default: 'false'
|
||||
required: false
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||
|
||||
@@ -5,7 +5,8 @@ export enum Inputs {
|
||||
UploadChunkSize = "upload-chunk-size", // Input for cache, save action
|
||||
EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action
|
||||
FailOnCacheMiss = "fail-on-cache-miss", // Input for cache, restore action
|
||||
LookupOnly = "lookup-only" // Input for cache, restore action
|
||||
LookupOnly = "lookup-only", // Input for cache, restore action
|
||||
ForceOverwrite = "force-overwrite" // Input for cache action
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
StateProvider
|
||||
} from "./stateProvider";
|
||||
import * as utils from "./utils/actionUtils";
|
||||
import { issueCommand } from "@actions/core/lib/command";
|
||||
|
||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
||||
@@ -47,13 +48,18 @@ export async function saveImpl(
|
||||
// NO-OP in case of SaveOnly action
|
||||
const restoredKey = stateProvider.getCacheState();
|
||||
|
||||
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
|
||||
const forceOverwrite = utils.getInputAsBool(Inputs.ForceOverwrite);
|
||||
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
`Cache hit occurred on the primary key ${primaryKey} and force-overwrite is disabled, not saving cache.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (utils.isExactKeyMatch(primaryKey, restoredKey) && forceOverwrite) {
|
||||
await issueCommand('actions-cache delete', {}, primaryKey);
|
||||
}
|
||||
|
||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||
required: true
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user