Skip to content

Commit d8237d2

Browse files
ansdmichaelklishin
authored andcommitted
Add bazel run test-logs fallback for non-desktop session
My workflow is developing RabbitMQ on an Ubuntu server. Since it doesn't have a desktop or browser, let's fallback for `bazel run test-logs` command to start an HTTP server instead. From now on, I can run conveniently: ``` david@nuc:~/workspace/rabbitmq-server$ bazel run test-logs //deps/rabbitmq_auth_backend_oauth2:unit_SUITE --config=local INFO: Analyzed target //:test-logs (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //:test-logs up-to-date: bazel-bin/open-test-logs.sh INFO: Elapsed time: 0.047s, Critical Path: 0.00s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action INFO: Build completed successfully, 1 total action Archive: outputs.zip Couldn't find a suitable web browser! Set the BROWSER environment variable to your desired browser. Warning: program returned non-zero exit code #256 /usr/bin/open: 882: www-browser: not found /usr/bin/open: 882: links2: not found /usr/bin/open: 882: elinks: not found /usr/bin/open: 882: links: not found /usr/bin/open: 882: lynx: not found /usr/bin/open: 882: w3m: not found xdg-open: no method available for opening 'index.html' Open your browser at http://nuc:8000/index.html Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ... ``` and then open http://nuc:8000/index.html in my browser on MacOS. (cherry picked from commit 107b8a4)
1 parent 55a9f7a commit d8237d2

File tree

1 file changed

+44
-34
lines changed

1 file changed

+44
-34
lines changed

BUILD.bazel

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,33 @@ genrule(
9797
outs = ["open-test-logs.sh"],
9898
cmd = """set -euo pipefail
9999
cat << 'EOF' > $@
100-
set -euo pipefail
101-
if [ $$# -eq 0 ]; then
102-
echo "Usage: bazel run test-logs TEST_LABEL [shard_index]"
103-
exit 1
104-
fi
105-
106-
RELATIVE=$${1#//}
107-
PACKAGE=$${RELATIVE%%:*}
108-
SUITE=$${RELATIVE##*:}
109-
OUTPUT_DIR=test.outputs
110-
if [ $$# -gt 1 ]; then
111-
OUTPUT_DIR=shard_$$2_of_*/test.outputs
112-
fi
113-
cd bazel-testlogs/$$PACKAGE/$$SUITE/$$OUTPUT_DIR
114-
if [ -f outputs.zip ]; then
115-
unzip -u outputs.zip
116-
fi
117-
open index.html
100+
#!/bin/bash
101+
set -euo pipefail
102+
if [ $$# -eq 0 ]; then
103+
echo "Usage: bazel run test-logs TEST_LABEL [shard_index]"
104+
exit 1
105+
fi
106+
107+
RELATIVE=$${1#//}
108+
PACKAGE=$${RELATIVE%%:*}
109+
SUITE=$${RELATIVE##*:}
110+
OUTPUT_DIR=test.outputs
111+
if [ $$# -gt 1 ]; then
112+
OUTPUT_DIR=shard_$$2_of_*/test.outputs
113+
fi
114+
cd "bazel-testlogs/$$PACKAGE/$$SUITE/$$OUTPUT_DIR"
115+
if [ -f outputs.zip ]; then
116+
unzip -u outputs.zip
117+
fi
118+
set +e
119+
open index.html
120+
rc=$$?
121+
set -e
122+
if [[ $$rc -eq 3 ]]; then
123+
# For xdg-open exit code 3 means "A required tool could not be found." That is, there is no browser.
124+
echo "Open your browser at http://$$(hostname -s):8000/index.html"
125+
python -m http.server 8000
126+
fi
118127
EOF
119128
""",
120129
executable = True,
@@ -125,22 +134,23 @@ genrule(
125134
outs = ["open-remote-test-logs.sh"],
126135
cmd = """set -euo pipefail
127136
cat << 'EOF' > $@
128-
set -euo pipefail
129-
if [ $$# -eq 0 ]; then
130-
echo "Usage: bazel run remote-test-logs TEST_LABEL [shard_index]"
131-
exit 1
132-
fi
133-
134-
RELATIVE=$${1#//}
135-
PACKAGE=$${RELATIVE%%:*}
136-
SUITE=$${RELATIVE##*:}
137-
OUTPUT_DIR=test.outputs
138-
if [ $$# -gt 1 ]; then
139-
OUTPUT_DIR=shard_$$2_of_*/test.outputs
140-
fi
141-
TESTLOGS=$$(echo $$(bazel info output_path)/k8-*/testlogs)
142-
cd $$TESTLOGS/$$PACKAGE/$$SUITE/$$OUTPUT_DIR && unzip -u outputs.zip
143-
open index.html
137+
#!/bin/bash
138+
set -euo pipefail
139+
if [ $$# -eq 0 ]; then
140+
echo "Usage: bazel run remote-test-logs TEST_LABEL [shard_index]"
141+
exit 1
142+
fi
143+
144+
RELATIVE=$${1#//}
145+
PACKAGE=$${RELATIVE%%:*}
146+
SUITE=$${RELATIVE##*:}
147+
OUTPUT_DIR=test.outputs
148+
if [ $$# -gt 1 ]; then
149+
OUTPUT_DIR=shard_$$2_of_*/test.outputs
150+
fi
151+
TESTLOGS=$$(echo $$(bazel info output_path)/k8-*/testlogs)
152+
cd "$$TESTLOGS/$$PACKAGE/$$SUITE/$$OUTPUT_DIR" && unzip -u outputs.zip
153+
open index.html
144154
EOF
145155
""",
146156
executable = True,

0 commit comments

Comments
 (0)