feat(preflight): Use venv for yamllint installation (#11694)

This commit is contained in:
JAYADITYA
2025-10-23 04:28:04 +05:30
committed by GitHub
parent a90b9fe977
commit 8f8a689722

View File

@@ -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) {