gradle-build-cache-validation.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. set -euo pipefail
  3. VALIDATION_SCRIPTS_VERSION=2.5.1
  4. GRADLE_ENTERPRISE_ACCESS_KEY=$(vault kv get -field=value secret/ci/elastic-elasticsearch/gradle-enterprise-api-key)
  5. export GRADLE_ENTERPRISE_ACCESS_KEY
  6. curl -s -L -O https://github.com/gradle/gradle-enterprise-build-validation-scripts/releases/download/v$VALIDATION_SCRIPTS_VERSION/gradle-enterprise-gradle-build-validation-$VALIDATION_SCRIPTS_VERSION.zip && unzip -q -o gradle-enterprise-gradle-build-validation-$VALIDATION_SCRIPTS_VERSION.zip
  7. # Create a temporary file
  8. tmpOutputFile=$(mktemp)
  9. trap "rm $tmpOutputFile" EXIT
  10. set +e
  11. gradle-enterprise-gradle-build-validation/03-validate-local-build-caching-different-locations.sh -r https://github.com/elastic/elasticsearch.git -b $BUILDKITE_BRANCH --gradle-enterprise-server https://gradle-enterprise.elastic.co -t precommit --fail-if-not-fully-cacheable | tee $tmpOutputFile
  12. # Capture the return value
  13. retval=$?
  14. set -e
  15. # Now read the content from the temporary file into a variable
  16. perfOutput=$(cat $tmpOutputFile | sed -n '/Performance Characteristics/,/See https:\/\/gradle.com\/bvs\/main\/Gradle.md#performance-characteristics for details./p' | sed '$d' | sed 's/\x1b\[[0-9;]*m//g')
  17. investigationOutput=$(cat $tmpOutputFile | sed -n '/Investigation Quick Links/,$p' | sed 's/\x1b\[[0-9;]*m//g')
  18. # Initialize HTML output variable
  19. summaryHtml="<h4>Build Cache Performance Characteristics</h4>"
  20. summaryHtml+="<ul>"
  21. # Process each line of the string
  22. while IFS=: read -r label value; do
  23. if [[ -n "$label" && -n "$value" ]]; then
  24. # Trim whitespace from label and value
  25. trimmed_label=$(echo "$label" | xargs)
  26. trimmed_value=$(echo "$value" | xargs)
  27. # Append to HTML output variable
  28. summaryHtml+="<li><strong>$trimmed_label:</strong> $trimmed_value</li>"
  29. fi
  30. done <<< "$perfOutput"
  31. summaryHtml+="</ul>"
  32. # generate html for links
  33. summaryHtml+="<h4>Investigation Links</h4>"
  34. summaryHtml+="<ul>"
  35. # Process each line of the string
  36. while IFS= read -r line; do
  37. if [[ "$line" =~ http.* ]]; then
  38. # Extract URL and description using awk
  39. url=$(echo "$line" | awk '{print $NF}')
  40. description=$(echo "$line" | sed -e "s/:.*//")
  41. # Append to HTML output variable
  42. summaryHtml+=" <li><a href=\"$url\">$description</a></li>"
  43. fi
  44. done <<< "$investigationOutput"
  45. # End of the HTML content
  46. summaryHtml+="</ul>"
  47. cat << EOF | buildkite-agent annotate --context "ctx-validation-summary" --style "info"
  48. $summaryHtml
  49. EOF
  50. # Check if the command was successful
  51. if [ $retval -eq 0 ]; then
  52. echo "Experiment completed successfully"
  53. elif [ $retval -eq 1 ]; then
  54. echo "An invalid input was provided while attempting to run the experiment"
  55. elif [ $retval -eq 2 ]; then
  56. echo "One of the builds that is part of the experiment failed"
  57. elif [ $retval -eq 3 ]; then
  58. echo "The build was not fully cacheable for the given task graph"
  59. elif [ $retval -eq 3 ]; then
  60. echo "An unclassified, fatal error happened while running the experiment"
  61. fi
  62. exit $retval