From 9ba5e3d2a8aeab8d1d868a1b6f8f1b2836cbfd0a Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Tue, 5 Mar 2024 12:15:20 -0300 Subject: [PATCH] gha: export start_time to collect artifacts properly The jobs running on garm will collect journal information. The data gathered is based on the time the tests started running. The $start_time is exported on run_tests() and used in collect_artifacts(). It happens that run_tests() and collect_artifacts() are called on different steps of the workflow and the environment variables aren't preserved between them, i.e, $start_time exported on the first step is not available on the subsequents. To solve that issue, let's save $start_time in the file pointed out by $GITHUB_ENV that Github actions uses to export variables. In case $GITHUB_ENV is empty then probably it is running locally outside of Github, so it won't save the start time value. Fixes #9217 Signed-off-by: Wainer dos Santos Moschetta --- tests/integration/kubernetes/gha-run.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/integration/kubernetes/gha-run.sh b/tests/integration/kubernetes/gha-run.sh index cf52312a8e..0278f9e0cd 100755 --- a/tests/integration/kubernetes/gha-run.sh +++ b/tests/integration/kubernetes/gha-run.sh @@ -209,7 +209,16 @@ function run_tests() { pushd "${kubernetes_dir}" bash setup.sh - export start_time=$(date '+%Y-%m-%d %H:%M:%S') + + # In case of running on Github workflow it needs to save the start time + # on the environment variables file so that the variable is exported on + # next workflow steps. + if [ -n "$GITHUB_ENV" ]; then + start_time=$(date '+%Y-%m-%d %H:%M:%S') + export start_time + echo "start_time=${start_time}" >> "$GITHUB_ENV" + fi + if [[ "${KATA_HYPERVISOR}" = "dragonball" ]] && [[ "${SNAPSHOTTER}" = "devmapper" ]] || [[ "${KATA_HYPERVISOR}" = "cloud-hypervisor" ]] && [[ "${SNAPSHOTTER}" = "devmapper" ]]; then # cloud-hypervisor runtime-rs issue is https://github.com/kata-containers/kata-containers/issues/9034 echo "Skipping tests for $KATA_HYPERVISOR using devmapper" @@ -220,6 +229,11 @@ function run_tests() { } function collect_artifacts() { + if [ -z "${start_time:-}" ]; then + warn "tests start time is not defined. Cannot gather journal information" + return + fi + local artifacts_dir="/tmp/artifacts" if [ -d "${artifacts_dir}" ]; then rm -rf "${artifacts_dir}"