All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: Daniel Kiper <dkiper@net-space.pl>, grub-devel@gnu.org
Cc: Glenn Washburn <development@efficientek.com>
Subject: [LOCAL-CI v2 3/3] scripts: Add local-tester.sh script to run local CI tests
Date: Tue,  4 Jan 2022 12:00:46 -0600	[thread overview]
Message-ID: <3284161835f15c7444bb298d8b85932f1475ce4a.1641317423.git.development@efficientek.com> (raw)
In-Reply-To: <cover.1641317423.git.development@efficientek.com>

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 scripts/ci/functions.local.sh | 37 +++++++++++++++++++++++++++++++++
 scripts/local-tester.sh       | 39 +++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100644 scripts/ci/functions.local.sh
 create mode 100755 scripts/local-tester.sh

diff --git a/scripts/ci/functions.local.sh b/scripts/ci/functions.local.sh
new file mode 100644
index 000000000..7a6766c07
--- /dev/null
+++ b/scripts/ci/functions.local.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+TXT_RED="\e[31m"
+TXT_YELLOW="\e[33m"
+TXT_CLEAR="\e[0m"
+TXT_LOG_COLOR="\e[97;100m"
+
+function start_log() {
+  local LOG_COLLAPSE LOG_NAME
+  while [ "$#" -gt 0 ]; do
+    case "$1" in
+      -c) LOG_COLLAPSE=1; shift;;
+      -n) LOG_NAME="$2"; shift;;
+      *) [ "$#" -eq 1 ] && LOG_MSG="$1"; shift;;
+    esac
+  done
+
+  echo -e "=========="
+  echo -e "========== ${TXT_YELLOW}Start Section ${LOG_NAME}: ${LOG_MSG}${TXT_CLEAR}"
+  echo -e "=========="
+  echo -e "${LOG_NAME} STARTTIME=`date +%s`" >&2
+}
+
+function end_log() {
+  local LOG_NAME
+  while [ "$#" -gt 0 ]; do
+    case "$1" in
+      -n) LOG_NAME=$2; shift;;
+      *) shift;;
+    esac
+  done
+
+  echo -e "${LOG_NAME} ENDTIME=`date +%s`" >&2
+  echo -e "========== End Section ${LOG_NAME} =========="
+}
+
+:;
diff --git a/scripts/local-tester.sh b/scripts/local-tester.sh
new file mode 100755
index 000000000..9cc7b8f43
--- /dev/null
+++ b/scripts/local-tester.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+set -e
+
+SDIR=$(realpath -e "${SDIR:-"${0%/*}"}")
+ROOT=$(realpath -m "${ROOT:-"./grub-tests"}")
+
+mkdir -p "$ROOT"
+cd "$ROOT"
+
+# Log stdout+stderr to file while keeping stdout going to original stdout
+exec 2>"$ROOT/$(basename "$0" .sh).$(date '+%Y%m%d%H%M%S').log" > >(exec 3>&1; exec tee >(exec cat >&3) >&2)
+PTTY=$!
+
+if [ "x$SHELL_TRACE" = "xy" ]; then
+  set -x
+  export >&2
+fi
+
+export CI_TYPE=local
+if [ -d "${SDIR}/ci" ]; then
+  export SCRIPTS_DIR=${SCRIPTS_DIR:-"${SDIR}"}
+  export CI_SCRIPTS_DIR=${CI_SCRIPTS_DIR:-"${SCRIPTS_DIR}/ci"}
+fi
+
+# If found, source helper functions
+[ -f "${CI_SCRIPTS_DIR}/functions.sh" ] &&
+. "${CI_SCRIPTS_DIR}/functions.sh"
+
+
+onexit() {
+  set +x
+  # Must close our end of the pipe to tee, else it will not exit and
+  # we'll wait forever on it to exit.
+  exec >&-
+  wait_anypid $PTTY
+}
+trap onexit exit
+
+main "$@"
-- 
2.27.0



      parent reply	other threads:[~2022-01-04 18:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 18:00 [LOCAL-CI v2 0/3] Add support for local automated testing Glenn Washburn
2022-01-04 18:00 ` [LOCAL-CI v2 1/3] scripts: Add general scripts to aid " Glenn Washburn
2022-01-04 18:00 ` [LOCAL-CI v2 2/3] scripts: Add functions for CI stages and default variables to functions.sh Glenn Washburn
2022-01-04 18:00 ` Glenn Washburn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3284161835f15c7444bb298d8b85932f1475ce4a.1641317423.git.development@efficientek.com \
    --to=development@efficientek.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.