Repository: etcd-io/etcd
File: scripts/test_lib.sh (Shell)

Code before:
#  (unless the set is limited using ${PKG} or / ${USERMOD})
function run_for_modules {
  KEEP_GOING_MODULE=${KEEP_GOING_MODULE:-false}
  local pkg="${PKG:-./...}"
  local fail_mod=false
  if [ -z "${USERMOD:-}" ]; then
    for m in $(module_dirs); do
      if run_for_module "${m}" "$@" "${pkg}"; then
        continue
      else
        if [ "$KEEP_GOING_MODULE" = false ]; then
          log_error "There was a Failure in module ${m}, aborting..."
          return 1
        fi
        log_error "There was a Failure in module ${m}, keep going..."
        fail_mod=true
      fi
    done
    if [ "$fail_mod" = true ]; then
      return 1
    fi
  else
    run_for_module "${USERMOD}" "$@" "${pkg}" || return "$?"
  fi
}

junitFilenamePrefix() {
  if [[ -z "${JUNIT_REPORT_DIR:-}" ]]; then
    echo ""
    return
  fi
  mkdir -p "${JUNIT_REPORT_DIR}"
  DATE=$( date +%s | base64 | head -c 15 )
  echo "${JUNIT_REPORT_DIR}/junit_$DATE"
}

function produce_junit_xmlreport {
  local -r junit_filename_prefix=${1:-}
  if [[ -z "${junit_filename_prefix}" ]]; then
    return
  fi

  local junit_xml_filename
  junit_xml_filename="${junit_filename_prefix}.xml"

  # Ensure that gotestsum is run without cross-compiling
  run_go_tool gotest.tools/gotestsum --junitfile "${junit_xml_filename}" --raw-command cat "${junit_filename_prefix}"*.stdout || exit 1
  if [ "${VERBOSE:-}" != "1" ]; then
    rm "${junit_filename_prefix}"*.stdout
  fi


Review comment (suggestion):
It's very similar to `run_for_modules`, are you going to remove it or consolidate them eventually? 

https://github.com/etcd-io/etcd/blob/547ea9a3ab13356d5e535d1ac671be88d8287d51/scripts/test_lib.sh#L148-L172

Code after:
# (unless the set is limited using ${PKG} or / ${USERMOD})
function run_for_workspace_modules {
  local keep_going_module=${KEEP_GOING_MODULE:-false}
  local fail_mod=false
  local pkg="${PKG:-./...}"

  if [ -z "${USERMOD:-}" ]; then
    local _modules=()
    load_workspace_relative_modules _modules
    for module in "${_modules[@]}"; do
      if ! run_for_module "${module%...}" "$@"; then
        if [ "$keep_going_module" = false ]; then
          log_error "There was a Failure in module ${module}, aborting..."
          return 1
        fi
        log_error "There was a Failure in module ${module}, keep going..."
        fail_mod=true
      fi
    done
    if [ "$fail_mod" = true ]; then
      return 1
    fi
  else
    run_for_module "${USERMOD}" "$@" "${pkg}" || return "$?"
  fi
}

#  run_for_modules [cmd]
#  run given command across all modules and packages
#  (unless the set is limited using ${PKG} or / ${USERMOD})
function run_for_modules {
  KEEP_GOING_MODULE=${KEEP_GOING_MODULE:-false}
  local pkg="${PKG:-./...}"
  local fail_mod=false
  if [ -z "${USERMOD:-}" ]; then
    for m in $(module_dirs); do
      if run_for_module "${m}" "$@" "${pkg}"; then
        continue
      else
        if [ "$KEEP_GOING_MODULE" = false ]; then
          log_error "There was a Failure in module ${m}, aborting..."
          return 1
        fi
        log_error "There was a Failure in module ${m}, keep going..."
        fail_mod=true
      fi
    done
    if [ "$fail_mod" = true ]; then
      return 1
    fi
  else