mirror of
https://github.com/subosito/flutter-action.git
synced 2024-08-16 10:19:50 +02:00
add helper to extract .tar.xz
This commit is contained in:
parent
d34b182ed1
commit
ae2427424b
6 changed files with 103 additions and 27 deletions
|
@ -14,12 +14,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const io = __importStar(require("@actions/io"));
|
||||
const tc = __importStar(require("@actions/tool-cache"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const v4_1 = __importDefault(require("uuid/v4"));
|
||||
const exec_1 = require("@actions/exec/lib/exec");
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const IS_DARWIN = process.platform === 'darwin';
|
||||
const IS_LINUX = process.platform === 'linux';
|
||||
|
@ -108,10 +113,38 @@ function extractFile(file, destDir) {
|
|||
throw new Error(`Failed to extract ${file} - it is a directory`);
|
||||
}
|
||||
if ('tar.xz' === extName()) {
|
||||
yield tc.extract7z(file, destDir);
|
||||
yield extractTarXz(file, destDir);
|
||||
}
|
||||
else {
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
|
23
node_modules/@actions/exec/package.json
generated
vendored
23
node_modules/@actions/exec/package.json
generated
vendored
|
@ -1,36 +1,35 @@
|
|||
{
|
||||
"_args": [
|
||||
[
|
||||
"@actions/exec@1.0.0",
|
||||
"/Users/subosito/Code/playground/flutter-actions"
|
||||
]
|
||||
],
|
||||
"_from": "@actions/exec@1.0.0",
|
||||
"_from": "@actions/exec",
|
||||
"_id": "@actions/exec@1.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-nquH0+XKng+Ll7rZfCojN7NWSbnGh+ltwUJhzfbLkmOJgxocGX2/yXcZLMyT9fa7+tByEow/NSTrBExNlEj9fw==",
|
||||
"_location": "/@actions/exec",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "@actions/exec@1.0.0",
|
||||
"raw": "@actions/exec",
|
||||
"name": "@actions/exec",
|
||||
"escapedName": "@actions%2fexec",
|
||||
"scope": "@actions",
|
||||
"rawSpec": "1.0.0",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.0"
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/",
|
||||
"/@actions/tool-cache"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.0.tgz",
|
||||
"_spec": "1.0.0",
|
||||
"_shasum": "70c8b698c9baa02965c07da5f0b185ca56f0a955",
|
||||
"_spec": "@actions/exec",
|
||||
"_where": "/Users/subosito/Code/playground/flutter-actions",
|
||||
"bugs": {
|
||||
"url": "https://github.com/actions/toolkit/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Actions exec lib",
|
||||
"devDependencies": {
|
||||
"@actions/io": "^1.0.0"
|
||||
|
|
23
node_modules/uuid/package.json
generated
vendored
23
node_modules/uuid/package.json
generated
vendored
|
@ -1,32 +1,29 @@
|
|||
{
|
||||
"_args": [
|
||||
[
|
||||
"uuid@3.3.2",
|
||||
"/Users/subosito/Code/playground/flutter-actions"
|
||||
]
|
||||
],
|
||||
"_from": "uuid@3.3.2",
|
||||
"_from": "uuid",
|
||||
"_id": "uuid@3.3.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==",
|
||||
"_location": "/uuid",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "uuid@3.3.2",
|
||||
"raw": "uuid",
|
||||
"name": "uuid",
|
||||
"escapedName": "uuid",
|
||||
"rawSpec": "3.3.2",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "3.3.2"
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/",
|
||||
"/@actions/tool-cache",
|
||||
"/request"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
|
||||
"_spec": "3.3.2",
|
||||
"_shasum": "1b4af4955eb3077c501c23872fc6513811587131",
|
||||
"_spec": "uuid",
|
||||
"_where": "/Users/subosito/Code/playground/flutter-actions",
|
||||
"bin": {
|
||||
"uuid": "./bin/uuid"
|
||||
|
@ -39,6 +36,7 @@
|
|||
"bugs": {
|
||||
"url": "https://github.com/kelektiv/node-uuid/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
|
@ -66,6 +64,7 @@
|
|||
"email": "shtylman@gmail.com"
|
||||
}
|
||||
],
|
||||
"deprecated": false,
|
||||
"description": "RFC4122 (v1, v4, and v5) UUIDs",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "7.0.0",
|
||||
|
|
9
package-lock.json
generated
9
package-lock.json
generated
|
@ -554,6 +554,15 @@
|
|||
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/uuid": {
|
||||
"version": "3.4.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.5.tgz",
|
||||
"integrity": "sha512-MNL15wC3EKyw1VLF+RoVO4hJJdk9t/Hlv3rt1OL65Qvuadm4BYo6g9ZJQqoq7X8NBFSsQXgAujWciovh2lpVjA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/yargs": {
|
||||
"version": "12.0.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-12.0.12.tgz",
|
||||
|
|
|
@ -24,13 +24,16 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.0.0",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/io": "^1.0.0",
|
||||
"@actions/tool-cache": "^1.0.0"
|
||||
"@actions/tool-cache": "^1.0.0",
|
||||
"uuid": "^3.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.13",
|
||||
"@types/node": "^12.0.4",
|
||||
"@types/semver": "^6.0.0",
|
||||
"@types/uuid": "^3.4.5",
|
||||
"husky": "^3.0.0",
|
||||
"jest": "^24.8.0",
|
||||
"jest-circus": "^24.7.1",
|
||||
|
|
|
@ -3,6 +3,8 @@ import * as io from '@actions/io';
|
|||
import * as tc from '@actions/tool-cache';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import uuidV4 from 'uuid/v4';
|
||||
import {exec} from '@actions/exec/lib/exec';
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const IS_DARWIN = process.platform === 'darwin';
|
||||
|
@ -115,8 +117,39 @@ async function extractFile(file: string, destDir: string): Promise<void> {
|
|||
}
|
||||
|
||||
if ('tar.xz' === extName()) {
|
||||
await tc.extract7z(file, destDir);
|
||||
await extractTarXz(file, destDir);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue