mirror of
https://github.com/extractions/setup-just
synced 2026-09-14 20:13:55 +00:00
Rework logging
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
"fmt": "node node_modules/.bin/prettier --write **/*.ts",
|
"fmt": "node node_modules/.bin/prettier --write **/*.ts",
|
||||||
"lint": "node node_modules/.bin/eslint **/*.ts",
|
"lint": "node node_modules/.bin/eslint **/*.ts",
|
||||||
"build": "rm -rf dist/ && ncc build src/index.ts --minify",
|
"build": "rm -rf dist/ && ncc build src/index.ts --minify",
|
||||||
"run": "npm run build && node dist/index.js"
|
"run": "npm run build && RUNNER_TOOL_CACHE=./runner/cache RUNNER_TEMP=./runner/temp node dist/index.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
+45
-27
@@ -1,3 +1,4 @@
|
|||||||
|
import * as path from "path";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as tc from "@actions/tool-cache";
|
import * as tc from "@actions/tool-cache";
|
||||||
import * as semver from "semver";
|
import * as semver from "semver";
|
||||||
@@ -34,6 +35,20 @@ interface Tool {
|
|||||||
versionSpec?: string;
|
versionSpec?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an installed tool.
|
||||||
|
*/
|
||||||
|
interface InstalledTool {
|
||||||
|
/** The GitHub owner (username or organization). */
|
||||||
|
owner: string;
|
||||||
|
/** The name of the tool and the GitHub repo name. */
|
||||||
|
name: string;
|
||||||
|
/** The version of the tool. */
|
||||||
|
version: string;
|
||||||
|
/** The directory containing the tool binary. */
|
||||||
|
dir: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single release for a {@link Tool}.
|
* Represents a single release for a {@link Tool}.
|
||||||
*/
|
*/
|
||||||
@@ -103,43 +118,45 @@ async function getRelease(tool: Tool, target: string): Promise<Release> {
|
|||||||
*
|
*
|
||||||
* @returns the directory containing the tool binary.
|
* @returns the directory containing the tool binary.
|
||||||
*/
|
*/
|
||||||
async function checkOrInstallTool(tool: Tool, target: string): Promise<string> {
|
async function checkOrInstallTool(
|
||||||
|
tool: Tool,
|
||||||
|
target: string
|
||||||
|
): Promise<InstalledTool> {
|
||||||
const { name, versionSpec } = tool;
|
const { name, versionSpec } = tool;
|
||||||
|
|
||||||
// first check if we have previously donwloaded the tool
|
// first check if we have previously downloaded the tool
|
||||||
const cache = tc.find(name, versionSpec || "*");
|
let dir = tc.find(name, versionSpec || "*");
|
||||||
if (cache) {
|
|
||||||
core.info(
|
if (!dir) {
|
||||||
`${name} matching version specifier ${versionSpec} found in cache`
|
// find the latest release by querying GitHub API
|
||||||
);
|
const { version, downloadUrl } = await getRelease(tool, target);
|
||||||
return cache;
|
|
||||||
|
// download, extract, and cache the tool
|
||||||
|
const artifact = await tc.downloadTool(downloadUrl);
|
||||||
|
core.debug(`Successfully downloaded ${name} v${version}`);
|
||||||
|
|
||||||
|
let extractDir;
|
||||||
|
if (downloadUrl.endsWith(".zip")) {
|
||||||
|
extractDir = await tc.extractZip(artifact);
|
||||||
|
} else {
|
||||||
|
extractDir = await tc.extractTar(artifact);
|
||||||
|
}
|
||||||
|
core.debug(`Successfully extracted archive for ${name} v${version}`);
|
||||||
|
|
||||||
|
dir = await tc.cacheDir(extractDir, name, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the latest release by querying GitHub API
|
// FIXME: is there a better way to get the version?
|
||||||
const { version, downloadUrl } = await getRelease(tool, target);
|
const version = path.basename(path.dirname(dir));
|
||||||
|
|
||||||
// download, extract, and cache the tool
|
return { version, dir, ...tool };
|
||||||
core.info(`Download from "${downloadUrl}"`);
|
|
||||||
const artifact = await tc.downloadTool(downloadUrl);
|
|
||||||
|
|
||||||
core.info("Extract downloaded archive");
|
|
||||||
const dir = `./${name}-${version}`;
|
|
||||||
|
|
||||||
let extractDir;
|
|
||||||
if (downloadUrl.endsWith(".zip")) {
|
|
||||||
extractDir = await tc.extractZip(artifact, dir);
|
|
||||||
} else {
|
|
||||||
extractDir = await tc.extractTar(artifact, dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tc.cacheDir(extractDir, name, version);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const versionSpec = core.getInput("just-version");
|
const versionSpec = core.getInput("just-version");
|
||||||
const target = getTarget();
|
const target = getTarget();
|
||||||
const cacheDir = await checkOrInstallTool(
|
const tool = await checkOrInstallTool(
|
||||||
{
|
{
|
||||||
owner: "casey",
|
owner: "casey",
|
||||||
name: "just",
|
name: "just",
|
||||||
@@ -147,7 +164,8 @@ async function main() {
|
|||||||
},
|
},
|
||||||
target
|
target
|
||||||
);
|
);
|
||||||
core.addPath(cacheDir);
|
core.addPath(tool.dir);
|
||||||
|
core.info(`Successfully setup ${tool.name} v${tool.version}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.setFailed(err.message);
|
core.setFailed(err.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user