github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/.buildkite/hooks/post-command (about)

     1  # Upload all relevant test failures.
     2  make -s testlogs 2>/dev/null | grep // | sort | uniq | (
     3    declare log_count=0
     4    while read target log; do
     5      if test -z "${target}"; then
     6        continue
     7      fi
     8  
     9      # N.B. If *all* tests fail due to some common cause, then we will
    10      # end up spending way too much time uploading logs. Instead, we just
    11      # upload the first 10 and stop. That is hopefully enough to debug.
    12      #
    13      # We include this test in the metadata, but note that we cannot
    14      # upload the actual test logs. The user should rerun locally.
    15      log_count=$((${log_count}+1))
    16      if test "${log_count}" -ge 10; then
    17        echo " * ${target} (no upload)" | \
    18          buildkite-agent annotate --style error --context failures --append
    19      else
    20        buildkite-agent artifact upload "${log}"
    21        echo " * [${target}](artifact://${log#/}) (${BUILDKITE_LABEL})" | \
    22          buildkite-agent annotate --style error --context failures --append
    23      fi
    24    done
    25  )
    26  
    27  # Upload all profiles, and include in an annotation.
    28  declare profile_output=$(mktemp --tmpdir)
    29  for file in $(find /tmp/profile -name \*.pprof -print 2>/dev/null | sort); do
    30    # Generate a link to the profile parsing function in gvisor.dev, which
    31    # implicitly uses a prefix of https://storage.googleapis.com. Note that
    32    # this relies on the specific BuildKite bucket location, and will break if
    33    # this changes (although the artifacts will still exist and be just fine).
    34    profile_name="${file#/tmp/profile/}"
    35    profile_url="https://gvisor.dev/profile/gvisor-buildkite/${BUILDKITE_BUILD_ID}/${BUILDKITE_JOB_ID}/${file#/}/"
    36    buildkite-agent artifact upload "${file}"
    37    echo "<li><a href='${profile_url}'>${profile_name}</a></li>" >> "${profile_output}"
    38  done
    39  
    40  # Upload if we had outputs.
    41  if test -s "${profile_output}"; then
    42    # Make the list a collapsible section in markdown.
    43    sed -i "1s|^|<details><summary>${BUILDKITE_LABEL}</summary><ul>\n|" "${profile_output}"
    44    echo "</ul></details>" >> "${profile_output}"
    45    cat "${profile_output}" | buildkite-agent annotate --style info --context profiles --append
    46  fi
    47  rm -rf "${profile_output}"
    48  
    49  # Clean the bazel cache, if there's failure.
    50  if test "${BUILDKITE_COMMAND_EXIT_STATUS}" -ne "0"; then
    51    # Attempt to clear the cache and shut down.
    52    make clean || echo "make clean failed with code $?"
    53    make bazel-shutdown || echo "make bazel-shutdown failed with code $?"
    54    # Attempt to clear any Go cache.
    55    sudo rm -rf "${HOME}/.cache/go-build"
    56    sudo rm -rf "${HOME}/go"
    57  fi
    58  
    59  # Kill any running containers (clear state).
    60  CONTAINERS="$(docker ps -q)"
    61  if ! test -z "${CONTAINERS}"; then
    62    docker container kill ${CONTAINERS} 2>/dev/null || true
    63  fi