fix: actions fails silently if runner bin doesn't exist (#1175)

This commit is contained in:
Fabian-Lars
2025-11-13 23:09:44 +01:00
committed by GitHub
parent c905d99edb
commit eea189090a
6 changed files with 77 additions and 14 deletions

View File

@@ -0,0 +1,5 @@
---
action: patch
---
Improved runner detection to prevent silent fails if runner (npm, pnpm, yarn, bun) was not installed while a lockfile was present.

View File

@@ -7,5 +7,8 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"@tauri-apps/cli": "^2.9.4"
}
}

View File

@@ -42,9 +42,9 @@ jobs:
- name: install example dependencies
run: |
echo "skipped"
# Testing cli fallback install
# cd ../example-with-tauri-v2
# pnpm install
# disabled to test cli fallback install
#cd ./.github/fixtures/example-with-tauri-v2
# pnpm install
# rust
- name: install Rust stable

4
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -4,6 +4,7 @@ import {
hasTauriScript,
retry,
usesBun,
usesNpm,
usesPnpm,
usesYarn,
} from './utils';
@@ -46,20 +47,27 @@ async function getRunner(
tauriScript: string | null,
): Promise<Runner> {
if (tauriScript) {
console.log('`tauriScript` set. Skipping cli verification.');
// FIXME: This will also split file paths with spaces.
const [runnerCommand, ...runnerArgs] = tauriScript.split(' ');
return new Runner(runnerCommand, runnerArgs);
}
if (hasDependency('@tauri-apps/cli', root)) {
// usesX also check if the runner executable exists.
if (usesYarn(root)) return new Runner('yarn', ['tauri']);
if (usesPnpm(root)) return new Runner('pnpm', ['tauri']);
if (usesBun(root)) return new Runner('bun', ['tauri']);
return new Runner('npm', [hasTauriScript(root) ? 'run' : 'exec', 'tauri']);
// npm should always be available in a GitHub runner but we'll check for it anyway.
if (usesNpm(root))
return new Runner('npm', [
hasTauriScript(root) ? 'run' : 'exec',
'tauri',
]);
}
console.warn(
'Could not detect `@tauri-apps/cli` installation. Proceeding to install global npm package...',
'Could not detect valid `@tauri-apps/cli` installation. Proceeding to install global npm package...',
);
await execCommand('npm', ['install', '-g', `@tauri-apps/cli@v2`], {

View File

@@ -9,7 +9,7 @@ import path, {
} from 'node:path';
import TOML from 'smol-toml';
import { execa } from 'execa';
import { execa, execaSync } from 'execa';
import { globbySync } from 'globby';
import { TauriConfig } from './config';
@@ -355,18 +355,65 @@ export function hasTauriScript(root: string): boolean {
);
}
export function usesNpm(root: string): boolean {
if (existsSync(join(root, 'package-lock.json'))) {
if (isRunnerInstalled('npm')) {
return true;
} else {
console.warn(
"package-lock.json detected but couldn't find `npm` executable.",
);
}
}
return false;
}
export function usesYarn(root: string): boolean {
return existsSync(join(root, 'yarn.lock'));
if (existsSync(join(root, 'yarn.lock'))) {
if (isRunnerInstalled('yarn')) {
return true;
} else {
console.warn("yarn.lock detected but couldn't find `yarn` executable.");
}
}
return false;
}
export function usesPnpm(root: string): boolean {
return existsSync(join(root, 'pnpm-lock.yaml'));
if (existsSync(join(root, 'pnpm-lock.yaml'))) {
if (isRunnerInstalled('pnpm')) {
return true;
} else {
console.warn(
"pnpm-lock.yaml detected but couldn't find `pnpm` executable.",
);
}
}
return false;
}
export function usesBun(root: string): boolean {
return (
existsSync(join(root, 'bun.lockb')) || existsSync(join(root, 'bun.lock'))
);
if (
existsSync(join(root, 'bun.lockb')) ||
existsSync(join(root, 'bun.lock'))
) {
if (isRunnerInstalled('bun')) {
return true;
} else {
console.warn("bun.lock(b) detected but couldn't find `bun` executable.");
}
}
return false;
}
function isRunnerInstalled(runner: string) {
const bin = process.platform === 'win32' ? 'where.exe' : 'which';
try {
return execaSync(bin, [runner]).exitCode === 0;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (_e) {
return false;
}
}
export async function execCommand(