mirror of
https://github.com/actions/cache.git
synced 2025-06-27 21:01:11 +02:00
Compare commits
5 Commits
joshmgross
...
v1.0.2
Author | SHA1 | Date | |
---|---|---|---|
44543250bd | |||
6491e51b66 | |||
86dff562ab | |||
0f810ad45a | |||
9d8c7b4041 |
23
README.md
23
README.md
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This GitHub Action allows caching dependencies and build outputs to improve workflow execution time.
|
This GitHub Action allows caching dependencies and build outputs to improve workflow execution time.
|
||||||
|
|
||||||
<a href="https://github.com/actions/cache/actions?query=workflow%3ATests"><img alt="GitHub Actions status" src="https://github.com/actions/cache/workflows/Tests/badge.svg?branch=master&event=push"></a>
|
<a href="https://github.com/actions/cache"><img alt="GitHub Actions status" src="https://github.com/actions/cache/workflows/Tests/badge.svg?branch=master&event=push"></a>
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
@ -54,26 +54,9 @@ jobs:
|
|||||||
run: /primes.sh -d prime-numbers
|
run: /primes.sh -d prime-numbers
|
||||||
```
|
```
|
||||||
|
|
||||||
## Implementation Examples
|
## Ecosystem Examples
|
||||||
|
|
||||||
Every programming language and framework has it's own way of caching.
|
|
||||||
|
|
||||||
See [Examples](examples.md) for a list of `actions/cache` implementations for use with:
|
|
||||||
|
|
||||||
- [C# - Nuget](./examples.md#c---nuget)
|
|
||||||
- [Elixir - Mix](./examples.md#elixir---mix)
|
|
||||||
- [Go - Modules](./examples.md#go---modules)
|
|
||||||
- [Java - Gradle](./examples.md#java---gradle)
|
|
||||||
- [Java - Maven](./examples.md#java---maven)
|
|
||||||
- [Node - npm](./examples.md#node---npm)
|
|
||||||
- [Node - Yarn](./examples.md#node---yarn)
|
|
||||||
- [PHP - Composer](./examples.md#php---composer)
|
|
||||||
- [Python - pip](./examples.md#python---pip)
|
|
||||||
- [Ruby - Gem](./examples.md#ruby---gem)
|
|
||||||
- [Rust - Cargo](./examples.md#rust---cargo)
|
|
||||||
- [Swift, Objective-C - Carthage](./examples.md#swift-objective-c---carthage)
|
|
||||||
- [Swift, Objective-C - CocoaPods](./examples.md#swift-objective-c---cocoapods)
|
|
||||||
|
|
||||||
|
See [Examples](examples.md)
|
||||||
|
|
||||||
## Cache Limits
|
## Cache Limits
|
||||||
|
|
||||||
|
@ -162,16 +162,6 @@ test("getCacheState with valid state", () => {
|
|||||||
expect(getStateMock).toHaveBeenCalledTimes(1);
|
expect(getStateMock).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("logWarning logs a message with a warning prefix", () => {
|
|
||||||
const message = "A warning occurred.";
|
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
|
||||||
|
|
||||||
actionUtils.logWarning(message);
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("isValidEvent returns false for unknown event", () => {
|
test("isValidEvent returns false for unknown event", () => {
|
||||||
const event = "foo";
|
const event = "foo";
|
||||||
process.env[Events.Key] = event;
|
process.env[Events.Key] = event;
|
||||||
|
@ -50,16 +50,14 @@ afterEach(() => {
|
|||||||
delete process.env[Events.Key];
|
delete process.env[Events.Key];
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with invalid event outputs warning", async () => {
|
test("restore with invalid event", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const invalidEvent = "commit_comment";
|
const invalidEvent = "commit_comment";
|
||||||
process.env[Events.Key] = invalidEvent;
|
process.env[Events.Key] = invalidEvent;
|
||||||
await run();
|
await run();
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(failedMock).toHaveBeenCalledWith(
|
||||||
`Event Validation Error: The event type ${invalidEvent} is not supported. Only push, pull_request events are supported at this time.`
|
`Event Validation Error: The event type ${invalidEvent} is not supported. Only push, pull_request events are supported at this time.`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with no path should fail", async () => {
|
test("restore with no path should fail", async () => {
|
||||||
@ -128,6 +126,7 @@ test("restore with no cache found", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -139,6 +138,7 @@ test("restore with no cache found", async () => {
|
|||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
@ -153,7 +153,7 @@ test("restore with server error should fail", async () => {
|
|||||||
key
|
key
|
||||||
});
|
});
|
||||||
|
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -168,8 +168,8 @@ test("restore with server error should fail", async () => {
|
|||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
expect(warningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
|
||||||
@ -187,6 +187,7 @@ test("restore with restore keys and no cache found", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -198,6 +199,7 @@ test("restore with restore keys and no cache found", async () => {
|
|||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
@ -214,6 +216,7 @@ test("restore with cache found", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -255,10 +258,7 @@ test("restore with cache found", async () => {
|
|||||||
expect(getCacheMock).toHaveBeenCalledWith([key]);
|
expect(getCacheMock).toHaveBeenCalledWith([key]);
|
||||||
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(
|
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
||||||
cacheEntry.archiveLocation,
|
|
||||||
archivePath
|
|
||||||
);
|
|
||||||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
||||||
|
|
||||||
@ -281,6 +281,7 @@ test("restore with cache found", async () => {
|
|||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -295,6 +296,7 @@ test("restore with a pull request event and cache found", async () => {
|
|||||||
process.env[Events.Key] = Events.PullRequest;
|
process.env[Events.Key] = Events.PullRequest;
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -336,10 +338,7 @@ test("restore with a pull request event and cache found", async () => {
|
|||||||
expect(getCacheMock).toHaveBeenCalledWith([key]);
|
expect(getCacheMock).toHaveBeenCalledWith([key]);
|
||||||
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(
|
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
||||||
cacheEntry.archiveLocation,
|
|
||||||
archivePath
|
|
||||||
);
|
|
||||||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`);
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
||||||
@ -363,6 +362,7 @@ test("restore with a pull request event and cache found", async () => {
|
|||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -377,6 +377,7 @@ test("restore with cache found for restore key", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -418,10 +419,7 @@ test("restore with cache found for restore key", async () => {
|
|||||||
expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey]);
|
expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey]);
|
||||||
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(
|
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
||||||
cacheEntry.archiveLocation,
|
|
||||||
archivePath
|
|
||||||
);
|
|
||||||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`);
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
||||||
@ -447,5 +445,6 @@ test("restore with cache found for restore key", async () => {
|
|||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
);
|
);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,7 @@ import * as exec from "@actions/exec";
|
|||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as cacheHttpClient from "../src/cacheHttpClient";
|
import * as cacheHttpClient from "../src/cacheHttpClient";
|
||||||
import { Events, Inputs } from "../src/constants";
|
import { Inputs } from "../src/constants";
|
||||||
import { ArtifactCacheEntry } from "../src/contracts";
|
import { ArtifactCacheEntry } from "../src/contracts";
|
||||||
import run from "../src/save";
|
import run from "../src/save";
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
import * as actionUtils from "../src/utils/actionUtils";
|
||||||
@ -32,16 +32,6 @@ beforeAll(() => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.isValidEvent();
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getSupportedEvents").mockImplementation(() => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.getSupportedEvents();
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "resolvePath").mockImplementation(filePath => {
|
jest.spyOn(actionUtils, "resolvePath").mockImplementation(filePath => {
|
||||||
return path.resolve(filePath);
|
return path.resolve(filePath);
|
||||||
});
|
});
|
||||||
@ -55,29 +45,12 @@ beforeAll(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env[Events.Key] = Events.Push;
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
testUtils.clearInputs();
|
testUtils.clearInputs();
|
||||||
delete process.env[Events.Key];
|
|
||||||
});
|
|
||||||
|
|
||||||
test("save with invalid event outputs warning", async () => {
|
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const invalidEvent = "commit_comment";
|
|
||||||
process.env[Events.Key] = invalidEvent;
|
|
||||||
await run();
|
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
|
||||||
`Event Validation Error: The event type ${invalidEvent} is not supported. Only push, pull_request events are supported at this time.`
|
|
||||||
);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with no primary key in state outputs warning", async () => {
|
test("save with no primary key in state outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const cacheEntry: ArtifactCacheEntry = {
|
const cacheEntry: ArtifactCacheEntry = {
|
||||||
@ -99,15 +72,16 @@ test("save with no primary key in state outputs warning", async () => {
|
|||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(warningMock).toHaveBeenCalledWith(
|
||||||
`Error retrieving key from state.`
|
`Error retrieving key from state.`
|
||||||
);
|
);
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with exact match returns early", async () => {
|
test("save with exact match returns early", async () => {
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -138,11 +112,12 @@ test("save with exact match returns early", async () => {
|
|||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(0);
|
expect(execMock).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with missing input outputs warning", async () => {
|
test("save with missing input outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -165,15 +140,15 @@ test("save with missing input outputs warning", async () => {
|
|||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(warningMock).toHaveBeenCalledWith(
|
||||||
"Input required and not supplied: path"
|
"Input required and not supplied: path"
|
||||||
);
|
);
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with large cache outputs warning", async () => {
|
test("save with large cache outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -200,7 +175,7 @@ test("save with large cache outputs warning", async () => {
|
|||||||
|
|
||||||
const execMock = jest.spyOn(exec, "exec");
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
|
|
||||||
const cacheSize = 4 * 1024 * 1024 * 1024; //~4GB, over the 2GB limit
|
const cacheSize = 1024 * 1024 * 1024; //~1GB, over the 400MB limit
|
||||||
jest.spyOn(actionUtils, "getArchiveFileSize").mockImplementationOnce(() => {
|
jest.spyOn(actionUtils, "getArchiveFileSize").mockImplementationOnce(() => {
|
||||||
return cacheSize;
|
return cacheSize;
|
||||||
});
|
});
|
||||||
@ -212,29 +187,29 @@ test("save with large cache outputs warning", async () => {
|
|||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
const args = IS_WINDOWS
|
const args = IS_WINDOWS
|
||||||
? [
|
? [
|
||||||
"-cz",
|
"-cz",
|
||||||
"--force-local",
|
"--force-local",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath.replace(/\\/g, "/"),
|
archivePath.replace(/\\/g, "/"),
|
||||||
"-C",
|
"-C",
|
||||||
cachePath.replace(/\\/g, "/"),
|
cachePath.replace(/\\/g, "/"),
|
||||||
"."
|
"."
|
||||||
]
|
]
|
||||||
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1);
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(warningMock).toHaveBeenCalledWith(
|
||||||
"Cache size of ~4 GB (4294967296 B) is over the 2GB limit, not saving cache."
|
"Cache size of ~1024 MB (1073741824 B) is over the 400MB limit, not saving cache."
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with server error outputs warning", async () => {
|
test("save with server error outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -259,11 +234,6 @@ test("save with server error outputs warning", async () => {
|
|||||||
const cachePath = path.resolve(inputPath);
|
const cachePath = path.resolve(inputPath);
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
|
|
||||||
const cacheId = 4;
|
|
||||||
const reserveCacheMock = jest.spyOn(cacheHttpClient, "reserveCache").mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(cacheId);
|
|
||||||
});
|
|
||||||
|
|
||||||
const execMock = jest.spyOn(exec, "exec");
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
|
|
||||||
const saveCacheMock = jest
|
const saveCacheMock = jest
|
||||||
@ -274,37 +244,35 @@ test("save with server error outputs warning", async () => {
|
|||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(reserveCacheMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey);
|
|
||||||
|
|
||||||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
const args = IS_WINDOWS
|
const args = IS_WINDOWS
|
||||||
? [
|
? [
|
||||||
"-cz",
|
"-cz",
|
||||||
"--force-local",
|
"--force-local",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath.replace(/\\/g, "/"),
|
archivePath.replace(/\\/g, "/"),
|
||||||
"-C",
|
"-C",
|
||||||
cachePath.replace(/\\/g, "/"),
|
cachePath.replace(/\\/g, "/"),
|
||||||
"."
|
"."
|
||||||
]
|
]
|
||||||
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1);
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(cacheId, archivePath);
|
expect(saveCacheMock).toHaveBeenCalledWith(primaryKey, archivePath);
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
expect(warningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with valid inputs uploads a cache", async () => {
|
test("save with valid inputs uploads a cache", async () => {
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -329,40 +297,33 @@ test("save with valid inputs uploads a cache", async () => {
|
|||||||
const cachePath = path.resolve(inputPath);
|
const cachePath = path.resolve(inputPath);
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
|
|
||||||
const cacheId = 4;
|
|
||||||
const reserveCacheMock = jest.spyOn(cacheHttpClient, "reserveCache").mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(cacheId);
|
|
||||||
});
|
|
||||||
|
|
||||||
const execMock = jest.spyOn(exec, "exec");
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
|
|
||||||
const saveCacheMock = jest.spyOn(cacheHttpClient, "saveCache");
|
const saveCacheMock = jest.spyOn(cacheHttpClient, "saveCache");
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(reserveCacheMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey);
|
|
||||||
|
|
||||||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
const args = IS_WINDOWS
|
const args = IS_WINDOWS
|
||||||
? [
|
? [
|
||||||
"-cz",
|
"-cz",
|
||||||
"--force-local",
|
"--force-local",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath.replace(/\\/g, "/"),
|
archivePath.replace(/\\/g, "/"),
|
||||||
"-C",
|
"-C",
|
||||||
cachePath.replace(/\\/g, "/"),
|
cachePath.replace(/\\/g, "/"),
|
||||||
"."
|
"."
|
||||||
]
|
]
|
||||||
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1);
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(cacheId, archivePath);
|
expect(saveCacheMock).toHaveBeenCalledWith(primaryKey, archivePath);
|
||||||
|
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
161
dist/restore/index.js
vendored
161
dist/restore/index.js
vendored
@ -1496,57 +1496,48 @@ const fs = __importStar(__webpack_require__(747));
|
|||||||
const Handlers_1 = __webpack_require__(941);
|
const Handlers_1 = __webpack_require__(941);
|
||||||
const HttpClient_1 = __webpack_require__(874);
|
const HttpClient_1 = __webpack_require__(874);
|
||||||
const RestClient_1 = __webpack_require__(105);
|
const RestClient_1 = __webpack_require__(105);
|
||||||
const utils = __importStar(__webpack_require__(443));
|
function getCacheUrl() {
|
||||||
function isSuccessStatusCode(statusCode) {
|
|
||||||
return statusCode >= 200 && statusCode < 300;
|
|
||||||
}
|
|
||||||
function getCacheApiUrl() {
|
|
||||||
// Ideally we just use ACTIONS_CACHE_URL
|
// Ideally we just use ACTIONS_CACHE_URL
|
||||||
const baseUrl = (process.env["ACTIONS_CACHE_URL"] ||
|
const cacheUrl = (process.env["ACTIONS_CACHE_URL"] ||
|
||||||
process.env["ACTIONS_RUNTIME_URL"] ||
|
process.env["ACTIONS_RUNTIME_URL"] ||
|
||||||
"").replace("pipelines", "artifactcache");
|
"").replace("pipelines", "artifactcache");
|
||||||
if (!baseUrl) {
|
if (!cacheUrl) {
|
||||||
throw new Error("Cache Service Url not found, unable to restore cache.");
|
throw new Error("Cache Service Url not found, unable to restore cache.");
|
||||||
}
|
}
|
||||||
core.debug(`Cache Url: ${baseUrl}`);
|
core.debug(`Cache Url: ${cacheUrl}`);
|
||||||
return `${baseUrl}_apis/artifactcache/`;
|
return cacheUrl;
|
||||||
}
|
}
|
||||||
function createAcceptHeader(type, apiVersion) {
|
function createAcceptHeader(type, apiVersion) {
|
||||||
return `${type};api-version=${apiVersion}`;
|
return `${type};api-version=${apiVersion}`;
|
||||||
}
|
}
|
||||||
function getRequestOptions() {
|
function getRequestOptions() {
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
acceptHeader: createAcceptHeader("application/json", "6.0-preview.1")
|
acceptHeader: createAcceptHeader("application/json", "5.2-preview.1")
|
||||||
};
|
};
|
||||||
return requestOptions;
|
return requestOptions;
|
||||||
}
|
}
|
||||||
function createRestClient() {
|
|
||||||
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
|
||||||
const bearerCredentialHandler = new Handlers_1.BearerCredentialHandler(token);
|
|
||||||
return new RestClient_1.RestClient("actions/cache", getCacheApiUrl(), [
|
|
||||||
bearerCredentialHandler
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
function getCacheEntry(keys) {
|
function getCacheEntry(keys) {
|
||||||
var _a;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const restClient = createRestClient();
|
const cacheUrl = getCacheUrl();
|
||||||
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}`;
|
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||||
|
const bearerCredentialHandler = new Handlers_1.BearerCredentialHandler(token);
|
||||||
|
const resource = `_apis/artifactcache/cache?keys=${encodeURIComponent(keys.join(","))}`;
|
||||||
|
const restClient = new RestClient_1.RestClient("actions/cache", cacheUrl, [
|
||||||
|
bearerCredentialHandler
|
||||||
|
]);
|
||||||
const response = yield restClient.get(resource, getRequestOptions());
|
const response = yield restClient.get(resource, getRequestOptions());
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!isSuccessStatusCode(response.statusCode)) {
|
if (response.statusCode !== 200) {
|
||||||
throw new Error(`Cache service responded with ${response.statusCode}`);
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
}
|
}
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
const cacheDownloadUrl = (_a = cacheResult) === null || _a === void 0 ? void 0 : _a.archiveLocation;
|
|
||||||
if (!cacheDownloadUrl) {
|
|
||||||
throw new Error("Cache not found.");
|
|
||||||
}
|
|
||||||
core.setSecret(cacheDownloadUrl);
|
|
||||||
core.debug(`Cache Result:`);
|
core.debug(`Cache Result:`);
|
||||||
core.debug(JSON.stringify(cacheResult));
|
core.debug(JSON.stringify(cacheResult));
|
||||||
|
if (!cacheResult || !cacheResult.archiveLocation) {
|
||||||
|
throw new Error("Cache not found.");
|
||||||
|
}
|
||||||
return cacheResult;
|
return cacheResult;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1560,102 +1551,34 @@ function pipeResponseToStream(response, stream) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function downloadCache(archiveLocation, archivePath) {
|
function downloadCache(cacheEntry, archivePath) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const stream = fs.createWriteStream(archivePath);
|
const stream = fs.createWriteStream(archivePath);
|
||||||
const httpClient = new HttpClient_1.HttpClient("actions/cache");
|
const httpClient = new HttpClient_1.HttpClient("actions/cache");
|
||||||
const downloadResponse = yield httpClient.get(archiveLocation);
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const downloadResponse = yield httpClient.get(cacheEntry.archiveLocation);
|
||||||
yield pipeResponseToStream(downloadResponse, stream);
|
yield pipeResponseToStream(downloadResponse, stream);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.downloadCache = downloadCache;
|
exports.downloadCache = downloadCache;
|
||||||
// Reserve Cache
|
function saveCache(key, archivePath) {
|
||||||
function reserveCache(key) {
|
|
||||||
var _a, _b, _c;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const restClient = createRestClient();
|
const stream = fs.createReadStream(archivePath);
|
||||||
const reserveCacheRequest = {
|
const cacheUrl = getCacheUrl();
|
||||||
key
|
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||||
};
|
const bearerCredentialHandler = new Handlers_1.BearerCredentialHandler(token);
|
||||||
const response = yield restClient.create("caches", reserveCacheRequest, getRequestOptions());
|
const resource = `_apis/artifactcache/cache/${encodeURIComponent(key)}`;
|
||||||
return _c = (_b = (_a = response) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.cacheId, (_c !== null && _c !== void 0 ? _c : -1);
|
const postUrl = cacheUrl + resource;
|
||||||
});
|
const restClient = new RestClient_1.RestClient("actions/cache", undefined, [
|
||||||
}
|
bearerCredentialHandler
|
||||||
exports.reserveCache = reserveCache;
|
]);
|
||||||
function getContentRange(start, end) {
|
|
||||||
// Format: `bytes start-end/filesize
|
|
||||||
// start and end are inclusive
|
|
||||||
// filesize can be *
|
|
||||||
// For a 200 byte chunk starting at byte 0:
|
|
||||||
// Content-Range: bytes 0-199/*
|
|
||||||
return `bytes ${start}-${end}/*`;
|
|
||||||
}
|
|
||||||
// function bufferToStream(buffer: Buffer): NodeJS.ReadableStream {
|
|
||||||
// const stream = new Duplex();
|
|
||||||
// stream.push(buffer);
|
|
||||||
// stream.push(null);
|
|
||||||
// return stream;
|
|
||||||
// }
|
|
||||||
function uploadChunk(restClient, resourceUrl, data, start, end) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
core.debug(`Uploading chunk of size ${end - start + 1} bytes at offset ${start} with content range: ${getContentRange(start, end)}`);
|
|
||||||
const requestOptions = getRequestOptions();
|
const requestOptions = getRequestOptions();
|
||||||
requestOptions.additionalHeaders = {
|
requestOptions.additionalHeaders = {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream"
|
||||||
"Content-Range": getContentRange(start, end)
|
|
||||||
};
|
};
|
||||||
return yield restClient.uploadStream("PATCH", resourceUrl, data, requestOptions);
|
const response = yield restClient.uploadStream("POST", postUrl, stream, requestOptions);
|
||||||
});
|
if (response.statusCode !== 200) {
|
||||||
}
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
function commitCache(restClient, cacheId, filesize) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const requestOptions = getRequestOptions();
|
|
||||||
const commitCacheRequest = { size: filesize };
|
|
||||||
return yield restClient.create(`caches/${cacheId.toString()}`, commitCacheRequest, requestOptions);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function uploadFile(restClient, cacheId, archivePath) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Upload Chunks
|
|
||||||
const fileSize = fs.statSync(archivePath).size;
|
|
||||||
const resourceUrl = getCacheApiUrl() + "caches/" + cacheId.toString();
|
|
||||||
const responses = [];
|
|
||||||
const fd = fs.openSync(archivePath, "r");
|
|
||||||
const concurrency = 16; // # of HTTP requests in parallel
|
|
||||||
const MAX_CHUNK_SIZE = 32000000; // 32 MB Chunks
|
|
||||||
core.debug(`Concurrency: ${concurrency} and Chunk Size: ${MAX_CHUNK_SIZE}`);
|
|
||||||
const parallelUploads = [...new Array(concurrency).keys()];
|
|
||||||
core.debug("Awaiting all uploads");
|
|
||||||
let offset = 0;
|
|
||||||
yield Promise.all(parallelUploads.map(() => __awaiter(this, void 0, void 0, function* () {
|
|
||||||
while (offset < fileSize) {
|
|
||||||
const chunkSize = offset + MAX_CHUNK_SIZE > fileSize ? fileSize - offset : MAX_CHUNK_SIZE;
|
|
||||||
const start = offset;
|
|
||||||
const end = offset + chunkSize - 1;
|
|
||||||
offset += MAX_CHUNK_SIZE;
|
|
||||||
const chunk = fs.createReadStream(archivePath, { fd, start, end, autoClose: false });
|
|
||||||
responses.push(yield uploadChunk(restClient, resourceUrl, chunk, start, end));
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
fs.closeSync(fd);
|
|
||||||
const failedResponse = responses.find(x => !isSuccessStatusCode(x.statusCode));
|
|
||||||
if (failedResponse) {
|
|
||||||
throw new Error(`Cache service responded with ${failedResponse.statusCode} during chunk upload.`);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function saveCache(cacheId, archivePath) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const restClient = createRestClient();
|
|
||||||
core.debug("Upload cache");
|
|
||||||
yield uploadFile(restClient, cacheId, archivePath);
|
|
||||||
core.debug("Commiting cache");
|
|
||||||
// Commit Cache
|
|
||||||
const cacheSize = utils.getArchiveFileSize(archivePath);
|
|
||||||
const commitCacheResponse = yield commitCache(restClient, cacheId, cacheSize);
|
|
||||||
if (!isSuccessStatusCode(commitCacheResponse.statusCode)) {
|
|
||||||
throw new Error(`Cache service responded with ${commitCacheResponse.statusCode} during commit cache.`);
|
|
||||||
}
|
}
|
||||||
core.info("Cache saved successfully");
|
core.info("Cache saved successfully");
|
||||||
});
|
});
|
||||||
@ -2285,11 +2208,6 @@ function getCacheState() {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
exports.getCacheState = getCacheState;
|
exports.getCacheState = getCacheState;
|
||||||
function logWarning(message) {
|
|
||||||
const warningPrefix = "[warning]";
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
exports.logWarning = logWarning;
|
|
||||||
function resolvePath(filePath) {
|
function resolvePath(filePath) {
|
||||||
if (filePath[0] === "~") {
|
if (filePath[0] === "~") {
|
||||||
const home = os.homedir();
|
const home = os.homedir();
|
||||||
@ -3074,15 +2992,13 @@ const cacheHttpClient = __importStar(__webpack_require__(154));
|
|||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
const utils = __importStar(__webpack_require__(443));
|
const utils = __importStar(__webpack_require__(443));
|
||||||
function run() {
|
function run() {
|
||||||
var _a, _b;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
// Validate inputs, this can cause task failure
|
// Validate inputs, this can cause task failure
|
||||||
if (!utils.isValidEvent()) {
|
if (!utils.isValidEvent()) {
|
||||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported. Only ${utils
|
core.setFailed(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported. Only ${utils
|
||||||
.getSupportedEvents()
|
.getSupportedEvents()
|
||||||
.join(", ")} events are supported at this time.`);
|
.join(", ")} events are supported at this time.`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const cachePath = utils.resolvePath(core.getInput(constants_1.Inputs.Path, { required: true }));
|
const cachePath = utils.resolvePath(core.getInput(constants_1.Inputs.Path, { required: true }));
|
||||||
core.debug(`Cache Path: ${cachePath}`);
|
core.debug(`Cache Path: ${cachePath}`);
|
||||||
@ -3112,7 +3028,7 @@ function run() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const cacheEntry = yield cacheHttpClient.getCacheEntry(keys);
|
const cacheEntry = yield cacheHttpClient.getCacheEntry(keys);
|
||||||
if (!cacheEntry || !((_a = cacheEntry) === null || _a === void 0 ? void 0 : _a.archiveLocation)) {
|
if (!cacheEntry) {
|
||||||
core.info(`Cache not found for input keys: ${keys.join(", ")}.`);
|
core.info(`Cache not found for input keys: ${keys.join(", ")}.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3121,8 +3037,7 @@ function run() {
|
|||||||
// Store the cache result
|
// Store the cache result
|
||||||
utils.setCacheState(cacheEntry);
|
utils.setCacheState(cacheEntry);
|
||||||
// Download the cache from the cache entry
|
// Download the cache from the cache entry
|
||||||
yield cacheHttpClient.downloadCache((_b = cacheEntry) === null || _b === void 0 ? void 0 : _b.archiveLocation, archivePath);
|
yield cacheHttpClient.downloadCache(cacheEntry, archivePath);
|
||||||
yield exec_1.exec(`md5sum`, [archivePath]);
|
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
||||||
// Create directory to extract tar into
|
// Create directory to extract tar into
|
||||||
@ -3148,7 +3063,7 @@ function run() {
|
|||||||
core.info(`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`);
|
core.info(`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
utils.logWarning(error.message);
|
core.warning(error.message);
|
||||||
utils.setCacheHitOutput(false);
|
utils.setCacheHitOutput(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
175
dist/save/index.js
vendored
175
dist/save/index.js
vendored
@ -1496,57 +1496,48 @@ const fs = __importStar(__webpack_require__(747));
|
|||||||
const Handlers_1 = __webpack_require__(941);
|
const Handlers_1 = __webpack_require__(941);
|
||||||
const HttpClient_1 = __webpack_require__(874);
|
const HttpClient_1 = __webpack_require__(874);
|
||||||
const RestClient_1 = __webpack_require__(105);
|
const RestClient_1 = __webpack_require__(105);
|
||||||
const utils = __importStar(__webpack_require__(443));
|
function getCacheUrl() {
|
||||||
function isSuccessStatusCode(statusCode) {
|
|
||||||
return statusCode >= 200 && statusCode < 300;
|
|
||||||
}
|
|
||||||
function getCacheApiUrl() {
|
|
||||||
// Ideally we just use ACTIONS_CACHE_URL
|
// Ideally we just use ACTIONS_CACHE_URL
|
||||||
const baseUrl = (process.env["ACTIONS_CACHE_URL"] ||
|
const cacheUrl = (process.env["ACTIONS_CACHE_URL"] ||
|
||||||
process.env["ACTIONS_RUNTIME_URL"] ||
|
process.env["ACTIONS_RUNTIME_URL"] ||
|
||||||
"").replace("pipelines", "artifactcache");
|
"").replace("pipelines", "artifactcache");
|
||||||
if (!baseUrl) {
|
if (!cacheUrl) {
|
||||||
throw new Error("Cache Service Url not found, unable to restore cache.");
|
throw new Error("Cache Service Url not found, unable to restore cache.");
|
||||||
}
|
}
|
||||||
core.debug(`Cache Url: ${baseUrl}`);
|
core.debug(`Cache Url: ${cacheUrl}`);
|
||||||
return `${baseUrl}_apis/artifactcache/`;
|
return cacheUrl;
|
||||||
}
|
}
|
||||||
function createAcceptHeader(type, apiVersion) {
|
function createAcceptHeader(type, apiVersion) {
|
||||||
return `${type};api-version=${apiVersion}`;
|
return `${type};api-version=${apiVersion}`;
|
||||||
}
|
}
|
||||||
function getRequestOptions() {
|
function getRequestOptions() {
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
acceptHeader: createAcceptHeader("application/json", "6.0-preview.1")
|
acceptHeader: createAcceptHeader("application/json", "5.2-preview.1")
|
||||||
};
|
};
|
||||||
return requestOptions;
|
return requestOptions;
|
||||||
}
|
}
|
||||||
function createRestClient() {
|
|
||||||
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
|
||||||
const bearerCredentialHandler = new Handlers_1.BearerCredentialHandler(token);
|
|
||||||
return new RestClient_1.RestClient("actions/cache", getCacheApiUrl(), [
|
|
||||||
bearerCredentialHandler
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
function getCacheEntry(keys) {
|
function getCacheEntry(keys) {
|
||||||
var _a;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const restClient = createRestClient();
|
const cacheUrl = getCacheUrl();
|
||||||
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}`;
|
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||||
|
const bearerCredentialHandler = new Handlers_1.BearerCredentialHandler(token);
|
||||||
|
const resource = `_apis/artifactcache/cache?keys=${encodeURIComponent(keys.join(","))}`;
|
||||||
|
const restClient = new RestClient_1.RestClient("actions/cache", cacheUrl, [
|
||||||
|
bearerCredentialHandler
|
||||||
|
]);
|
||||||
const response = yield restClient.get(resource, getRequestOptions());
|
const response = yield restClient.get(resource, getRequestOptions());
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!isSuccessStatusCode(response.statusCode)) {
|
if (response.statusCode !== 200) {
|
||||||
throw new Error(`Cache service responded with ${response.statusCode}`);
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
}
|
}
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
const cacheDownloadUrl = (_a = cacheResult) === null || _a === void 0 ? void 0 : _a.archiveLocation;
|
|
||||||
if (!cacheDownloadUrl) {
|
|
||||||
throw new Error("Cache not found.");
|
|
||||||
}
|
|
||||||
core.setSecret(cacheDownloadUrl);
|
|
||||||
core.debug(`Cache Result:`);
|
core.debug(`Cache Result:`);
|
||||||
core.debug(JSON.stringify(cacheResult));
|
core.debug(JSON.stringify(cacheResult));
|
||||||
|
if (!cacheResult || !cacheResult.archiveLocation) {
|
||||||
|
throw new Error("Cache not found.");
|
||||||
|
}
|
||||||
return cacheResult;
|
return cacheResult;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1560,102 +1551,34 @@ function pipeResponseToStream(response, stream) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function downloadCache(archiveLocation, archivePath) {
|
function downloadCache(cacheEntry, archivePath) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const stream = fs.createWriteStream(archivePath);
|
const stream = fs.createWriteStream(archivePath);
|
||||||
const httpClient = new HttpClient_1.HttpClient("actions/cache");
|
const httpClient = new HttpClient_1.HttpClient("actions/cache");
|
||||||
const downloadResponse = yield httpClient.get(archiveLocation);
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const downloadResponse = yield httpClient.get(cacheEntry.archiveLocation);
|
||||||
yield pipeResponseToStream(downloadResponse, stream);
|
yield pipeResponseToStream(downloadResponse, stream);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.downloadCache = downloadCache;
|
exports.downloadCache = downloadCache;
|
||||||
// Reserve Cache
|
function saveCache(key, archivePath) {
|
||||||
function reserveCache(key) {
|
|
||||||
var _a, _b, _c;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const restClient = createRestClient();
|
const stream = fs.createReadStream(archivePath);
|
||||||
const reserveCacheRequest = {
|
const cacheUrl = getCacheUrl();
|
||||||
key
|
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||||
};
|
const bearerCredentialHandler = new Handlers_1.BearerCredentialHandler(token);
|
||||||
const response = yield restClient.create("caches", reserveCacheRequest, getRequestOptions());
|
const resource = `_apis/artifactcache/cache/${encodeURIComponent(key)}`;
|
||||||
return _c = (_b = (_a = response) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.cacheId, (_c !== null && _c !== void 0 ? _c : -1);
|
const postUrl = cacheUrl + resource;
|
||||||
});
|
const restClient = new RestClient_1.RestClient("actions/cache", undefined, [
|
||||||
}
|
bearerCredentialHandler
|
||||||
exports.reserveCache = reserveCache;
|
]);
|
||||||
function getContentRange(start, end) {
|
|
||||||
// Format: `bytes start-end/filesize
|
|
||||||
// start and end are inclusive
|
|
||||||
// filesize can be *
|
|
||||||
// For a 200 byte chunk starting at byte 0:
|
|
||||||
// Content-Range: bytes 0-199/*
|
|
||||||
return `bytes ${start}-${end}/*`;
|
|
||||||
}
|
|
||||||
// function bufferToStream(buffer: Buffer): NodeJS.ReadableStream {
|
|
||||||
// const stream = new Duplex();
|
|
||||||
// stream.push(buffer);
|
|
||||||
// stream.push(null);
|
|
||||||
// return stream;
|
|
||||||
// }
|
|
||||||
function uploadChunk(restClient, resourceUrl, data, start, end) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
core.debug(`Uploading chunk of size ${end - start + 1} bytes at offset ${start} with content range: ${getContentRange(start, end)}`);
|
|
||||||
const requestOptions = getRequestOptions();
|
const requestOptions = getRequestOptions();
|
||||||
requestOptions.additionalHeaders = {
|
requestOptions.additionalHeaders = {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream"
|
||||||
"Content-Range": getContentRange(start, end)
|
|
||||||
};
|
};
|
||||||
return yield restClient.uploadStream("PATCH", resourceUrl, data, requestOptions);
|
const response = yield restClient.uploadStream("POST", postUrl, stream, requestOptions);
|
||||||
});
|
if (response.statusCode !== 200) {
|
||||||
}
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
function commitCache(restClient, cacheId, filesize) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const requestOptions = getRequestOptions();
|
|
||||||
const commitCacheRequest = { size: filesize };
|
|
||||||
return yield restClient.create(`caches/${cacheId.toString()}`, commitCacheRequest, requestOptions);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function uploadFile(restClient, cacheId, archivePath) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Upload Chunks
|
|
||||||
const fileSize = fs.statSync(archivePath).size;
|
|
||||||
const resourceUrl = getCacheApiUrl() + "caches/" + cacheId.toString();
|
|
||||||
const responses = [];
|
|
||||||
const fd = fs.openSync(archivePath, "r");
|
|
||||||
const concurrency = 16; // # of HTTP requests in parallel
|
|
||||||
const MAX_CHUNK_SIZE = 32000000; // 32 MB Chunks
|
|
||||||
core.debug(`Concurrency: ${concurrency} and Chunk Size: ${MAX_CHUNK_SIZE}`);
|
|
||||||
const parallelUploads = [...new Array(concurrency).keys()];
|
|
||||||
core.debug("Awaiting all uploads");
|
|
||||||
let offset = 0;
|
|
||||||
yield Promise.all(parallelUploads.map(() => __awaiter(this, void 0, void 0, function* () {
|
|
||||||
while (offset < fileSize) {
|
|
||||||
const chunkSize = offset + MAX_CHUNK_SIZE > fileSize ? fileSize - offset : MAX_CHUNK_SIZE;
|
|
||||||
const start = offset;
|
|
||||||
const end = offset + chunkSize - 1;
|
|
||||||
offset += MAX_CHUNK_SIZE;
|
|
||||||
const chunk = fs.createReadStream(archivePath, { fd, start, end, autoClose: false });
|
|
||||||
responses.push(yield uploadChunk(restClient, resourceUrl, chunk, start, end));
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
fs.closeSync(fd);
|
|
||||||
const failedResponse = responses.find(x => !isSuccessStatusCode(x.statusCode));
|
|
||||||
if (failedResponse) {
|
|
||||||
throw new Error(`Cache service responded with ${failedResponse.statusCode} during chunk upload.`);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function saveCache(cacheId, archivePath) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const restClient = createRestClient();
|
|
||||||
core.debug("Upload cache");
|
|
||||||
yield uploadFile(restClient, cacheId, archivePath);
|
|
||||||
core.debug("Commiting cache");
|
|
||||||
// Commit Cache
|
|
||||||
const cacheSize = utils.getArchiveFileSize(archivePath);
|
|
||||||
const commitCacheResponse = yield commitCache(restClient, cacheId, cacheSize);
|
|
||||||
if (!isSuccessStatusCode(commitCacheResponse.statusCode)) {
|
|
||||||
throw new Error(`Cache service responded with ${commitCacheResponse.statusCode} during commit cache.`);
|
|
||||||
}
|
}
|
||||||
core.info("Cache saved successfully");
|
core.info("Cache saved successfully");
|
||||||
});
|
});
|
||||||
@ -2285,11 +2208,6 @@ function getCacheState() {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
exports.getCacheState = getCacheState;
|
exports.getCacheState = getCacheState;
|
||||||
function logWarning(message) {
|
|
||||||
const warningPrefix = "[warning]";
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
exports.logWarning = logWarning;
|
|
||||||
function resolvePath(filePath) {
|
function resolvePath(filePath) {
|
||||||
if (filePath[0] === "~") {
|
if (filePath[0] === "~") {
|
||||||
const home = os.homedir();
|
const home = os.homedir();
|
||||||
@ -2964,30 +2882,17 @@ const utils = __importStar(__webpack_require__(443));
|
|||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
if (!utils.isValidEvent()) {
|
|
||||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported. Only ${utils
|
|
||||||
.getSupportedEvents()
|
|
||||||
.join(", ")} events are supported at this time.`);
|
|
||||||
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
|
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||||
const primaryKey = core.getState(constants_1.State.CacheKey);
|
const primaryKey = core.getState(constants_1.State.CacheKey);
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
core.warning(`Error retrieving key from state.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.debug("Reserving Cache");
|
|
||||||
const cacheId = yield cacheHttpClient.reserveCache(primaryKey);
|
|
||||||
if (cacheId < 0) {
|
|
||||||
core.info(`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
core.debug(`Cache ID: ${cacheId}`);
|
|
||||||
const cachePath = utils.resolvePath(core.getInput(constants_1.Inputs.Path, { required: true }));
|
const cachePath = utils.resolvePath(core.getInput(constants_1.Inputs.Path, { required: true }));
|
||||||
core.debug(`Cache Path: ${cachePath}`);
|
core.debug(`Cache Path: ${cachePath}`);
|
||||||
const archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz");
|
const archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz");
|
||||||
@ -3009,19 +2914,17 @@ function run() {
|
|||||||
const tarPath = yield io.which("tar", true);
|
const tarPath = yield io.which("tar", true);
|
||||||
core.debug(`Tar Path: ${tarPath}`);
|
core.debug(`Tar Path: ${tarPath}`);
|
||||||
yield exec_1.exec(`"${tarPath}"`, args);
|
yield exec_1.exec(`"${tarPath}"`, args);
|
||||||
const fileSizeLimit = 2 * 1024 * 1024 * 1024; // 2GB per repo limit
|
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.debug(`File Size: ${archiveFileSize}`);
|
core.debug(`File Size: ${archiveFileSize}`);
|
||||||
if (archiveFileSize > fileSizeLimit) {
|
if (archiveFileSize > fileSizeLimit) {
|
||||||
utils.logWarning(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024 * 1024))} GB (${archiveFileSize} B) is over the 2GB limit, not saving cache.`);
|
core.warning(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield exec_1.exec(`md5sum`, [archivePath]);
|
yield cacheHttpClient.saveCache(primaryKey, archivePath);
|
||||||
core.debug("Saving Cache");
|
|
||||||
yield cacheHttpClient.saveCache(cacheId, archivePath);
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
utils.logWarning(error.message);
|
core.warning(error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
41
examples.md
41
examples.md
@ -1,18 +1,25 @@
|
|||||||
# Examples
|
# Examples
|
||||||
|
|
||||||
- [C# - Nuget](#c---nuget)
|
- [Examples](#examples)
|
||||||
- [Elixir - Mix](#elixir---mix)
|
- [C# - Nuget](#c---nuget)
|
||||||
- [Go - Modules](#go---modules)
|
- [Elixir - Mix](#elixir---mix)
|
||||||
- [Java - Gradle](#java---gradle)
|
- [Go - Modules](#go---modules)
|
||||||
- [Java - Maven](#java---maven)
|
- [Java - Gradle](#java---gradle)
|
||||||
- [Node - npm](#node---npm)
|
- [Java - Maven](#java---maven)
|
||||||
- [Node - Yarn](#node---yarn)
|
- [Node - npm](#node---npm)
|
||||||
- [PHP - Composer](#php---composer)
|
- [macOS and Ubuntu](#macos-and-ubuntu)
|
||||||
- [Python - pip](#python---pip)
|
- [Windows](#windows)
|
||||||
- [Ruby - Gem](#ruby---gem)
|
- [Using multiple systems and `npm config`](#using-multiple-systems-and-npm-config)
|
||||||
- [Rust - Cargo](#rust---cargo)
|
- [Node - Yarn](#node---yarn)
|
||||||
- [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
|
- [PHP - Composer](#php---composer)
|
||||||
- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods)
|
- [Python - pip](#python---pip)
|
||||||
|
- [Simple example](#simple-example)
|
||||||
|
- [Multiple OS's in a workflow](#multiple-oss-in-a-workflow)
|
||||||
|
- [Using a script to get cache location](#using-a-script-to-get-cache-location)
|
||||||
|
- [Ruby - Gem](#ruby---gem)
|
||||||
|
- [Rust - Cargo](#rust---cargo)
|
||||||
|
- [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
|
||||||
|
- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods)
|
||||||
|
|
||||||
## C# - Nuget
|
## C# - Nuget
|
||||||
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
|
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
|
||||||
@ -219,14 +226,6 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-gem-
|
${{ runner.os }}-gem-
|
||||||
```
|
```
|
||||||
When dependencies are installed later in the workflow, we must specify the same path for the bundler.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- name: Bundle install
|
|
||||||
run: |
|
|
||||||
bundle config path vendor/bundle
|
|
||||||
bundle install --jobs 4 --retry 3
|
|
||||||
```
|
|
||||||
|
|
||||||
## Rust - Cargo
|
## Rust - Cargo
|
||||||
|
|
||||||
|
14
package-lock.json
generated
14
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "1.0.3",
|
"version": "1.0.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -4859,9 +4859,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"version": "1.19.1",
|
"version": "1.18.2",
|
||||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz",
|
||||||
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
|
"integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"prettier-linter-helpers": {
|
"prettier-linter-helpers": {
|
||||||
@ -5983,9 +5983,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"version": "3.7.3",
|
"version": "3.6.4",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.4.tgz",
|
||||||
"integrity": "sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==",
|
"integrity": "sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"uglify-js": {
|
"uglify-js": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "1.1.0",
|
"version": "1.0.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Cache dependencies and build outputs",
|
"description": "Cache dependencies and build outputs",
|
||||||
"main": "dist/restore/index.js",
|
"main": "dist/restore/index.js",
|
||||||
@ -46,8 +46,8 @@
|
|||||||
"jest": "^24.8.0",
|
"jest": "^24.8.0",
|
||||||
"jest-circus": "^24.7.1",
|
"jest-circus": "^24.7.1",
|
||||||
"nock": "^11.7.0",
|
"nock": "^11.7.0",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "1.18.2",
|
||||||
"ts-jest": "^24.0.2",
|
"ts-jest": "^24.0.2",
|
||||||
"typescript": "^3.7.3"
|
"typescript": "^3.6.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,37 +3,24 @@ import * as fs from "fs";
|
|||||||
import { BearerCredentialHandler } from "typed-rest-client/Handlers";
|
import { BearerCredentialHandler } from "typed-rest-client/Handlers";
|
||||||
import { HttpClient } from "typed-rest-client/HttpClient";
|
import { HttpClient } from "typed-rest-client/HttpClient";
|
||||||
import { IHttpClientResponse } from "typed-rest-client/Interfaces";
|
import { IHttpClientResponse } from "typed-rest-client/Interfaces";
|
||||||
import {
|
import { IRequestOptions, RestClient } from "typed-rest-client/RestClient";
|
||||||
IRequestOptions,
|
import { ArtifactCacheEntry } from "./contracts";
|
||||||
RestClient,
|
|
||||||
IRestResponse
|
|
||||||
} from "typed-rest-client/RestClient";
|
|
||||||
import {
|
|
||||||
ArtifactCacheEntry,
|
|
||||||
CommitCacheRequest,
|
|
||||||
ReserveCacheRequest,
|
|
||||||
ReserverCacheResponse
|
|
||||||
} from "./contracts";
|
|
||||||
import * as utils from "./utils/actionUtils";
|
|
||||||
|
|
||||||
function isSuccessStatusCode(statusCode: number): boolean {
|
function getCacheUrl(): string {
|
||||||
return statusCode >= 200 && statusCode < 300;
|
|
||||||
}
|
|
||||||
function getCacheApiUrl(): string {
|
|
||||||
// Ideally we just use ACTIONS_CACHE_URL
|
// Ideally we just use ACTIONS_CACHE_URL
|
||||||
const baseUrl: string = (
|
const cacheUrl: string = (
|
||||||
process.env["ACTIONS_CACHE_URL"] ||
|
process.env["ACTIONS_CACHE_URL"] ||
|
||||||
process.env["ACTIONS_RUNTIME_URL"] ||
|
process.env["ACTIONS_RUNTIME_URL"] ||
|
||||||
""
|
""
|
||||||
).replace("pipelines", "artifactcache");
|
).replace("pipelines", "artifactcache");
|
||||||
if (!baseUrl) {
|
if (!cacheUrl) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Cache Service Url not found, unable to restore cache."
|
"Cache Service Url not found, unable to restore cache."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`Cache Url: ${baseUrl}`);
|
core.debug(`Cache Url: ${cacheUrl}`);
|
||||||
return `${baseUrl}_apis/artifactcache/`;
|
return cacheUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAcceptHeader(type: string, apiVersion: string): string {
|
function createAcceptHeader(type: string, apiVersion: string): string {
|
||||||
@ -42,26 +29,26 @@ function createAcceptHeader(type: string, apiVersion: string): string {
|
|||||||
|
|
||||||
function getRequestOptions(): IRequestOptions {
|
function getRequestOptions(): IRequestOptions {
|
||||||
const requestOptions: IRequestOptions = {
|
const requestOptions: IRequestOptions = {
|
||||||
acceptHeader: createAcceptHeader("application/json", "6.0-preview.1")
|
acceptHeader: createAcceptHeader("application/json", "5.2-preview.1")
|
||||||
};
|
};
|
||||||
|
|
||||||
return requestOptions;
|
return requestOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRestClient(): RestClient {
|
|
||||||
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
|
||||||
const bearerCredentialHandler = new BearerCredentialHandler(token);
|
|
||||||
|
|
||||||
return new RestClient("actions/cache", getCacheApiUrl(), [
|
|
||||||
bearerCredentialHandler
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getCacheEntry(
|
export async function getCacheEntry(
|
||||||
keys: string[]
|
keys: string[]
|
||||||
): Promise<ArtifactCacheEntry | null> {
|
): Promise<ArtifactCacheEntry | null> {
|
||||||
const restClient = createRestClient();
|
const cacheUrl = getCacheUrl();
|
||||||
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}`;
|
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||||
|
const bearerCredentialHandler = new BearerCredentialHandler(token);
|
||||||
|
|
||||||
|
const resource = `_apis/artifactcache/cache?keys=${encodeURIComponent(
|
||||||
|
keys.join(",")
|
||||||
|
)}`;
|
||||||
|
|
||||||
|
const restClient = new RestClient("actions/cache", cacheUrl, [
|
||||||
|
bearerCredentialHandler
|
||||||
|
]);
|
||||||
|
|
||||||
const response = await restClient.get<ArtifactCacheEntry>(
|
const response = await restClient.get<ArtifactCacheEntry>(
|
||||||
resource,
|
resource,
|
||||||
@ -70,17 +57,15 @@ export async function getCacheEntry(
|
|||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!isSuccessStatusCode(response.statusCode)) {
|
if (response.statusCode !== 200) {
|
||||||
throw new Error(`Cache service responded with ${response.statusCode}`);
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
}
|
}
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
const cacheDownloadUrl = cacheResult?.archiveLocation;
|
|
||||||
if (!cacheDownloadUrl) {
|
|
||||||
throw new Error("Cache not found.");
|
|
||||||
}
|
|
||||||
core.setSecret(cacheDownloadUrl);
|
|
||||||
core.debug(`Cache Result:`);
|
core.debug(`Cache Result:`);
|
||||||
core.debug(JSON.stringify(cacheResult));
|
core.debug(JSON.stringify(cacheResult));
|
||||||
|
if (!cacheResult || !cacheResult.archiveLocation) {
|
||||||
|
throw new Error("Cache not found.");
|
||||||
|
}
|
||||||
|
|
||||||
return cacheResult;
|
return cacheResult;
|
||||||
}
|
}
|
||||||
@ -97,165 +82,46 @@ async function pipeResponseToStream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadCache(
|
export async function downloadCache(
|
||||||
archiveLocation: string,
|
cacheEntry: ArtifactCacheEntry,
|
||||||
archivePath: string
|
archivePath: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const stream = fs.createWriteStream(archivePath);
|
const stream = fs.createWriteStream(archivePath);
|
||||||
const httpClient = new HttpClient("actions/cache");
|
const httpClient = new HttpClient("actions/cache");
|
||||||
const downloadResponse = await httpClient.get(archiveLocation);
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const downloadResponse = await httpClient.get(cacheEntry.archiveLocation!);
|
||||||
await pipeResponseToStream(downloadResponse, stream);
|
await pipeResponseToStream(downloadResponse, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reserve Cache
|
export async function saveCache(
|
||||||
export async function reserveCache(key: string): Promise<number> {
|
key: string,
|
||||||
const restClient = createRestClient();
|
archivePath: string
|
||||||
|
): Promise<void> {
|
||||||
|
const stream = fs.createReadStream(archivePath);
|
||||||
|
|
||||||
const reserveCacheRequest: ReserveCacheRequest = {
|
const cacheUrl = getCacheUrl();
|
||||||
key
|
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||||
};
|
const bearerCredentialHandler = new BearerCredentialHandler(token);
|
||||||
const response = await restClient.create<ReserverCacheResponse>(
|
|
||||||
"caches",
|
|
||||||
reserveCacheRequest,
|
|
||||||
getRequestOptions()
|
|
||||||
);
|
|
||||||
|
|
||||||
return response?.result?.cacheId ?? -1;
|
const resource = `_apis/artifactcache/cache/${encodeURIComponent(key)}`;
|
||||||
}
|
const postUrl = cacheUrl + resource;
|
||||||
|
|
||||||
function getContentRange(start: number, end: number): string {
|
const restClient = new RestClient("actions/cache", undefined, [
|
||||||
// Format: `bytes start-end/filesize
|
bearerCredentialHandler
|
||||||
// start and end are inclusive
|
]);
|
||||||
// filesize can be *
|
|
||||||
// For a 200 byte chunk starting at byte 0:
|
|
||||||
// Content-Range: bytes 0-199/*
|
|
||||||
return `bytes ${start}-${end}/*`;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function uploadChunk(
|
|
||||||
restClient: RestClient,
|
|
||||||
resourceUrl: string,
|
|
||||||
data: NodeJS.ReadableStream,
|
|
||||||
start: number,
|
|
||||||
end: number
|
|
||||||
): Promise<IRestResponse<void>> {
|
|
||||||
core.debug(
|
|
||||||
`Uploading chunk of size ${end -
|
|
||||||
start +
|
|
||||||
1} bytes at offset ${start} with content range: ${getContentRange(
|
|
||||||
start,
|
|
||||||
end
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
const requestOptions = getRequestOptions();
|
const requestOptions = getRequestOptions();
|
||||||
requestOptions.additionalHeaders = {
|
requestOptions.additionalHeaders = {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream"
|
||||||
"Content-Range": getContentRange(start, end)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return await restClient.uploadStream<void>(
|
const response = await restClient.uploadStream<void>(
|
||||||
"PATCH",
|
"POST",
|
||||||
resourceUrl,
|
postUrl,
|
||||||
data,
|
stream,
|
||||||
requestOptions
|
requestOptions
|
||||||
);
|
);
|
||||||
}
|
if (response.statusCode !== 200) {
|
||||||
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
async function uploadFile(
|
|
||||||
restClient: RestClient,
|
|
||||||
cacheId: number,
|
|
||||||
archivePath: string
|
|
||||||
): Promise<void> {
|
|
||||||
// Upload Chunks
|
|
||||||
const fileSize = fs.statSync(archivePath).size;
|
|
||||||
const resourceUrl = getCacheApiUrl() + "caches/" + cacheId.toString();
|
|
||||||
const responses: IRestResponse<void>[] = [];
|
|
||||||
const fd = fs.openSync(archivePath, "r");
|
|
||||||
|
|
||||||
const concurrency = 4; // # of HTTP requests in parallel
|
|
||||||
const MAX_CHUNK_SIZE = 32000000; // 32 MB Chunks
|
|
||||||
core.debug(`Concurrency: ${concurrency} and Chunk Size: ${MAX_CHUNK_SIZE}`);
|
|
||||||
|
|
||||||
const parallelUploads = [...new Array(concurrency).keys()];
|
|
||||||
core.debug("Awaiting all uploads");
|
|
||||||
let offset = 0;
|
|
||||||
await Promise.all(
|
|
||||||
parallelUploads.map(async () => {
|
|
||||||
while (offset < fileSize) {
|
|
||||||
const chunkSize =
|
|
||||||
offset + MAX_CHUNK_SIZE > fileSize
|
|
||||||
? fileSize - offset
|
|
||||||
: MAX_CHUNK_SIZE;
|
|
||||||
const start = offset;
|
|
||||||
const end = offset + chunkSize - 1;
|
|
||||||
offset += MAX_CHUNK_SIZE;
|
|
||||||
const chunk = fs.createReadStream(archivePath, {
|
|
||||||
fd,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
autoClose: false
|
|
||||||
});
|
|
||||||
responses.push(
|
|
||||||
await uploadChunk(
|
|
||||||
restClient,
|
|
||||||
resourceUrl,
|
|
||||||
chunk,
|
|
||||||
start,
|
|
||||||
end
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
fs.closeSync(fd);
|
|
||||||
|
|
||||||
const failedResponse = responses.find(
|
|
||||||
x => !isSuccessStatusCode(x.statusCode)
|
|
||||||
);
|
|
||||||
if (failedResponse) {
|
|
||||||
throw new Error(
|
|
||||||
`Cache service responded with ${failedResponse.statusCode} during chunk upload.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function commitCache(
|
|
||||||
restClient: RestClient,
|
|
||||||
cacheId: number,
|
|
||||||
filesize: number
|
|
||||||
): Promise<IRestResponse<void>> {
|
|
||||||
const requestOptions = getRequestOptions();
|
|
||||||
const commitCacheRequest: CommitCacheRequest = { size: filesize };
|
|
||||||
return await restClient.create(
|
|
||||||
`caches/${cacheId.toString()}`,
|
|
||||||
commitCacheRequest,
|
|
||||||
requestOptions
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function saveCache(
|
|
||||||
cacheId: number,
|
|
||||||
archivePath: string
|
|
||||||
): Promise<void> {
|
|
||||||
const restClient = createRestClient();
|
|
||||||
|
|
||||||
core.debug("Upload cache");
|
|
||||||
await uploadFile(restClient, cacheId, archivePath);
|
|
||||||
|
|
||||||
// Commit Cache
|
|
||||||
core.debug("Commiting cache");
|
|
||||||
const cacheSize = utils.getArchiveFileSize(archivePath);
|
|
||||||
const commitCacheResponse = await commitCache(
|
|
||||||
restClient,
|
|
||||||
cacheId,
|
|
||||||
cacheSize
|
|
||||||
);
|
|
||||||
if (!isSuccessStatusCode(commitCacheResponse.statusCode)) {
|
|
||||||
throw new Error(
|
|
||||||
`Cache service responded with ${commitCacheResponse.statusCode} during commit cache.`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info("Cache saved successfully");
|
core.info("Cache saved successfully");
|
||||||
|
13
src/contracts.d.ts
vendored
13
src/contracts.d.ts
vendored
@ -4,16 +4,3 @@ export interface ArtifactCacheEntry {
|
|||||||
creationTime?: string;
|
creationTime?: string;
|
||||||
archiveLocation?: string;
|
archiveLocation?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CommitCacheRequest {
|
|
||||||
size: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ReserveCacheRequest {
|
|
||||||
key: string;
|
|
||||||
version?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ReserverCacheResponse {
|
|
||||||
cacheId: number;
|
|
||||||
}
|
|
||||||
|
@ -10,14 +10,13 @@ async function run(): Promise<void> {
|
|||||||
try {
|
try {
|
||||||
// Validate inputs, this can cause task failure
|
// Validate inputs, this can cause task failure
|
||||||
if (!utils.isValidEvent()) {
|
if (!utils.isValidEvent()) {
|
||||||
utils.logWarning(
|
core.setFailed(
|
||||||
`Event Validation Error: The event type ${
|
`Event Validation Error: The event type ${
|
||||||
process.env[Events.Key]
|
process.env[Events.Key]
|
||||||
} is not supported. Only ${utils
|
} is not supported. Only ${utils
|
||||||
.getSupportedEvents()
|
.getSupportedEvents()
|
||||||
.join(", ")} events are supported at this time.`
|
.join(", ")} events are supported at this time.`
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachePath = utils.resolvePath(
|
const cachePath = utils.resolvePath(
|
||||||
@ -61,7 +60,7 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
|
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
|
||||||
if (!cacheEntry || !cacheEntry?.archiveLocation) {
|
if (!cacheEntry) {
|
||||||
core.info(
|
core.info(
|
||||||
`Cache not found for input keys: ${keys.join(", ")}.`
|
`Cache not found for input keys: ${keys.join(", ")}.`
|
||||||
);
|
);
|
||||||
@ -78,10 +77,7 @@ async function run(): Promise<void> {
|
|||||||
utils.setCacheState(cacheEntry);
|
utils.setCacheState(cacheEntry);
|
||||||
|
|
||||||
// Download the cache from the cache entry
|
// Download the cache from the cache entry
|
||||||
await cacheHttpClient.downloadCache(
|
await cacheHttpClient.downloadCache(cacheEntry, archivePath);
|
||||||
cacheEntry?.archiveLocation,
|
|
||||||
archivePath
|
|
||||||
);
|
|
||||||
|
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.info(
|
core.info(
|
||||||
@ -122,7 +118,7 @@ async function run(): Promise<void> {
|
|||||||
`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`
|
`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
utils.logWarning(error.message);
|
core.warning(error.message);
|
||||||
utils.setCacheHitOutput(false);
|
utils.setCacheHitOutput(false);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
37
src/save.ts
37
src/save.ts
@ -3,28 +3,17 @@ import { exec } from "@actions/exec";
|
|||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as cacheHttpClient from "./cacheHttpClient";
|
import * as cacheHttpClient from "./cacheHttpClient";
|
||||||
import { Events, Inputs, State } from "./constants";
|
import { Inputs, State } from "./constants";
|
||||||
import * as utils from "./utils/actionUtils";
|
import * as utils from "./utils/actionUtils";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!utils.isValidEvent()) {
|
|
||||||
utils.logWarning(
|
|
||||||
`Event Validation Error: The event type ${
|
|
||||||
process.env[Events.Key]
|
|
||||||
} is not supported. Only ${utils
|
|
||||||
.getSupportedEvents()
|
|
||||||
.join(", ")} events are supported at this time.`
|
|
||||||
);
|
|
||||||
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
|
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||||
const primaryKey = core.getState(State.CacheKey);
|
const primaryKey = core.getState(State.CacheKey);
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
core.warning(`Error retrieving key from state.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,15 +24,6 @@ async function run(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug("Reserving Cache");
|
|
||||||
const cacheId = await cacheHttpClient.reserveCache(primaryKey);
|
|
||||||
if (cacheId < 0) {
|
|
||||||
core.info(
|
|
||||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
core.debug(`Cache ID: ${cacheId}`);
|
|
||||||
const cachePath = utils.resolvePath(
|
const cachePath = utils.resolvePath(
|
||||||
core.getInput(Inputs.Path, { required: true })
|
core.getInput(Inputs.Path, { required: true })
|
||||||
);
|
);
|
||||||
@ -74,22 +54,21 @@ async function run(): Promise<void> {
|
|||||||
core.debug(`Tar Path: ${tarPath}`);
|
core.debug(`Tar Path: ${tarPath}`);
|
||||||
await exec(`"${tarPath}"`, args);
|
await exec(`"${tarPath}"`, args);
|
||||||
|
|
||||||
const fileSizeLimit = 2 * 1024 * 1024 * 1024; // 2GB per repo limit
|
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.debug(`File Size: ${archiveFileSize}`);
|
core.debug(`File Size: ${archiveFileSize}`);
|
||||||
if (archiveFileSize > fileSizeLimit) {
|
if (archiveFileSize > fileSizeLimit) {
|
||||||
utils.logWarning(
|
core.warning(
|
||||||
`Cache size of ~${Math.round(
|
`Cache size of ~${Math.round(
|
||||||
archiveFileSize / (1024 * 1024 * 1024)
|
archiveFileSize / (1024 * 1024)
|
||||||
)} GB (${archiveFileSize} B) is over the 2GB limit, not saving cache.`
|
)} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug("Saving Cache");
|
await cacheHttpClient.saveCache(primaryKey, archivePath);
|
||||||
await cacheHttpClient.saveCache(cacheId, archivePath);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
utils.logWarning(error.message);
|
core.warning(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,11 +77,6 @@ export function getCacheState(): ArtifactCacheEntry | undefined {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logWarning(message: string): void {
|
|
||||||
const warningPrefix = "[warning]";
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolvePath(filePath: string): string {
|
export function resolvePath(filePath: string): string {
|
||||||
if (filePath[0] === "~") {
|
if (filePath[0] === "~") {
|
||||||
const home = os.homedir();
|
const home = os.homedir();
|
||||||
|
Reference in New Issue
Block a user