post-command 1.4 KB

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. # This script is executed by Buildkite on the host machine.
  3. # In contrast, our build jobs are run in Docker containers.
  4. # This means that even though our build jobs write to
  5. # `/artifact-mount`, the directory on the host machine is
  6. # actually `/tmp/artifacts`.
  7. # Here, we cat all text files in artifact-mount/test-summaries
  8. # and upload them as a Buildkite annotation.
  9. # These files contain a condensed summary of all failing pytest
  10. # tests to make it easy for users to see which tests are failing.
  11. # Because we upload them to Buildkite, we don't need to
  12. # upload them as artifacts and delete them afterwards.
  13. set -e
  14. if [ -d "/tmp/artifacts/test-summaries" ] && [ "$(ls -A /tmp/artifacts/test-summaries)" ]; then
  15. # Only upload annotations if there are at least 2 files in the directory:
  16. # 1 header and 1 failed test.
  17. if [ "$(find /tmp/artifacts/test-summaries -maxdepth 1 -name '*.txt' | wc -l)" -ge 2 ]; then
  18. cat /tmp/artifacts/test-summaries/*.txt | buildkite-agent annotate --job "${BUILDKITE_JOB_ID}" --append --style error --context "${BUILDKITE_JOB_ID}"
  19. fi
  20. # Remove test summaries files (don't actually upload as artifacts)
  21. # This has to be done with docker to avoid permission issues
  22. echo "--- Cleaning up"
  23. docker run --rm -v /tmp/artifacts:/artifact-mount alpine:latest /bin/sh -c 'rm -rf /artifact-mount/test-summaries' || true
  24. fi