Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Stop destroying test output with automatic logging (#569)

sarayourfriendd2bc44cdad36
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index 9caecf327..ab7e44ab3 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -72,12 +72,15 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
+
- name: Setup just
uses: extractions/setup-just@v1
+
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
+
- name: Cache Python dependencies
uses: actions/cache@v2
with:
@@ -85,6 +88,7 @@ jobs:
key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pip-
+
- name: Install Python deps for ingestion-server
run: |
pip install -U pip
@@ -102,6 +106,17 @@ jobs:
- name: Run ingestion-server tests
run: just ing-testlocal
+ - name: Upload ingestion test logs
+ if: ${{ always() }}
+ uses: actions/upload-artifact@v2
+ with:
+ name: ing_logs
+ path: ingestion_server/test/ingestion_logs.txt
+
+ - name: Print ingestion test logs
+ if: ${{ always() }}
+ run: cat ingestion_server/test/ingestion_logs.txt
+
test-api:
name: Run tests for the API
runs-on: ubuntu-latest
@@ -126,11 +141,26 @@ jobs:
- name: Start API, ingest and index test data
run: just init
+
- name: Run API tests
run: just api-test -T
+ - name: Print API test logs
+ if: ${{ always() }}
+ run: |
+ just logs > api_logs
+ cat api_logs
+
+ - name: Upload API test logs
+ if: ${{ always() }}
+ uses: actions/upload-artifact@v2
+ with:
+ name: api_logs
+ path: api_logs
+
- name: Make developer docs
run: just sphinx-make -T
+
- name: Upload developer docs
uses: actions/upload-artifact@v2
with:
diff --git a/api/test/run_test.sh b/api/test/run_test.sh
index 706beeb86..e4fcb2bbe 100755
--- a/api/test/run_test.sh
+++ b/api/test/run_test.sh
@@ -16,10 +16,9 @@ pytest -s --disable-pytest-warnings $TEST_ARG
succeeded=$?
if [[ $succeeded -eq 0 ]]; then
- printf "${green}:-) All tests passed${endcol}\n"
+ printf "${green}:-) All tests passed${endcol}\n"
else
- printf "Full system logs:\n"
- docker-compose logs
- printf "${red}:'( Some tests did not pass${endcol}\n"
+ printf "\n\n${red}:'( Some tests did not pass${endcol}\n"
+ printf "Hint: \`just logs [service]\` will print the Docker logs and may be helpful for debugging.\n\n"
fi
exit $succeeded
diff --git a/ingestion_server/test/run_test.sh b/ingestion_server/test/run_test.sh
index 66a926e73..7a5da9494 100755
--- a/ingestion_server/test/run_test.sh
+++ b/ingestion_server/test/run_test.sh
@@ -18,8 +18,6 @@ succeeded=$?
if [[ $succeeded -eq 0 ]]; then
printf "${green}:-) All tests passed${endcol}\n"
else
- printf "Full system logs:\n"
- cat test/ingestion_logs.txt
printf "${red}:'( Some tests did not pass${endcol}\n"
fi
exit $succeeded
diff --git a/justfile b/justfile
index eafbdbd66..fc1f584d7 100644
--- a/justfile
+++ b/justfile
@@ -1,5 +1,7 @@
set dotenv-load := false
+IS_CI := env_var_or_default("CI", "")
+
# Show all available recipes
default:
@just --list --unsorted
@@ -48,7 +50,7 @@ recreate:
@just up "--force-recreate --build"
# Show logs of all, or named, Docker services
-logs services="" args="-f":
+logs services="" args=(if IS_CI != "" { "" } else { "-f" }):
docker-compose {{ DOCKER_FILE }} logs {{ args }} {{ services }}