fix(dev-infra): publish script python check not working on windows (#41943)

We recently added a sanity check that ensures that `python` is
available for Bazel. The check relies on `/usr/bin/python` to check
if python is available w/ the correct version. The problem is
that on Windows there is no guarantee that the `/usr/bin` folder
exists, so the `ng-dev release publish` command always fails.

We fix this by just accessing the `env` binary that is also consulted
by scripts executed within Bazel actions. The `env` binary can be
assumed exist in the shell's `$PATH` and can point us to Python
as if it would be executed within Bazel.

PR Close #41943
This commit is contained in:
Paul Gschwendtner 2021-05-04 16:02:54 +02:00 committed by Misko Hevery
parent 21c2a06811
commit 530e45f093
2 changed files with 10 additions and 10 deletions

View File

@ -6772,16 +6772,16 @@ class ReleaseTool {
});
}
/**
* Verifies the current environment contains /usr/bin/python which points to the Python3
* interpreter. python is required by our tooling in bazel as it contains scripts setting
* `#! /usr/bin/env python`.
*
* Verifies that Python can be resolved within scripts and points to a compatible version. Python
* is required in Bazel actions as there can be tools (such as `skydoc`) that rely on it.
* @returns a boolean indicating success or failure.
*/
_verifyEnvironmentHasPython3Symlink() {
return tslib.__awaiter(this, void 0, void 0, function* () {
try {
const pyVersion = yield spawnWithDebugOutput('/usr/bin/python', ['--version'], { mode: 'silent' });
// Note: We do not rely on `/usr/bin/env` but rather access the `env` binary directly as it
// should be part of the shell's `$PATH`. This is necessary for compatibility with Windows.
const pyVersion = yield spawnWithDebugOutput('env', ['python', '--version'], { mode: 'silent' });
const version = pyVersion.stdout.trim() || pyVersion.stderr.trim();
if (version.startsWith('Python 3.')) {
debug(`Local python version: ${version}`);

View File

@ -130,16 +130,16 @@ export class ReleaseTool {
}
/**
* Verifies the current environment contains /usr/bin/python which points to the Python3
* interpreter. python is required by our tooling in bazel as it contains scripts setting
* `#! /usr/bin/env python`.
*
* Verifies that Python can be resolved within scripts and points to a compatible version. Python
* is required in Bazel actions as there can be tools (such as `skydoc`) that rely on it.
* @returns a boolean indicating success or failure.
*/
private async _verifyEnvironmentHasPython3Symlink(): Promise<boolean> {
try {
// Note: We do not rely on `/usr/bin/env` but rather access the `env` binary directly as it
// should be part of the shell's `$PATH`. This is necessary for compatibility with Windows.
const pyVersion =
await spawnWithDebugOutput('/usr/bin/python', ['--version'], {mode: 'silent'});
await spawnWithDebugOutput('env', ['python', '--version'], {mode: 'silent'});
const version = pyVersion.stdout.trim() || pyVersion.stderr.trim();
if (version.startsWith('Python 3.')) {
debug(`Local python version: ${version}`);