From 9449a0e0eda7aa49f13dc0eb181fb28dc8e63939 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 16 Nov 2023 15:55:41 +0000 Subject: [PATCH] DEV: Silence successful database migration output in github actions (#24416) The output of db:migrate for a new database is 20k+ lines. We only need the output when an error occurs. --- .github/workflows/tests.yml | 6 +++--- script/silence_successful_output | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100755 script/silence_successful_output diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ccb1f270c72..e5c3b6b9058 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -141,7 +141,7 @@ jobs: - name: Restore database from cache if: steps.app-cache.outputs.cache-hit == 'true' - run: psql --quiet -o /dev/null -f tmp/app-cache/cache.sql postgres + run: script/silence_successful_output psql --quiet -o /dev/null -f tmp/app-cache/cache.sql postgres - name: Restore uploads from cache if: steps.app-cache.outputs.cache-hit == 'true' @@ -151,7 +151,7 @@ jobs: if: steps.app-cache.outputs.cache-hit != 'true' run: | bin/rake db:create - bin/rake db:migrate + script/silence_successful_output bin/rake db:migrate - name: Create and migrate parallel databases if: >- @@ -159,7 +159,7 @@ jobs: steps.app-cache.outputs.cache-hit != 'true' run: | bin/rake parallel:create - bin/rake parallel:migrate + script/silence_successful_output bin/rake parallel:migrate - name: Dump database for cache if: steps.app-cache.outputs.cache-hit != 'true' diff --git a/script/silence_successful_output b/script/silence_successful_output new file mode 100755 index 00000000000..11082e3b18b --- /dev/null +++ b/script/silence_successful_output @@ -0,0 +1,21 @@ +#!/bin/bash + +# Run a command and write stdout/stderr to a temporary file. Print the output only if the command exits with a non-zero exit status + +tmp=$(mktemp) + +echo "[silence_successful_output] Running '$@' with output silenced..." >&2 + +("$@") 2>&1 &> "$tmp" +STATUS=$? + +if (( $STATUS )) ; then + echo "[silence_successful_output] '$@' failed! Output:" >&2 + cat "$tmp" >&2 +else + echo "[silence_successful_output] '$@' succeeded!" +fi + +rm "$tmp" + +exit $STATUS