Compare commits

..

8 Commits

Author SHA1 Message Date
Josh Gross
7527073910 Test sudo tar 2019-12-27 11:48:00 -05:00
Kevin Burke
a631fadf14 README.md: fix grammar error (#136)
"it's" is short for "it is," but the use in this sentence is as a
possessive - something belonging to "it" - hence, "its" is correct.
2019-12-23 10:30:34 -05:00
Chris Patterson
e223b0a12d Merge pull request #124 from nogic1008/patch-1
Add Another C# Example to use personal cache folder
2019-12-16 10:24:25 -05:00
Nogic
decbafc350 Update examples.md
Co-Authored-By: Chris Patterson <chrispat@github.com>
2019-12-16 09:45:29 +09:00
Josh Gross
3854a40aee Use BSD tar on windows (#126)
* Use BSD tar on windows

* Linting

* Fallback to which tar if no system tar

* Fix formatting

* Bump prettier and typescript
2019-12-13 17:24:37 -05:00
Nogic
0188dffc5a Revert original C# Example
* Treat "Use Personal Cache Folder" way as another C# example
* Describe the situation in which another example should be used
2019-12-13 10:03:43 +09:00
Nogic
002d3a77f4 Use Personal Cache Folder in C# Example
Ref: #115
2019-12-10 09:21:47 +09:00
Jon Pugh
4809f4ada4 Add list of implementation examples. (#116)
More visibility into the samples by having it on the main README. Easier to see, better SEO.
2019-12-07 18:25:23 -05:00
8 changed files with 145 additions and 63 deletions

View File

@@ -54,9 +54,26 @@ jobs:
run: /primes.sh -d prime-numbers run: /primes.sh -d prime-numbers
``` ```
## Ecosystem Examples ## Implementation Examples
Every programming language and framework has its own way of caching.
See [Examples](examples.md) for a list of `actions/cache` implementations for use with:
- [C# - Nuget](./examples.md#c---nuget)
- [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

View File

@@ -6,17 +6,11 @@ jest.mock("@actions/exec");
jest.mock("@actions/io"); jest.mock("@actions/io");
beforeAll(() => { beforeAll(() => {
process.env["windir"] = "C:";
jest.spyOn(io, "which").mockImplementation(tool => { jest.spyOn(io, "which").mockImplementation(tool => {
return Promise.resolve(tool); return Promise.resolve(tool);
}); });
}); });
afterAll(() => {
delete process.env["windir"];
});
test("extract tar", async () => { test("extract tar", async () => {
const mkdirMock = jest.spyOn(io, "mkdirP"); const mkdirMock = jest.spyOn(io, "mkdirP");
const execMock = jest.spyOn(exec, "exec"); const execMock = jest.spyOn(exec, "exec");
@@ -28,7 +22,9 @@ test("extract tar", async () => {
expect(mkdirMock).toHaveBeenCalledWith(targetDirectory); expect(mkdirMock).toHaveBeenCalledWith(targetDirectory);
const IS_WINDOWS = process.platform === "win32"; const IS_WINDOWS = process.platform === "win32";
const tarPath = IS_WINDOWS ? "C:\\System32\\tar.exe" : "tar"; const tarPath = IS_WINDOWS
? `${process.env["windir"]}\\System32\\tar.exe`
: "tar";
expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledTimes(1);
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [ expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
"-xz", "-xz",
@@ -47,7 +43,9 @@ test("create tar", async () => {
await tar.createTar(archivePath, sourceDirectory); await tar.createTar(archivePath, sourceDirectory);
const IS_WINDOWS = process.platform === "win32"; const IS_WINDOWS = process.platform === "win32";
const tarPath = IS_WINDOWS ? "C:\\System32\\tar.exe" : "tar"; const tarPath = IS_WINDOWS
? `${process.env["windir"]}\\System32\\tar.exe`
: "tar";
expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledTimes(1);
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [ expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
"-cz", "-cz",

48
dist/restore/index.js vendored
View File

@@ -5168,35 +5168,53 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const exec_1 = __webpack_require__(986); const exec_1 = __webpack_require__(986);
const io = __importStar(__webpack_require__(1)); const io = __importStar(__webpack_require__(1));
const fs_1 = __webpack_require__(747);
function getTarPath() {
return __awaiter(this, void 0, void 0, function* () {
// Explicitly use BSD Tar on Windows
const IS_WINDOWS = process.platform === "win32";
if (IS_WINDOWS) {
const systemTar = `${process.env["windir"]}\\System32\\tar.exe`;
if (fs_1.existsSync(systemTar)) {
return systemTar;
}
}
return yield io.which("tar", true);
});
}
function execTar(args) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
const tarPath = yield getTarPath();
const tarExec = process.platform !== "win32" ? `sudo ${tarPath}` : tarPath;
yield exec_1.exec(`"${tarExec}"`, args);
}
catch (error) {
const IS_WINDOWS = process.platform === "win32";
if (IS_WINDOWS) {
throw new Error(`Tar failed with error: ${(_a = error) === null || _a === void 0 ? void 0 : _a.message}. Ensure BSD tar is installed and on the PATH.`);
}
throw new Error(`Tar failed with error: ${(_b = error) === null || _b === void 0 ? void 0 : _b.message}`);
}
});
}
function extractTar(archivePath, targetDirectory) { function extractTar(archivePath, targetDirectory) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// Create directory to extract tar into // Create directory to extract tar into
yield io.mkdirP(targetDirectory); yield io.mkdirP(targetDirectory);
// http://man7.org/linux/man-pages/man1/tar.1.html
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
const args = ["-xz", "-f", archivePath, "-C", targetDirectory]; const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
yield exec_1.exec(`"${yield getTarPath()}"`, args); yield execTar(args);
}); });
} }
exports.extractTar = extractTar; exports.extractTar = extractTar;
function createTar(archivePath, sourceDirectory) { function createTar(archivePath, sourceDirectory) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// http://man7.org/linux/man-pages/man1/tar.1.html
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."]; const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
yield exec_1.exec(`"${yield getTarPath()}"`, args); yield execTar(args);
}); });
} }
exports.createTar = createTar; exports.createTar = createTar;
function getTarPath() {
return __awaiter(this, void 0, void 0, function* () {
// Explicitly use BSD Tar on Windows
const IS_WINDOWS = process.platform === "win32";
return IS_WINDOWS
? `${process.env["windir"]}\\System32\\tar.exe`
: yield io.which("tar", true);
});
}
/***/ }), /***/ }),

48
dist/save/index.js vendored
View File

@@ -5142,35 +5142,53 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const exec_1 = __webpack_require__(986); const exec_1 = __webpack_require__(986);
const io = __importStar(__webpack_require__(1)); const io = __importStar(__webpack_require__(1));
const fs_1 = __webpack_require__(747);
function getTarPath() {
return __awaiter(this, void 0, void 0, function* () {
// Explicitly use BSD Tar on Windows
const IS_WINDOWS = process.platform === "win32";
if (IS_WINDOWS) {
const systemTar = `${process.env["windir"]}\\System32\\tar.exe`;
if (fs_1.existsSync(systemTar)) {
return systemTar;
}
}
return yield io.which("tar", true);
});
}
function execTar(args) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
const tarPath = yield getTarPath();
const tarExec = process.platform !== "win32" ? `sudo ${tarPath}` : tarPath;
yield exec_1.exec(`"${tarExec}"`, args);
}
catch (error) {
const IS_WINDOWS = process.platform === "win32";
if (IS_WINDOWS) {
throw new Error(`Tar failed with error: ${(_a = error) === null || _a === void 0 ? void 0 : _a.message}. Ensure BSD tar is installed and on the PATH.`);
}
throw new Error(`Tar failed with error: ${(_b = error) === null || _b === void 0 ? void 0 : _b.message}`);
}
});
}
function extractTar(archivePath, targetDirectory) { function extractTar(archivePath, targetDirectory) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// Create directory to extract tar into // Create directory to extract tar into
yield io.mkdirP(targetDirectory); yield io.mkdirP(targetDirectory);
// http://man7.org/linux/man-pages/man1/tar.1.html
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
const args = ["-xz", "-f", archivePath, "-C", targetDirectory]; const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
yield exec_1.exec(`"${yield getTarPath()}"`, args); yield execTar(args);
}); });
} }
exports.extractTar = extractTar; exports.extractTar = extractTar;
function createTar(archivePath, sourceDirectory) { function createTar(archivePath, sourceDirectory) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// http://man7.org/linux/man-pages/man1/tar.1.html
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."]; const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
yield exec_1.exec(`"${yield getTarPath()}"`, args); yield execTar(args);
}); });
} }
exports.createTar = createTar; exports.createTar = createTar;
function getTarPath() {
return __awaiter(this, void 0, void 0, function* () {
// Explicitly use BSD Tar on Windows
const IS_WINDOWS = process.platform === "win32";
return IS_WINDOWS
? `${process.env["windir"]}\\System32\\tar.exe`
: yield io.which("tar", true);
});
}
/***/ }), /***/ }),

View File

@@ -1,6 +1,6 @@
# Examples # Examples
- [C# - Nuget](#c---nuget) - [C# - NuGet](#c---nuget)
- [Elixir - Mix](#elixir---mix) - [Elixir - Mix](#elixir---mix)
- [Go - Modules](#go---modules) - [Go - Modules](#go---modules)
- [Java - Gradle](#java---gradle) - [Java - Gradle](#java---gradle)
@@ -14,7 +14,7 @@
- [Swift, Objective-C - Carthage](#swift-objective-c---carthage) - [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods) - [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):
```yaml ```yaml
@@ -26,6 +26,21 @@ Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/packa
${{ runner.os }}-nuget- ${{ runner.os }}-nuget-
``` ```
Depending on the environment, huge packages might be pre-installed in the global cache folder.
If you do not want to include them, consider to move the cache folder like below.
>Note: This workflow does not work for projects that require files to be placed in user profile package folder
```yaml
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
steps:
- uses: actions/cache@v1
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
```
## Elixir - Mix ## Elixir - Mix
```yaml ```yaml
- uses: actions/cache@v1 - uses: actions/cache@v1

12
package-lock.json generated
View File

@@ -4859,9 +4859,9 @@
"dev": true "dev": true
}, },
"prettier": { "prettier": {
"version": "1.18.2", "version": "1.19.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz", "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
"integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==", "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
"dev": true "dev": true
}, },
"prettier-linter-helpers": { "prettier-linter-helpers": {
@@ -5983,9 +5983,9 @@
} }
}, },
"typescript": { "typescript": {
"version": "3.6.4", "version": "3.7.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.4.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz",
"integrity": "sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==", "integrity": "sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==",
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {

View File

@@ -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.18.2", "prettier": "^1.19.1",
"ts-jest": "^24.0.2", "ts-jest": "^24.0.2",
"typescript": "^3.6.4" "typescript": "^3.7.3"
} }
} }

View File

@@ -1,12 +1,33 @@
import { exec } from "@actions/exec"; import { exec } from "@actions/exec";
import * as io from "@actions/io"; import * as io from "@actions/io";
import { existsSync } from "fs";
async function getTarPath(): Promise<string> { async function getTarPath(): Promise<string> {
// Explicitly use BSD Tar on Windows // Explicitly use BSD Tar on Windows
const IS_WINDOWS = process.platform === "win32"; const IS_WINDOWS = process.platform === "win32";
return IS_WINDOWS if (IS_WINDOWS) {
? `${process.env["windir"]}\\System32\\tar.exe` const systemTar = `${process.env["windir"]}\\System32\\tar.exe`;
: await io.which("tar", true); if (existsSync(systemTar)) {
return systemTar;
}
}
return await io.which("tar", true);
}
async function execTar(args: string[]): Promise<void> {
try {
const tarPath = await getTarPath();
const tarExec = process.platform !== "win32" ? `sudo ${tarPath}` : tarPath;
await exec(`"${tarExec}"`, args);
} catch (error) {
const IS_WINDOWS = process.platform === "win32";
if (IS_WINDOWS) {
throw new Error(
`Tar failed with error: ${error?.message}. Ensure BSD tar is installed and on the PATH.`
);
}
throw new Error(`Tar failed with error: ${error?.message}`);
}
} }
export async function extractTar( export async function extractTar(
@@ -15,19 +36,14 @@ export async function extractTar(
): Promise<void> { ): Promise<void> {
// Create directory to extract tar into // Create directory to extract tar into
await io.mkdirP(targetDirectory); await io.mkdirP(targetDirectory);
// http://man7.org/linux/man-pages/man1/tar.1.html
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
const args = ["-xz", "-f", archivePath, "-C", targetDirectory]; const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
await exec(`"${await getTarPath()}"`, args); await execTar(args);
} }
export async function createTar( export async function createTar(
archivePath: string, archivePath: string,
sourceDirectory: string sourceDirectory: string
): Promise<void> { ): Promise<void> {
// http://man7.org/linux/man-pages/man1/tar.1.html
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."]; const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
await exec(`"${await getTarPath()}"`, args); await execTar(args);
} }