| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -euo pipefail |
| 4 | |
| 5 | artifact_dir="${1:-bazel-testlogs-artifact}" |
| 6 | |
| 7 | testlogs_dir="$(bazel info bazel-testlogs 2>/dev/null || true)" |
| 8 | if [ -z "${testlogs_dir}" ] || [ ! -d "${testlogs_dir}" ]; then |
| 9 | echo "No Bazel testlogs directory found." |
| 10 | exit 0 |
| 11 | fi |
| 12 | |
| 13 | rm -rf "${artifact_dir}" |
| 14 | mkdir -p "${artifact_dir}" |
| 15 | |
| 16 | while IFS= read -r -d '' file; do |
| 17 | relative_path="${file#"${testlogs_dir}/"}" |
| 18 | destination="${artifact_dir}/${relative_path}" |
| 19 | mkdir -p "$(dirname "${destination}")" |
| 20 | cp "${file}" "${destination}" |
| 21 | done < <( |
| 22 | find "${testlogs_dir}" \ |
| 23 | \( -name test.log -o -name test.xml -o -name outputs.zip -o -name test.outputs_manifest \) \ |
| 24 | -type f -print0 |
| 25 | ) |
| 26 | |
| 27 | echo "Collected Bazel test logs into ${artifact_dir}" |