Skip to content

Commit aab145d

Browse files
schloerkejcheng5
andauthored
CI(debug): Print full stdout/stderr when command fails (#1660)
Co-authored-by: Joe Cheng <joe@posit.co>
1 parent 24013f4 commit aab145d

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

Makefile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,21 @@ clean-js: FORCE
149149
SUB_FILE:=
150150
PYTEST_BROWSERS:= --browser webkit --browser firefox --browser chromium
151151
PYTEST_DEPLOYS_BROWSERS:= --browser chromium
152+
153+
# Full test path to playwright tests
154+
TEST_FILE:=tests/playwright/$(SUB_FILE)
155+
# Default `make` values that shouldn't be directly used; (Use `TEST_FILE` instead!)
156+
DEPLOYS_TEST_FILE:=tests/playwright/deploys$(SUB_FILE)
157+
SHINY_TEST_FILE:=tests/playwright/shiny/$(SUB_FILE)
158+
EXAMPLES_TEST_FILE:=tests/playwright/examples/$(SUB_FILE)
159+
152160
install-playwright: FORCE
153161
playwright install --with-deps
154162

155163
install-rsconnect: FORCE
156164
pip install git+https://github.com/rstudio/rsconnect-python.git#egg=rsconnect-python
157165

158-
# Full test path to playwright tests
159-
TEST_FILE:="tests/playwright/$(SUB_FILE)"
166+
160167
# All end-to-end tests with playwright
161168
playwright: install-playwright ## All end-to-end tests with playwright; (TEST_FILE="" from root of repo)
162169
pytest $(TEST_FILE) $(PYTEST_BROWSERS)
@@ -169,20 +176,18 @@ playwright-show-trace: ## Show trace of failed tests
169176

170177
# end-to-end tests with playwright; (SUB_FILE="" within tests/playwright/shiny/)
171178
playwright-shiny: FORCE
172-
$(MAKE) playwright TEST_FILE="tests/playwright/shiny/$(SUB_FILE)"
179+
$(MAKE) playwright TEST_FILE="$(SHINY_TEST_FILE)"
173180

174181
# end-to-end tests on deployed apps with playwright; (SUB_FILE="" within tests/playwright/deploys/)
175182
playwright-deploys: FORCE
176-
$(MAKE) playwright PYTEST_BROWSERS="$(PYTEST_DEPLOYS_BROWSERS)" TEST_FILE="$(TEST_FILE)"
177-
playwright-deploys-legacy: FORCE
178-
$(MAKE) playwright TEST_FILE="tests/playwright/deploys/$(SUB_FILE)" PYTEST_BROWSERS="$(PYTEST_DEPLOYS_BROWSERS)"
183+
$(MAKE) playwright PYTEST_BROWSERS="$(PYTEST_DEPLOYS_BROWSERS)" TEST_FILE="$(DEPLOYS_TEST_FILE)"
179184

180185
# end-to-end tests on all py-shiny examples with playwright; (SUB_FILE="" within tests/playwright/examples/)
181186
playwright-examples: FORCE
182-
$(MAKE) playwright TEST_FILE="tests/playwright/examples/$(SUB_FILE)"
187+
$(MAKE) playwright TEST_FILE="$(EXAMPLES_TEST_FILE)"
183188

184189
coverage: FORCE ## check combined code coverage (must run e2e last)
185-
pytest --cov-report term-missing --cov=shiny tests/pytest/ tests/playwright/shiny/$(SUB_FILE) $(PYTEST_BROWSERS)
190+
pytest --cov-report term-missing --cov=shiny tests/pytest/ $(SHINY_TEST_FILE) $(PYTEST_BROWSERS)
186191
coverage html
187192
$(BROWSER) htmlcov/index.html
188193

tests/playwright/utils/deploy_utils.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
import re
56
import shutil
67
import subprocess
78
import sys
@@ -70,14 +71,33 @@ def skip_on_webkit(fn: CallableT) -> CallableT:
7071
def run_command(cmd: str) -> str:
7172
output = subprocess.run(
7273
cmd,
73-
check=True,
74+
check=False,
7475
capture_output=True,
7576
text=True,
7677
shell=True,
7778
)
79+
if output.returncode != 0:
80+
print(
81+
"Failed to run command!",
82+
"\nstdout:",
83+
output.stdout,
84+
"\nstderr:",
85+
output.stderr,
86+
file=sys.stderr,
87+
sep="\n",
88+
)
89+
raise RuntimeError(f"Failed to run command: {redact_api_key(cmd)}")
7890
return output.stdout
7991

8092

93+
def redact_api_key(cmd: str) -> str:
94+
# Redact the value of the `--api-key` CLI argument, replace it with `***`
95+
# Create a regex that replaces the argument following `--api-key`
96+
# with `***` (e.g. `--api-key my-api-key` -> `--api-key ***`)
97+
98+
return re.sub(r"(--api-key\s+)(\S+)", r"\1***", cmd)
99+
100+
81101
def deploy_to_connect(app_name: str, app_dir: str) -> str:
82102
if not api_key:
83103
raise RuntimeError("No api key found. Cannot deploy.")

0 commit comments

Comments
 (0)