mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-19 19:46:17 +02:00
Merge pull request #1 from prncevince/prncevince/reeval
Add boolean inputs to: * reevaluate cache's primary key * only restore the cache (not save it)
This commit is contained in:
commit
9840f83c99
7 changed files with 192 additions and 90 deletions
74
.github/workflows/workflow.yml
vendored
74
.github/workflows/workflow.yml
vendored
|
@ -53,6 +53,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
|
reeval: [false, true]
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
@ -67,10 +68,36 @@ jobs:
|
||||||
- name: Save cache
|
- name: Save cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
key: test-${{ runner.os }}-${{ github.run_id }}
|
reeval: ${{ matrix.reeval }}
|
||||||
|
key: test-${{ runner.os }}-${{ github.run_id }}-${{ matrix.reeval }}
|
||||||
path: |
|
path: |
|
||||||
test-cache
|
test-cache
|
||||||
~/test-cache
|
~/test-cache
|
||||||
|
test-only-restore:
|
||||||
|
needs: test-save
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
|
fail-fast: false
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Restore cache
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
only-restore: true
|
||||||
|
reeval: ${{ matrix.reeval }}
|
||||||
|
key: test-${{ runner.os }}-${{ github.run_id }}-${{ matrix.reeval }}
|
||||||
|
path: |
|
||||||
|
test-cache
|
||||||
|
~/test-cache
|
||||||
|
- name: Verify cache files in working directory
|
||||||
|
shell: bash
|
||||||
|
run: __tests__/verify-cache-files.sh ${{ runner.os }} test-cache
|
||||||
|
- name: Verify cache files outside working directory
|
||||||
|
shell: bash
|
||||||
|
run: __tests__/verify-cache-files.sh ${{ runner.os }} ~/test-cache
|
||||||
test-restore:
|
test-restore:
|
||||||
needs: test-save
|
needs: test-save
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -84,7 +111,8 @@ jobs:
|
||||||
- name: Restore cache
|
- name: Restore cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
key: test-${{ runner.os }}-${{ github.run_id }}
|
reeval: ${{ matrix.reeval }}
|
||||||
|
key: test-${{ runner.os }}-${{ github.run_id }}-${{ matrix.reeval }}
|
||||||
path: |
|
path: |
|
||||||
test-cache
|
test-cache
|
||||||
~/test-cache
|
~/test-cache
|
||||||
|
@ -97,6 +125,9 @@ jobs:
|
||||||
|
|
||||||
# End to end with proxy
|
# End to end with proxy
|
||||||
test-proxy-save:
|
test-proxy-save:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
reeval: [false, true]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: ubuntu:latest
|
image: ubuntu:latest
|
||||||
|
@ -116,10 +147,14 @@ jobs:
|
||||||
- name: Save cache
|
- name: Save cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
key: test-proxy-${{ github.run_id }}
|
reeval: ${{ matrix.reeval }}
|
||||||
|
key: test-proxy-${{ github.run_id }}-${{ matrix.reeval }}
|
||||||
path: test-cache
|
path: test-cache
|
||||||
test-proxy-restore:
|
test-proxy-only-restore:
|
||||||
needs: test-proxy-save
|
needs: test-proxy-save
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
reeval: [false, true]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: ubuntu:latest
|
image: ubuntu:latest
|
||||||
|
@ -137,7 +172,36 @@ jobs:
|
||||||
- name: Restore cache
|
- name: Restore cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
key: test-proxy-${{ github.run_id }}
|
only-restore: true
|
||||||
|
reeval: ${{ matrix.reeval }}
|
||||||
|
key: test-proxy-${{ github.run_id }}-${{ matrix.reeval }}
|
||||||
|
path: test-cache
|
||||||
|
- name: Verify cache
|
||||||
|
run: __tests__/verify-cache-files.sh proxy test-cache
|
||||||
|
test-proxy-restore:
|
||||||
|
needs: test-proxy-save
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
reeval: [false, true]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ubuntu:latest
|
||||||
|
options: --dns 127.0.0.1
|
||||||
|
services:
|
||||||
|
squid-proxy:
|
||||||
|
image: datadog/squid:latest
|
||||||
|
ports:
|
||||||
|
- 3128:3128
|
||||||
|
env:
|
||||||
|
https_proxy: http://squid-proxy:3128
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Restore cache
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
reeval: ${{ matrix.reeval }}
|
||||||
|
key: test-proxy-${{ github.run_id }}-${{ matrix.reeval }}
|
||||||
path: test-cache
|
path: test-cache
|
||||||
- name: Verify cache
|
- name: Verify cache
|
||||||
run: __tests__/verify-cache-files.sh proxy test-cache
|
run: __tests__/verify-cache-files.sh proxy test-cache
|
||||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -94,3 +94,6 @@ typings/
|
||||||
|
|
||||||
# Text editor files
|
# Text editor files
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -14,6 +14,14 @@ inputs:
|
||||||
upload-chunk-size:
|
upload-chunk-size:
|
||||||
description: 'The chunk size used to split up large files during upload, in bytes'
|
description: 'The chunk size used to split up large files during upload, in bytes'
|
||||||
required: false
|
required: false
|
||||||
|
reeval:
|
||||||
|
description: "Boolean. Whether to reevaluate the key argument in post. Set to TRUE if you would like your cache key set after your job's steps are complete."
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
only-restore:
|
||||||
|
description: 'Boolean. Whether to only perform cache restoration and NOT the save post run step.'
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||||
|
|
2
dist/restore/index.js
vendored
2
dist/restore/index.js
vendored
|
@ -4607,7 +4607,9 @@ exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inpu
|
||||||
var Inputs;
|
var Inputs;
|
||||||
(function (Inputs) {
|
(function (Inputs) {
|
||||||
Inputs["Key"] = "key";
|
Inputs["Key"] = "key";
|
||||||
|
Inputs["OnlyRestore"] = "only-restore";
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
|
Inputs["Reeval"] = "reeval";
|
||||||
Inputs["RestoreKeys"] = "restore-keys";
|
Inputs["RestoreKeys"] = "restore-keys";
|
||||||
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
|
|
17
dist/save/index.js
vendored
17
dist/save/index.js
vendored
|
@ -4607,7 +4607,9 @@ exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inpu
|
||||||
var Inputs;
|
var Inputs;
|
||||||
(function (Inputs) {
|
(function (Inputs) {
|
||||||
Inputs["Key"] = "key";
|
Inputs["Key"] = "key";
|
||||||
|
Inputs["OnlyRestore"] = "only-restore";
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
|
Inputs["Reeval"] = "reeval";
|
||||||
Inputs["RestoreKeys"] = "restore-keys";
|
Inputs["RestoreKeys"] = "restore-keys";
|
||||||
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
|
@ -46770,6 +46772,8 @@ const utils = __importStar(__webpack_require__(443));
|
||||||
process.on("uncaughtException", e => utils.logWarning(e.message));
|
process.on("uncaughtException", e => utils.logWarning(e.message));
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const save = !core.getBooleanInput(constants_1.Inputs.OnlyRestore);
|
||||||
|
if (save) {
|
||||||
try {
|
try {
|
||||||
if (!utils.isCacheFeatureAvailable()) {
|
if (!utils.isCacheFeatureAvailable()) {
|
||||||
return;
|
return;
|
||||||
|
@ -46779,8 +46783,16 @@ function run() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const state = utils.getCacheState();
|
const state = utils.getCacheState();
|
||||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
let primaryKey = "";
|
||||||
const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
|
const reeval = core.getBooleanInput(constants_1.Inputs.Reeval);
|
||||||
|
if (!reeval) {
|
||||||
|
// Inputs are reevaluted before the post action, so we want the original key used for restore
|
||||||
|
primaryKey = core.getState(constants_1.State.CachePrimaryKey);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// choose to reevaluate primary key
|
||||||
|
primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
||||||
|
}
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
utils.logWarning(`Error retrieving key from state.`);
|
||||||
return;
|
return;
|
||||||
|
@ -46814,6 +46826,7 @@ function run() {
|
||||||
catch (error) {
|
catch (error) {
|
||||||
utils.logWarning(error.message);
|
utils.logWarning(error.message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
run();
|
run();
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
export enum Inputs {
|
export enum Inputs {
|
||||||
Key = "key",
|
Key = "key",
|
||||||
|
OnlyRestore = "only-restore",
|
||||||
Path = "path",
|
Path = "path",
|
||||||
|
Reeval = "reeval",
|
||||||
RestoreKeys = "restore-keys",
|
RestoreKeys = "restore-keys",
|
||||||
UploadChunkSize = "upload-chunk-size"
|
UploadChunkSize = "upload-chunk-size"
|
||||||
}
|
}
|
||||||
|
|
14
src/save.ts
14
src/save.ts
|
@ -10,6 +10,8 @@ import * as utils from "./utils/actionUtils";
|
||||||
process.on("uncaughtException", e => utils.logWarning(e.message));
|
process.on("uncaughtException", e => utils.logWarning(e.message));
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
|
const save = !core.getBooleanInput(Inputs.OnlyRestore);
|
||||||
|
if (save) {
|
||||||
try {
|
try {
|
||||||
if (!utils.isCacheFeatureAvailable()) {
|
if (!utils.isCacheFeatureAvailable()) {
|
||||||
return;
|
return;
|
||||||
|
@ -26,8 +28,15 @@ async function run(): Promise<void> {
|
||||||
|
|
||||||
const state = utils.getCacheState();
|
const state = utils.getCacheState();
|
||||||
|
|
||||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
let primaryKey = "";
|
||||||
const primaryKey = core.getState(State.CachePrimaryKey);
|
const reeval = core.getBooleanInput(Inputs.Reeval);
|
||||||
|
if (!reeval) {
|
||||||
|
// Inputs are reevaluted before the post action, so we want the original key used for restore
|
||||||
|
primaryKey = core.getState(State.CachePrimaryKey);
|
||||||
|
} else {
|
||||||
|
// choose to reevaluate primary key
|
||||||
|
primaryKey = core.getInput(Inputs.Key, { required: true });
|
||||||
|
}
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
utils.logWarning(`Error retrieving key from state.`);
|
||||||
return;
|
return;
|
||||||
|
@ -63,6 +72,7 @@ async function run(): Promise<void> {
|
||||||
utils.logWarning((error as Error).message);
|
utils.logWarning((error as Error).message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue