fix(ci): make ci green (#1409)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { existsSync, statSync } from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { getShellEnv } from "./shellEnv.js";
|
||||
import { buildShellLaunchers } from "./shellLaunchers.js";
|
||||
@@ -76,11 +77,13 @@ export async function shell(args: ShellArgs): Promise<ShellResult> {
|
||||
}
|
||||
|
||||
const timeout = timeout_ms ?? DEFAULT_TIMEOUT;
|
||||
const cwd = workdir
|
||||
const defaultCwd = process.env.USER_CWD || process.cwd();
|
||||
const requestedCwd = workdir
|
||||
? path.isAbsolute(workdir)
|
||||
? workdir
|
||||
: path.resolve(process.env.USER_CWD || process.cwd(), workdir)
|
||||
: process.env.USER_CWD || process.cwd();
|
||||
: path.resolve(defaultCwd, workdir)
|
||||
: defaultCwd;
|
||||
const cwd = isUsableDirectory(requestedCwd) ? requestedCwd : defaultCwd;
|
||||
|
||||
const context: SpawnContext = {
|
||||
command,
|
||||
@@ -115,10 +118,9 @@ export async function shell(args: ShellArgs): Promise<ShellResult> {
|
||||
|
||||
function buildFallbackCommands(command: string[]): string[][] {
|
||||
if (!command.length) return [];
|
||||
const first = command[0];
|
||||
if (!first) return [];
|
||||
if (!isShellExecutableName(first)) return [];
|
||||
const script = extractShellScript(command);
|
||||
const shellIndex = findShellExecutableIndex(command);
|
||||
if (shellIndex === null) return [];
|
||||
const script = extractShellScript(command, shellIndex);
|
||||
if (!script) return [];
|
||||
const launchers = buildShellLaunchers(script);
|
||||
return launchers.filter((launcher) => !arraysEqual(launcher, command));
|
||||
@@ -132,6 +134,14 @@ function arraysEqual(a: string[], b: string[]): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function isUsableDirectory(candidate: string): boolean {
|
||||
try {
|
||||
return existsSync(candidate) && statSync(candidate).isDirectory();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isShellExecutableName(name: string): boolean {
|
||||
const normalized = name.replace(/\\/g, "/").toLowerCase();
|
||||
if (/(^|\/)(ba|z|a|da)?sh$/.test(normalized)) {
|
||||
@@ -149,8 +159,33 @@ function isShellExecutableName(name: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
function extractShellScript(command: string[]): string | null {
|
||||
function isEnvExecutableName(name: string): boolean {
|
||||
const normalized = name.replace(/\\/g, "/").toLowerCase();
|
||||
return normalized === "env" || normalized.endsWith("/env");
|
||||
}
|
||||
|
||||
function findShellExecutableIndex(command: string[]): number | null {
|
||||
const first = command[0];
|
||||
if (!first) return null;
|
||||
if (isShellExecutableName(first)) return 0;
|
||||
if (!isEnvExecutableName(first)) return null;
|
||||
|
||||
for (let i = 1; i < command.length; i += 1) {
|
||||
const token = command[i];
|
||||
if (!token) continue;
|
||||
if (token.startsWith("-")) continue;
|
||||
if (/^[A-Za-z_][A-Za-z0-9_]*=.*/.test(token)) continue;
|
||||
return isShellExecutableName(token) ? i : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractShellScript(
|
||||
command: string[],
|
||||
shellIndex: number,
|
||||
): string | null {
|
||||
for (let i = shellIndex + 1; i < command.length; i += 1) {
|
||||
const token = command[i];
|
||||
if (!token) continue;
|
||||
const normalized = token.toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user