1
0
Fork 0
mirror of https://github.com/subosito/flutter-action.git synced 2024-08-16 10:19:50 +02:00

Merge pull request #2 from subosito/tool-cache-110

tool-cache 1.1.0
This commit is contained in:
Alif Rachmawadi 2019-08-26 11:49:37 +07:00 committed by GitHub
commit 8f119fb49d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 690 additions and 780 deletions

View file

@ -14,9 +14,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
result["default"] = mod; result["default"] = mod;
return result; return result;
}; };
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
const io = __importStar(require("@actions/io")); const io = __importStar(require("@actions/io"));
@ -25,8 +22,6 @@ const fs = __importStar(require("fs"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const restm = __importStar(require("typed-rest-client/RestClient")); const restm = __importStar(require("typed-rest-client/RestClient"));
const semver = __importStar(require("semver")); const semver = __importStar(require("semver"));
const v4_1 = __importDefault(require("uuid/v4"));
const exec_1 = require("@actions/exec/lib/exec");
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
const IS_DARWIN = process.platform === 'darwin'; const IS_DARWIN = process.platform === 'darwin';
const IS_LINUX = process.platform === 'linux'; const IS_LINUX = process.platform === 'linux';
@ -122,50 +117,11 @@ function extractFile(file, destDir) {
throw new Error(`Failed to extract ${file} - it is a directory`); throw new Error(`Failed to extract ${file} - it is a directory`);
} }
if ('tar.xz' === extName()) { if ('tar.xz' === extName()) {
yield extractTarXz(file, destDir); yield tc.extractTar(file, destDir, 'x');
}
else {
if (IS_DARWIN) {
yield extractZipDarwin(file, destDir);
} }
else { else {
yield tc.extractZip(file, destDir); yield tc.extractZip(file, destDir);
} }
}
});
}
/**
* Extract a tar.xz
*
* @param file path to the tar.xz
* @param dest destination directory. Optional.
* @returns path to the destination directory
*/
function extractTarXz(file, dest) {
return __awaiter(this, void 0, void 0, function* () {
if (!file) {
throw new Error("parameter 'file' is required");
}
dest = dest || (yield _createExtractFolder(dest));
const tarPath = yield io.which('tar', true);
yield exec_1.exec(`"${tarPath}"`, ['xC', dest, '-f', file]);
return dest;
});
}
exports.extractTarXz = extractTarXz;
function _createExtractFolder(dest) {
return __awaiter(this, void 0, void 0, function* () {
if (!dest) {
dest = path.join(tempDirectory, v4_1.default());
}
yield io.mkdirP(dest);
return dest;
});
}
function extractZipDarwin(file, dest) {
return __awaiter(this, void 0, void 0, function* () {
const unzipPath = path.join(__dirname, '..', 'scripts', 'externals', 'unzip-darwin');
yield exec_1.exec(`"${unzipPath}"`, [file], { cwd: dest });
}); });
} }
function determineVersion(version, channel) { function determineVersion(version, channel) {

View file

@ -1,7 +0,0 @@
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -8,7 +8,7 @@
You can use this to download tools (or other files) from a download URL: You can use this to download tools (or other files) from a download URL:
``` ```js
const tc = require('@actions/tool-cache'); const tc = require('@actions/tool-cache');
const node12Path = await tc.downloadTool('http://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz'); const node12Path = await tc.downloadTool('http://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
@ -18,7 +18,7 @@ const node12Path = await tc.downloadTool('http://nodejs.org/dist/v12.7.0/node-v1
These can then be extracted in platform specific ways: These can then be extracted in platform specific ways:
``` ```js
const tc = require('@actions/tool-cache'); const tc = require('@actions/tool-cache');
if (process.platform === 'win32') { if (process.platform === 'win32') {
@ -41,7 +41,7 @@ Finally, you can cache these directories in our tool-cache. This is useful if yo
You'll often want to add it to the path as part of this step: You'll often want to add it to the path as part of this step:
``` ```js
const tc = require('@actions/tool-cache'); const tc = require('@actions/tool-cache');
const core = require('@actions/core'); const core = require('@actions/core');
@ -54,7 +54,7 @@ core.addPath(cachedPath);
You can also cache files for reuse. You can also cache files for reuse.
``` ```js
const tc = require('@actions/tool-cache'); const tc = require('@actions/tool-cache');
tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0'); tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0');
@ -64,7 +64,7 @@ tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0');
Finally, you can find directories and files you've previously cached: Finally, you can find directories and files you've previously cached:
``` ```js
const tc = require('@actions/tool-cache'); const tc = require('@actions/tool-cache');
const core = require('@actions/core'); const core = require('@actions/core');
@ -74,7 +74,7 @@ core.addPath(nodeDirectory);
You can even find all cached versions of a tool: You can even find all cached versions of a tool:
``` ```js
const tc = require('@actions/tool-cache'); const tc = require('@actions/tool-cache');
const allNodeVersions = tc.findAllVersions('node'); const allNodeVersions = tc.findAllVersions('node');

View file

@ -30,9 +30,10 @@ export declare function extract7z(file: string, dest?: string, _7zPath?: string)
* *
* @param file path to the tar * @param file path to the tar
* @param dest destination directory. Optional. * @param dest destination directory. Optional.
* @param flags flags for the tar. Optional.
* @returns path to the destination directory * @returns path to the destination directory
*/ */
export declare function extractTar(file: string, dest?: string): Promise<string>; export declare function extractTar(file: string, dest?: string, flags?: string): Promise<string>;
/** /**
* Extract a zip * Extract a zip
* *

View file

@ -185,16 +185,17 @@ exports.extract7z = extract7z;
* *
* @param file path to the tar * @param file path to the tar
* @param dest destination directory. Optional. * @param dest destination directory. Optional.
* @param flags flags for the tar. Optional.
* @returns path to the destination directory * @returns path to the destination directory
*/ */
function extractTar(file, dest) { function extractTar(file, dest, flags = 'xz') {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!file) { if (!file) {
throw new Error("parameter 'file' is required"); throw new Error("parameter 'file' is required");
} }
dest = dest || (yield _createExtractFolder(dest)); dest = dest || (yield _createExtractFolder(dest));
const tarPath = yield io.which('tar', true); const tarPath = yield io.which('tar', true);
yield exec_1.exec(`"${tarPath}"`, ['xzC', dest, '-f', file]); yield exec_1.exec(`"${tarPath}"`, [flags, '-C', dest, '-f', file]);
return dest; return dest;
}); });
} }
@ -215,9 +216,14 @@ function extractZip(file, dest) {
if (IS_WINDOWS) { if (IS_WINDOWS) {
yield extractZipWin(file, dest); yield extractZipWin(file, dest);
} }
else {
if (process.platform === 'darwin') {
yield extractZipDarwin(file, dest);
}
else { else {
yield extractZipNix(file, dest); yield extractZipNix(file, dest);
} }
}
return dest; return dest;
}); });
} }
@ -249,6 +255,12 @@ function extractZipNix(file, dest) {
yield exec_1.exec(`"${unzipPath}"`, [file], { cwd: dest }); yield exec_1.exec(`"${unzipPath}"`, [file], { cwd: dest });
}); });
} }
function extractZipDarwin(file, dest) {
return __awaiter(this, void 0, void 0, function* () {
const unzipPath = path.join(__dirname, '..', 'scripts', 'externals', 'unzip-darwin');
yield exec_1.exec(`"${unzipPath}"`, [file], { cwd: dest });
});
}
/** /**
* Caches a directory and installs it into the tool cacheDir * Caches a directory and installs it into the tool cacheDir
* *

File diff suppressed because one or more lines are too long

View file

@ -1,36 +1,32 @@
{ {
"_args": [ "_from": "@actions/tool-cache@^1.1.0",
[ "_id": "@actions/tool-cache@1.1.0",
"@actions/tool-cache@1.0.0",
"/Users/subosito/Code/playground/flutter-actions"
]
],
"_from": "@actions/tool-cache@1.0.0",
"_id": "@actions/tool-cache@1.0.0",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha512-l3zT0IfDfi5Ik5aMpnXqGHGATxN8xa9ls4ue+X/CBXpPhRMRZS4vcuh5Q9T98WAGbkysRCfhpbksTPHIcKnNwQ==", "_integrity": "sha512-Oe/R1Gxv0G699OUL9ypxk9cTwHf1uXHhpcK7kpZt8d/Sbw915ktMkfxXt9+awOfLDwyl54sLi86KGCuSvnRuIQ==",
"_location": "/@actions/tool-cache", "_location": "/@actions/tool-cache",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "version", "type": "range",
"registry": true, "registry": true,
"raw": "@actions/tool-cache@1.0.0", "raw": "@actions/tool-cache@^1.1.0",
"name": "@actions/tool-cache", "name": "@actions/tool-cache",
"escapedName": "@actions%2ftool-cache", "escapedName": "@actions%2ftool-cache",
"scope": "@actions", "scope": "@actions",
"rawSpec": "1.0.0", "rawSpec": "^1.1.0",
"saveSpec": null, "saveSpec": null,
"fetchSpec": "1.0.0" "fetchSpec": "^1.1.0"
}, },
"_requiredBy": [ "_requiredBy": [
"/" "/"
], ],
"_resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.0.0.tgz", "_resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.1.0.tgz",
"_spec": "1.0.0", "_shasum": "1a0e29f244f2b5c6989fc264581068689f9c219e",
"_where": "/Users/subosito/Code/playground/flutter-actions", "_spec": "@actions/tool-cache@^1.1.0",
"_where": "/Users/subosito/Code/subosito/flutter-action",
"bugs": { "bugs": {
"url": "https://github.com/actions/toolkit/issues" "url": "https://github.com/actions/toolkit/issues"
}, },
"bundleDependencies": false,
"dependencies": { "dependencies": {
"@actions/core": "^1.0.0", "@actions/core": "^1.0.0",
"@actions/exec": "^1.0.0", "@actions/exec": "^1.0.0",
@ -39,6 +35,7 @@
"typed-rest-client": "^1.4.0", "typed-rest-client": "^1.4.0",
"uuid": "^3.3.2" "uuid": "^3.3.2"
}, },
"deprecated": false,
"description": "Actions tool-cache lib", "description": "Actions tool-cache lib",
"devDependencies": { "devDependencies": {
"@types/nock": "^10.0.3", "@types/nock": "^10.0.3",
@ -54,7 +51,6 @@
"lib", "lib",
"scripts" "scripts"
], ],
"gitHead": "a40bce7c8d382aa3dbadaa327acbc696e9390e55",
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec", "homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
"keywords": [ "keywords": [
"exec", "exec",
@ -74,5 +70,5 @@
"test": "echo \"Error: run tests from root\" && exit 1", "test": "echo \"Error: run tests from root\" && exit 1",
"tsc": "tsc" "tsc": "tsc"
}, },
"version": "1.0.0" "version": "1.1.0"
} }

Binary file not shown.

6
package-lock.json generated
View file

@ -20,9 +20,9 @@
"integrity": "sha512-ezrJSRdqtXtdx1WXlfYL85+40F7gB39jCK9P0jZVODW3W6xUYmu6ZOEc/UmmElUwhRyDRm1R4yNZu1Joq2kuQg==" "integrity": "sha512-ezrJSRdqtXtdx1WXlfYL85+40F7gB39jCK9P0jZVODW3W6xUYmu6ZOEc/UmmElUwhRyDRm1R4yNZu1Joq2kuQg=="
}, },
"@actions/tool-cache": { "@actions/tool-cache": {
"version": "1.0.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.0.0.tgz", "resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.1.0.tgz",
"integrity": "sha512-l3zT0IfDfi5Ik5aMpnXqGHGATxN8xa9ls4ue+X/CBXpPhRMRZS4vcuh5Q9T98WAGbkysRCfhpbksTPHIcKnNwQ==", "integrity": "sha512-Oe/R1Gxv0G699OUL9ypxk9cTwHf1uXHhpcK7kpZt8d/Sbw915ktMkfxXt9+awOfLDwyl54sLi86KGCuSvnRuIQ==",
"requires": { "requires": {
"@actions/core": "^1.0.0", "@actions/core": "^1.0.0",
"@actions/exec": "^1.0.0", "@actions/exec": "^1.0.0",

View file

@ -26,7 +26,7 @@
"@actions/core": "^1.0.0", "@actions/core": "^1.0.0",
"@actions/exec": "^1.0.0", "@actions/exec": "^1.0.0",
"@actions/io": "^1.0.0", "@actions/io": "^1.0.0",
"@actions/tool-cache": "^1.0.0", "@actions/tool-cache": "^1.1.0",
"semver": "^6.3.0", "semver": "^6.3.0",
"uuid": "^3.3.2" "uuid": "^3.3.2"
}, },

View file

@ -5,8 +5,6 @@ import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import * as restm from 'typed-rest-client/RestClient'; import * as restm from 'typed-rest-client/RestClient';
import * as semver from 'semver'; import * as semver from 'semver';
import uuidV4 from 'uuid/v4';
import {exec} from '@actions/exec/lib/exec';
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
const IS_DARWIN = process.platform === 'darwin'; const IS_DARWIN = process.platform === 'darwin';
@ -130,57 +128,11 @@ async function extractFile(file: string, destDir: string): Promise<void> {
} }
if ('tar.xz' === extName()) { if ('tar.xz' === extName()) {
await extractTarXz(file, destDir); await tc.extractTar(file, destDir, 'x');
} else {
if (IS_DARWIN) {
await extractZipDarwin(file, destDir);
} else { } else {
await tc.extractZip(file, destDir); await tc.extractZip(file, destDir);
} }
} }
}
/**
* Extract a tar.xz
*
* @param file path to the tar.xz
* @param dest destination directory. Optional.
* @returns path to the destination directory
*/
export async function extractTarXz(
file: string,
dest?: string
): Promise<string> {
if (!file) {
throw new Error("parameter 'file' is required");
}
dest = dest || (await _createExtractFolder(dest));
const tarPath: string = await io.which('tar', true);
await exec(`"${tarPath}"`, ['xC', dest, '-f', file]);
return dest;
}
async function _createExtractFolder(dest?: string): Promise<string> {
if (!dest) {
dest = path.join(tempDirectory, uuidV4());
}
await io.mkdirP(dest);
return dest;
}
async function extractZipDarwin(file: string, dest: string): Promise<void> {
const unzipPath = path.join(
__dirname,
'..',
'scripts',
'externals',
'unzip-darwin'
);
await exec(`"${unzipPath}"`, [file], {cwd: dest});
}
async function determineVersion( async function determineVersion(
version: string, version: string,