From ae2427424b3ebbafd6ee3cc148c2186cc8f35f08 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Tue, 13 Aug 2019 17:46:10 +0700 Subject: [PATCH] add helper to extract .tar.xz --- lib/installer.js | 35 ++++++++++++++++++++++++- node_modules/@actions/exec/package.json | 23 ++++++++-------- node_modules/uuid/package.json | 23 ++++++++-------- package-lock.json | 9 +++++++ package.json | 5 +++- src/installer.ts | 35 ++++++++++++++++++++++++- 6 files changed, 103 insertions(+), 27 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index 1c5e2f0..0f4a0ee 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -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; + }); +} diff --git a/node_modules/@actions/exec/package.json b/node_modules/@actions/exec/package.json index 91cec3a..df7db38 100644 --- a/node_modules/@actions/exec/package.json +++ b/node_modules/@actions/exec/package.json @@ -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" diff --git a/node_modules/uuid/package.json b/node_modules/uuid/package.json index 6411532..405cf05 100644 --- a/node_modules/uuid/package.json +++ b/node_modules/uuid/package.json @@ -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", diff --git a/package-lock.json b/package-lock.json index 770b633..e47aef4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 354d2ea..e137bcb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/installer.ts b/src/installer.ts index c29da9d..255e90e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -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 { } 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 { + 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 { + if (!dest) { + dest = path.join(tempDirectory, uuidV4()); + } + + await io.mkdirP(dest); + return dest; +}