Use @actions/io to locate binaries
This commit is contained in:
parent
64cc90bcd4
commit
b58f4471c8
36 changed files with 69 additions and 233 deletions
|
|
@ -3,7 +3,7 @@ import * as path from "path";
|
|||
|
||||
import * as core from "@actions/core";
|
||||
import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import * as safeWhich from "@chrisgavin/safe-which";
|
||||
import * as io from "@actions/io";
|
||||
import { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package";
|
||||
|
||||
import type { Config } from "./config-utils";
|
||||
|
|
@ -209,7 +209,7 @@ export const getFileType = async (filePath: string): Promise<string> => {
|
|||
let fileCmdPath: string;
|
||||
|
||||
try {
|
||||
fileCmdPath = await safeWhich.safeWhich("file");
|
||||
fileCmdPath = await io.which("file", true);
|
||||
} catch (e) {
|
||||
throw new FileCmdNotFoundError(
|
||||
`The \`file\` program is required, but does not appear to be installed. Please install it: ${e}`,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import * as fs from "fs";
|
|||
import * as path from "path";
|
||||
import { performance } from "perf_hooks";
|
||||
|
||||
import { safeWhich } from "@chrisgavin/safe-which";
|
||||
import * as io from "@actions/io";
|
||||
import del from "del";
|
||||
import * as yaml from "js-yaml";
|
||||
|
||||
|
|
@ -660,7 +660,7 @@ export async function warnIfGoInstalledAfterInit(
|
|||
process.env[EnvVar.DID_AUTOBUILD_GOLANG] !== "true" &&
|
||||
goInitPath !== undefined
|
||||
) {
|
||||
const goBinaryPath = await safeWhich("go");
|
||||
const goBinaryPath = await io.which("go", true);
|
||||
|
||||
if (goInitPath !== goBinaryPath) {
|
||||
logger.warning(
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import * as fs from "fs";
|
|||
|
||||
import { ExecOptions } from "@actions/exec";
|
||||
import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import * as io from "@actions/io";
|
||||
import * as toolcache from "@actions/tool-cache";
|
||||
import * as safeWhich from "@chrisgavin/safe-which";
|
||||
import test, { ExecutionContext } from "ava";
|
||||
import del from "del";
|
||||
import * as yaml from "js-yaml";
|
||||
|
|
@ -819,8 +819,8 @@ for (const {
|
|||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(codeqlVersion);
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
// io throws because of the test CodeQL object.
|
||||
sinon.stub(io, "which").resolves("");
|
||||
await codeqlObject.databaseInterpretResults(
|
||||
"",
|
||||
[],
|
||||
|
|
@ -860,8 +860,8 @@ test("runTool summarizes several fatal errors", async (t) => {
|
|||
stubToolRunnerConstructor(32, cliStderr);
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
// io throws because of the test CodeQL object.
|
||||
sinon.stub(io, "which").resolves("");
|
||||
|
||||
await t.throwsAsync(
|
||||
async () =>
|
||||
|
|
@ -902,8 +902,8 @@ test("runTool summarizes autobuilder errors", async (t) => {
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
|
||||
sinon.stub(codeqlObject, "resolveExtractor").resolves("/path/to/extractor");
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
// io throws because of the test CodeQL object.
|
||||
sinon.stub(io, "which").resolves("");
|
||||
|
||||
await t.throwsAsync(
|
||||
async () => await codeqlObject.runAutobuild(stubConfig, Language.java),
|
||||
|
|
@ -929,8 +929,8 @@ test("runTool truncates long autobuilder errors", async (t) => {
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
|
||||
sinon.stub(codeqlObject, "resolveExtractor").resolves("/path/to/extractor");
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
// io throws because of the test CodeQL object.
|
||||
sinon.stub(io, "which").resolves("");
|
||||
|
||||
await t.throwsAsync(
|
||||
async () => await codeqlObject.runAutobuild(stubConfig, Language.java),
|
||||
|
|
@ -957,8 +957,8 @@ test("runTool recognizes fatal internal errors", async (t) => {
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
|
||||
sinon.stub(codeqlObject, "resolveExtractor").resolves("/path/to/extractor");
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
// io throws because of the test CodeQL object.
|
||||
sinon.stub(io, "which").resolves("");
|
||||
|
||||
await t.throwsAsync(
|
||||
async () =>
|
||||
|
|
@ -977,8 +977,8 @@ test("runTool outputs last line of stderr if fatal error could not be found", as
|
|||
stubToolRunnerConstructor(32, cliStderr);
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
// io throws because of the test CodeQL object.
|
||||
sinon.stub(io, "which").resolves("");
|
||||
|
||||
await t.throwsAsync(
|
||||
async () =>
|
||||
|
|
@ -1002,8 +1002,8 @@ test("Avoids duplicating --overwrite flag if specified in CODEQL_ACTION_EXTRA_OP
|
|||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
// io throws because of the test CodeQL object.
|
||||
sinon.stub(io, "which").resolves("");
|
||||
|
||||
process.env["CODEQL_ACTION_EXTRA_OPTIONS"] =
|
||||
'{ "database": { "init": ["--overwrite"] } }';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import * as safeWhich from "@chrisgavin/safe-which";
|
||||
import * as io from "@actions/io";
|
||||
|
||||
import {
|
||||
getOptionalInput,
|
||||
|
|
@ -18,7 +18,7 @@ async function runGitCommand(
|
|||
let stderr = "";
|
||||
core.debug(`Running git command: git ${args.join(" ")}`);
|
||||
try {
|
||||
await new toolrunner.ToolRunner(await safeWhich.safeWhich("git"), args, {
|
||||
await new toolrunner.ToolRunner(await io.which("git", true), args, {
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import * as fs from "fs";
|
|||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import { safeWhich } from "@chrisgavin/safe-which";
|
||||
import * as io from "@actions/io";
|
||||
import { v4 as uuidV4 } from "uuid";
|
||||
|
||||
import {
|
||||
|
|
@ -445,7 +445,7 @@ async function run() {
|
|||
process.platform === "linux"
|
||||
) {
|
||||
try {
|
||||
const goBinaryPath = await safeWhich("go");
|
||||
const goBinaryPath = await io.which("go", true);
|
||||
const fileOutput = await getFileType(goBinaryPath);
|
||||
|
||||
// Go 1.21 and above ships with statically linked binaries on Linux. CodeQL cannot currently trace custom builds
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import * as fs from "fs";
|
|||
import * as path from "path";
|
||||
|
||||
import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import * as safeWhich from "@chrisgavin/safe-which";
|
||||
import * as io from "@actions/io";
|
||||
|
||||
import { getOptionalInput, isSelfHostedRunner } from "./actions-util";
|
||||
import { GitHubApiCombinedDetails, GitHubApiDetails } from "./api-client";
|
||||
|
|
@ -150,7 +150,7 @@ export async function checkInstallPython311(
|
|||
"../python-setup",
|
||||
"check_python12.ps1",
|
||||
);
|
||||
await new toolrunner.ToolRunner(await safeWhich.safeWhich("powershell"), [
|
||||
await new toolrunner.ToolRunner(await io.which("powershell", true), [
|
||||
script,
|
||||
]).exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import * as fs from "fs";
|
|||
import * as stream from "stream";
|
||||
|
||||
import { ToolRunner } from "@actions/exec/lib/toolrunner";
|
||||
import * as io from "@actions/io";
|
||||
import * as toolcache from "@actions/tool-cache";
|
||||
import { safeWhich } from "@chrisgavin/safe-which";
|
||||
|
||||
import { CommandInvocationError } from "./actions-util";
|
||||
import { Logger } from "./logging";
|
||||
|
|
@ -19,7 +19,7 @@ export type TarVersion = {
|
|||
};
|
||||
|
||||
async function getTarVersion(): Promise<TarVersion> {
|
||||
const tar = await safeWhich("tar");
|
||||
const tar = await io.which("tar", true);
|
||||
let stdout = "";
|
||||
const exitCode = await new ToolRunner(tar, ["--version"], {
|
||||
listeners: {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { promisify } from "util";
|
|||
|
||||
import * as core from "@actions/core";
|
||||
import * as exec from "@actions/exec/lib/exec";
|
||||
import { safeWhich } from "@chrisgavin/safe-which";
|
||||
import * as io from "@actions/io";
|
||||
import checkDiskSpace from "check-disk-space";
|
||||
import del from "del";
|
||||
import getFolderSize from "get-folder-size";
|
||||
|
|
@ -1194,7 +1194,7 @@ export async function isBinaryAccessible(
|
|||
logger: Logger,
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
await safeWhich(binary);
|
||||
await io.which(binary, true);
|
||||
logger.debug(`Found ${binary}.`);
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue