fix: binary download
Some checks failed
Check Transpiled JavaScript / Check dist/ (push) Has been cancelled
Continuous Integration / GitHub Actions Test (push) Failing after 9s
Continuous Integration / TypeScript Tests (push) Failing after 32s

This commit is contained in:
Peter 2024-05-03 14:12:12 +02:00
parent 4431e4a952
commit 0bd5f12663
Signed by: prskr
GPG key ID: F56BED6903BC5E37
11 changed files with 395 additions and 64 deletions

321
dist/index.js vendored
View file

@ -1729,6 +1729,259 @@ class ExecState extends events.EventEmitter {
/***/ }),
/***/ 4087:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Context = void 0;
const fs_1 = __nccwpck_require__(7147);
const os_1 = __nccwpck_require__(2037);
class Context {
/**
* Hydrate the context from the environment
*/
constructor() {
var _a, _b, _c;
this.payload = {};
if (process.env.GITHUB_EVENT_PATH) {
if ((0, fs_1.existsSync)(process.env.GITHUB_EVENT_PATH)) {
this.payload = JSON.parse((0, fs_1.readFileSync)(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' }));
}
else {
const path = process.env.GITHUB_EVENT_PATH;
process.stdout.write(`GITHUB_EVENT_PATH ${path} does not exist${os_1.EOL}`);
}
}
this.eventName = process.env.GITHUB_EVENT_NAME;
this.sha = process.env.GITHUB_SHA;
this.ref = process.env.GITHUB_REF;
this.workflow = process.env.GITHUB_WORKFLOW;
this.action = process.env.GITHUB_ACTION;
this.actor = process.env.GITHUB_ACTOR;
this.job = process.env.GITHUB_JOB;
this.runNumber = parseInt(process.env.GITHUB_RUN_NUMBER, 10);
this.runId = parseInt(process.env.GITHUB_RUN_ID, 10);
this.apiUrl = (_a = process.env.GITHUB_API_URL) !== null && _a !== void 0 ? _a : `https://api.github.com`;
this.serverUrl = (_b = process.env.GITHUB_SERVER_URL) !== null && _b !== void 0 ? _b : `https://github.com`;
this.graphqlUrl =
(_c = process.env.GITHUB_GRAPHQL_URL) !== null && _c !== void 0 ? _c : `https://api.github.com/graphql`;
}
get issue() {
const payload = this.payload;
return Object.assign(Object.assign({}, this.repo), { number: (payload.issue || payload.pull_request || payload).number });
}
get repo() {
if (process.env.GITHUB_REPOSITORY) {
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
return { owner, repo };
}
if (this.payload.repository) {
return {
owner: this.payload.repository.owner.login,
repo: this.payload.repository.name
};
}
throw new Error("context.repo requires a GITHUB_REPOSITORY environment variable like 'owner/repo'");
}
}
exports.Context = Context;
//# sourceMappingURL=context.js.map
/***/ }),
/***/ 5438:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getOctokit = exports.context = void 0;
const Context = __importStar(__nccwpck_require__(4087));
const utils_1 = __nccwpck_require__(3030);
exports.context = new Context.Context();
/**
* Returns a hydrated octokit ready to use for GitHub Actions
*
* @param token the repo PAT or GITHUB_TOKEN
* @param options other options to set
*/
function getOctokit(token, options, ...additionalPlugins) {
const GitHubWithPlugins = utils_1.GitHub.plugin(...additionalPlugins);
return new GitHubWithPlugins((0, utils_1.getOctokitOptions)(token, options));
}
exports.getOctokit = getOctokit;
//# sourceMappingURL=github.js.map
/***/ }),
/***/ 7914:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getApiBaseUrl = exports.getProxyFetch = exports.getProxyAgentDispatcher = exports.getProxyAgent = exports.getAuthString = void 0;
const httpClient = __importStar(__nccwpck_require__(6255));
const undici_1 = __nccwpck_require__(1773);
function getAuthString(token, options) {
if (!token && !options.auth) {
throw new Error('Parameter token or opts.auth is required');
}
else if (token && options.auth) {
throw new Error('Parameters token and opts.auth may not both be specified');
}
return typeof options.auth === 'string' ? options.auth : `token ${token}`;
}
exports.getAuthString = getAuthString;
function getProxyAgent(destinationUrl) {
const hc = new httpClient.HttpClient();
return hc.getAgent(destinationUrl);
}
exports.getProxyAgent = getProxyAgent;
function getProxyAgentDispatcher(destinationUrl) {
const hc = new httpClient.HttpClient();
return hc.getAgentDispatcher(destinationUrl);
}
exports.getProxyAgentDispatcher = getProxyAgentDispatcher;
function getProxyFetch(destinationUrl) {
const httpDispatcher = getProxyAgentDispatcher(destinationUrl);
const proxyFetch = (url, opts) => __awaiter(this, void 0, void 0, function* () {
return (0, undici_1.fetch)(url, Object.assign(Object.assign({}, opts), { dispatcher: httpDispatcher }));
});
return proxyFetch;
}
exports.getProxyFetch = getProxyFetch;
function getApiBaseUrl() {
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
}
exports.getApiBaseUrl = getApiBaseUrl;
//# sourceMappingURL=utils.js.map
/***/ }),
/***/ 3030:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getOctokitOptions = exports.GitHub = exports.defaults = exports.context = void 0;
const Context = __importStar(__nccwpck_require__(4087));
const Utils = __importStar(__nccwpck_require__(7914));
// octokit + plugins
const core_1 = __nccwpck_require__(6762);
const plugin_rest_endpoint_methods_1 = __nccwpck_require__(3044);
const plugin_paginate_rest_1 = __nccwpck_require__(4193);
exports.context = new Context.Context();
const baseUrl = Utils.getApiBaseUrl();
exports.defaults = {
baseUrl,
request: {
agent: Utils.getProxyAgent(baseUrl),
fetch: Utils.getProxyFetch(baseUrl)
}
};
exports.GitHub = core_1.Octokit.plugin(plugin_rest_endpoint_methods_1.restEndpointMethods, plugin_paginate_rest_1.paginateRest).defaults(exports.defaults);
/**
* Convience function to correctly format Octokit Options to pass into the constructor.
*
* @param token the repo PAT or GITHUB_TOKEN
* @param options other options to set
*/
function getOctokitOptions(token, options) {
const opts = Object.assign({}, options || {}); // Shallow clone - don't mutate the object provided by the caller
// Auth
const auth = Utils.getAuthString(token, opts);
if (auth) {
opts.auth = auth;
}
return opts;
}
exports.getOctokitOptions = getOctokitOptions;
//# sourceMappingURL=utils.js.map
/***/ }),
/***/ 5526:
/***/ (function(__unused_webpack_module, exports) {
@ -49091,7 +49344,7 @@ var DartSass;
})(DartSass || (DartSass = {}));
var Action;
(function (Action) {
Action["WorkDirName"] = "actions_hugo";
Action["WorkDirName"] = "actions_hugo_setup";
Action["TempDirName"] = "_temp";
})(Action || (Action = {}));
@ -49117,25 +49370,28 @@ class Platform {
this.arch = arch;
this.env = env;
}
isWindows() {
return this.os === 'win32';
}
archiveExtension() {
if (this.os === 'win32') {
if (this.isWindows()) {
return '.zip';
}
return '.tar.gz';
}
binaryName(base) {
if (this.isWindows()) {
return `${base}.exec`;
}
return base;
}
async createWorkDir() {
const workDir = external_path_default().join(this.getHomeDir(), Action.WorkDirName);
await io.mkdirP(workDir);
core.debug(`workDir: ${workDir}`);
return workDir;
}
async createTempDir(workDir) {
const tempDir = external_path_default().join(workDir, Action.TempDirName);
await io.mkdirP(tempDir);
core.debug(`tempDir: ${tempDir}`);
return tempDir;
}
async createBinDir(workDir) {
async ensureBinDir(workDir) {
const binDir = external_path_default().join(workDir, 'bin');
await io.mkdirP(binDir);
core.addPath(binDir);
@ -49143,7 +49399,7 @@ class Platform {
return binDir;
}
getHomeDir() {
const homedir = this.os === 'win32'
const homedir = this.isWindows()
? this.env['USERPROFILE'] || 'C:\\'
: this.env.HOME || '/root';
core.debug(`homeDir: ${homedir}`);
@ -49153,11 +49409,16 @@ class Platform {
// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js
var tool_cache = __nccwpck_require__(7784);
;// CONCATENATED MODULE: external "node:os"
const external_node_os_namespaceObject = require("node:os");
;// CONCATENATED MODULE: ./src/hugo.ts
class HugoInstaller {
releaseLookup;
platform;
@ -49171,13 +49432,23 @@ class HugoInstaller {
core.debug(`Operating System: ${this.platform.os}`);
core.debug(`Processor Architecture: ${this.platform.arch}`);
const workDir = await this.platform.createWorkDir();
const binDir = await this.platform.createBinDir(workDir);
const tempDir = await this.platform.createTempDir(workDir);
const binDir = await this.platform.ensureBinDir(workDir);
const tmpDir = external_node_os_namespaceObject.tmpdir();
const toolUrl = release.assetUrl(this.platform, cmd.extended);
if (!toolUrl) {
throw new Error('No matching URL detected for given platform');
}
await (0,tool_cache.downloadTool)(toolUrl, binDir, tempDir);
const destPath = external_path_default().join(tmpDir, `hugo${this.platform.archiveExtension()}`);
await tool_cache.downloadTool(toolUrl, destPath);
core.debug(`Extract archive: ${destPath}`);
if (this.platform.isWindows()) {
await tool_cache.extractZip(destPath, tmpDir);
}
else {
await tool_cache.extractTar(destPath, tmpDir);
}
core.debug(`move binaries to binDir: ${binDir}`);
await (0,io.mv)(external_path_default().join(tmpDir, this.platform.binaryName(Hugo.CmdName)), binDir);
}
}
const HugoReleaseTransformer = {
@ -49211,14 +49482,17 @@ class HugoRelease {
}
}
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
var github = __nccwpck_require__(5438);
// EXTERNAL MODULE: ./node_modules/octokit/dist-node/index.js
var dist_node = __nccwpck_require__(7467);
;// CONCATENATED MODULE: ./src/asset-lookup.ts
class OctokitReleaseLookup {
octokit;
constructor(pat) {
this.octokit = new dist_node.Octokit({ auth: pat });
this.octokit = pat ? (0,github.getOctokit)(pat) : new dist_node.Octokit();
}
async getRelease(owner, repo, version, transformer) {
const latestRelease = version && version !== 'latest'
@ -49240,6 +49514,9 @@ class OctokitReleaseLookup {
class DartSassInstaller {
releaseLookup;
platform;
@ -49252,13 +49529,23 @@ class DartSassInstaller {
core.debug(`Operating System: ${this.platform.os}`);
core.debug(`Processor Architecture: ${this.platform.arch}`);
const workDir = await this.platform.createWorkDir();
const binDir = await this.platform.createBinDir(workDir);
const tempDir = await this.platform.createTempDir(workDir);
const binDir = await this.platform.ensureBinDir(workDir);
const tmpDir = external_node_os_namespaceObject.tmpdir();
const toolUrl = release.assetUrl(this.platform);
if (!toolUrl) {
throw new Error('No matching URL detected for given platform');
}
await (0,tool_cache.downloadTool)(toolUrl, binDir, tempDir);
const destPath = external_path_default().join(tmpDir, `dart-sass${this.platform.archiveExtension()}`);
await tool_cache.downloadTool(toolUrl, destPath);
core.debug(`Extract archive: ${destPath}`);
if (this.platform.isWindows()) {
await tool_cache.extractZip(destPath, tmpDir);
}
else {
await tool_cache.extractTar(destPath, tmpDir);
}
core.debug(`move binaries to binDir: ${binDir}`);
await (0,io.mv)(external_path_default().join(tmpDir, 'dart-sass', '*'), binDir);
}
}
const DartSassReleaseTransformer = {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

12
dist/licenses.txt vendored
View file

@ -22,6 +22,18 @@ The above copyright notice and this permission notice shall be included in all c
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.
@actions/github
MIT
The MIT License (MIT)
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.
@actions/http-client
MIT
Actions Http Client for Node.js

12
package-lock.json generated
View file

@ -11,6 +11,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1",
"octokit": "^3.2.0"
@ -56,6 +57,17 @@
"@actions/io": "^1.0.1"
}
},
"node_modules/@actions/github": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@actions/github/-/github-6.0.0.tgz",
"integrity": "sha512-alScpSVnYmjNEXboZjarjukQEzgCRmjMv6Xj47fsdnqGS73bjJNDpiiXmp8jr0UZLdUB6d9jW63IcmddUP+l0g==",
"dependencies": {
"@actions/http-client": "^2.2.0",
"@octokit/core": "^5.0.1",
"@octokit/plugin-paginate-rest": "^9.0.0",
"@octokit/plugin-rest-endpoint-methods": "^10.0.0"
}
},
"node_modules/@actions/http-client": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.1.tgz",

View file

@ -65,6 +65,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1",
"octokit": "^3.2.0"

View file

@ -1,5 +1,7 @@
import { Octokit } from 'octokit'
import { getOctokit } from '@actions/github'
import { components } from '@octokit/openapi-types/types'
import { GitHub } from '@actions/github/lib/utils'
import { Octokit } from 'octokit'
export interface IGithubRelease {
readonly tag_name: string
@ -19,10 +21,10 @@ export interface IReleaseLookup {
}
export class OctokitReleaseLookup implements IReleaseLookup {
octokit: Octokit
octokit: InstanceType<typeof GitHub> | Octokit
constructor(pat?: string) {
this.octokit = new Octokit({ auth: pat })
this.octokit = pat ? getOctokit(pat) : new Octokit()
}
async getRelease<T extends IGithubRelease>(

20
src/cache/download.ts vendored
View file

@ -1,20 +0,0 @@
import * as tc from '@actions/tool-cache'
import { Hugo as HugoTool } from '../constants'
import * as io from '@actions/io'
async function downloadTool(
toolURL: string,
binDir: string,
tempDir: string
): Promise<void> {
const toolAssets: string = await tc.downloadTool(toolURL)
let toolBin = ''
if (process.platform === 'win32') {
const toolExtractedFolder: string = await tc.extractZip(toolAssets, tempDir)
toolBin = `${toolExtractedFolder}/${HugoTool.CmdName}.exe`
} else {
const toolExtractedFolder: string = await tc.extractTar(toolAssets, tempDir)
toolBin = `${toolExtractedFolder}/${HugoTool.CmdName}`
}
await io.mv(toolBin, binDir)
}

View file

@ -14,6 +14,6 @@ export enum DartSass {
}
export enum Action {
WorkDirName = 'actions_hugo',
WorkDirName = 'actions_hugo_setup',
TempDirName = '_temp'
}

View file

@ -1,9 +1,12 @@
import { IGithubRelease, IReleaseLookup } from './asset-lookup'
import { DartSass } from './constants'
import { DartSass, Hugo } from './constants'
import { components } from '@octokit/openapi-types'
import * as tc from '@actions/tool-cache'
import * as core from '@actions/core'
import { Platform } from './os'
import { downloadTool } from '@actions/tool-cache'
import * as os from 'node:os'
import path from 'path'
import { mv } from '@actions/io'
export interface IDartSassInstallCommand {
version: string
@ -30,8 +33,8 @@ export class DartSassInstaller {
core.debug(`Processor Architecture: ${this.platform.arch}`)
const workDir = await this.platform.createWorkDir()
const binDir = await this.platform.createBinDir(workDir)
const tempDir = await this.platform.createTempDir(workDir)
const binDir = await this.platform.ensureBinDir(workDir)
const tmpDir = os.tmpdir()
const toolUrl = release.assetUrl(this.platform)
@ -39,7 +42,21 @@ export class DartSassInstaller {
throw new Error('No matching URL detected for given platform')
}
await downloadTool(toolUrl, binDir, tempDir)
const destPath = path.join(
tmpDir,
`dart-sass${this.platform.archiveExtension()}`
)
await tc.downloadTool(toolUrl, destPath)
core.debug(`Extract archive: ${destPath}`)
if (this.platform.isWindows()) {
await tc.extractZip(destPath, tmpDir)
} else {
await tc.extractTar(destPath, tmpDir)
}
core.debug(`move binaries to binDir: ${binDir}`)
await mv(path.join(tmpDir, 'dart-sass', '*'), binDir)
}
}

View file

@ -3,7 +3,10 @@ import { Hugo } from './constants'
import { IGithubRelease, IReleaseLookup } from './asset-lookup'
import { Platform } from './os'
import { components } from '@octokit/openapi-types'
import { downloadTool } from '@actions/tool-cache'
import * as tc from '@actions/tool-cache'
import path from 'path'
import * as os from 'node:os'
import { mv } from '@actions/io'
export interface IHugoInstallCommand {
version: string
@ -32,8 +35,8 @@ export class HugoInstaller {
core.debug(`Processor Architecture: ${this.platform.arch}`)
const workDir = await this.platform.createWorkDir()
const binDir = await this.platform.createBinDir(workDir)
const tempDir = await this.platform.createTempDir(workDir)
const binDir = await this.platform.ensureBinDir(workDir)
const tmpDir = os.tmpdir()
const toolUrl = release.assetUrl(this.platform, cmd.extended)
@ -41,7 +44,21 @@ export class HugoInstaller {
throw new Error('No matching URL detected for given platform')
}
await downloadTool(toolUrl, binDir, tempDir)
const destPath = path.join(
tmpDir,
`hugo${this.platform.archiveExtension()}`
)
await tc.downloadTool(toolUrl, destPath)
core.debug(`Extract archive: ${destPath}`)
if (this.platform.isWindows()) {
await tc.extractZip(destPath, tmpDir)
} else {
await tc.extractTar(destPath, tmpDir)
}
core.debug(`move binaries to binDir: ${binDir}`)
await mv(path.join(tmpDir, this.platform.binaryName(Hugo.CmdName)), binDir)
}
}

View file

@ -23,13 +23,24 @@ export class Platform {
this.env = env
}
isWindows(): boolean {
return this.os === 'win32'
}
archiveExtension(): string {
if (this.os === 'win32') {
if (this.isWindows()) {
return '.zip'
}
return '.tar.gz'
}
binaryName(base: string): string {
if (this.isWindows()) {
return `${base}.exec`
}
return base
}
async createWorkDir(): Promise<string> {
const workDir = path.join(this.getHomeDir(), Action.WorkDirName)
await io.mkdirP(workDir)
@ -37,14 +48,7 @@ export class Platform {
return workDir
}
async createTempDir(workDir: string): Promise<string> {
const tempDir = path.join(workDir, Action.TempDirName)
await io.mkdirP(tempDir)
core.debug(`tempDir: ${tempDir}`)
return tempDir
}
async createBinDir(workDir: string): Promise<string> {
async ensureBinDir(workDir: string): Promise<string> {
const binDir = path.join(workDir, 'bin')
await io.mkdirP(binDir)
core.addPath(binDir)
@ -53,10 +57,9 @@ export class Platform {
}
getHomeDir(): string {
const homedir =
this.os === 'win32'
? this.env['USERPROFILE'] || 'C:\\'
: this.env.HOME || '/root'
const homedir = this.isWindows()
? this.env['USERPROFILE'] || 'C:\\'
: this.env.HOME || '/root'
core.debug(`homeDir: ${homedir}`)