From 8f8a6897224e341d20c6148675fe199e721af855 Mon Sep 17 00:00:00 2001 From: JAYADITYA <96861162+JayadityaGit@users.noreply.github.com> Date: Thu, 23 Oct 2025 04:28:04 +0530 Subject: [PATCH] feat(preflight): Use venv for yamllint installation (#11694) --- scripts/lint.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/lint.js b/scripts/lint.js index a9613dfac9..eec8aeeb29 100644 --- a/scripts/lint.js +++ b/scripts/lint.js @@ -49,6 +49,13 @@ function getPlatformArch() { const platformArch = getPlatformArch(); +const PYTHON_VENV_PATH = join(TEMP_DIR, 'python_venv'); + +const yamllintCheck = + process.platform === 'win32' + ? `if exist "${PYTHON_VENV_PATH}\\Scripts\\yamllint.exe" (exit 0) else (exit 1)` + : `test -x "${PYTHON_VENV_PATH}/bin/yamllint"`; + /** * @typedef {{ * check: string; @@ -97,8 +104,11 @@ const LINTERS = { `, }, yamllint: { - check: 'command -v yamllint', - installer: `pip3 install --user "yamllint==${YAMLLINT_VERSION}"`, + check: yamllintCheck, + installer: ` + python3 -m venv "${PYTHON_VENV_PATH}" && \ + "${PYTHON_VENV_PATH}/bin/pip" install "yamllint==${YAMLLINT_VERSION}" + `, run: "git ls-files | grep -E '\\.(yaml|yml)' | xargs yamllint --format github", }, }; @@ -107,12 +117,7 @@ function runCommand(command, stdio = 'inherit') { try { const env = { ...process.env }; const nodeBin = join(process.cwd(), 'node_modules', '.bin'); - env.PATH = `${nodeBin}:${TEMP_DIR}/actionlint:${TEMP_DIR}/shellcheck:${env.PATH}`; - if (process.platform === 'darwin') { - env.PATH = `${env.PATH}:${process.env.HOME}/Library/Python/3.12/bin`; - } else if (process.platform === 'linux') { - env.PATH = `${env.PATH}:${process.env.HOME}/.local/bin`; - } + env.PATH = `${nodeBin}:${TEMP_DIR}/actionlint:${TEMP_DIR}/shellcheck:${PYTHON_VENV_PATH}/bin:${env.PATH}`; execSync(command, { stdio, env }); return true; } catch (_e) {