ensure-tox: fix pipe race

The

 command -v pip pip3 | head -n1

introduced with Ie50928c9b782ea84db916bb1441567e1206ff466 has a very
subtle race; if "pip" and "pip3" exists and there are two lines
output, the "head -n1" will exit and depending on scheduling the
"command" might write to a broken pipe (this manifests as exit code
141).

Move this to a more explicit if statement.

Co-Authored-By: Jens Harbott <j.harbott@x-ion.de>
Change-Id: I80823a7bc6351925d6f0b20bdebca3eafef0b27d
This commit is contained in:
Ian Wienand 2020-01-22 07:32:10 +11:00
parent 5eb4c257f5
commit 9e5907f4cc

View File

@ -1,7 +1,13 @@
- name: Ensure tox is installed
shell: |
set -euo pipefail
PIP=$(command -v pip pip3 | head -n1)
if command -v pip; then
PIP=pip
elif command -v pip3; then
PIP=pip3
fi
type tox || $PIP install --user tox
args:
executable: /bin/bash