graph_compare.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Compares build graphs for two given refs in the current directory git repo
  2. # Creates ya.make in the current directory listing affected ydb targets
  3. # Parameters: base_commit_sha head_commit_sha
  4. set -exo pipefail
  5. workdir=$(mktemp -d)
  6. echo Workdir: $workdir
  7. echo Checkout base commit...
  8. git checkout $1
  9. echo Build graph for base commit...
  10. ./ya make -Gj0 -ttt ydb --build release -k --cache-tests --build-all | jq '.graph[]' > $workdir/graph_base
  11. echo Checkout head commit...
  12. git checkout $2
  13. echo Build graph for head commit...
  14. ./ya make -Gj0 -ttt ydb --build release -k --cache-tests --build-all | jq '.graph[]' > $workdir/graph_head
  15. echo Generate lists of uids for base and head...
  16. cat $workdir/graph_base | jq '.uid' > $workdir/uid_base
  17. cat $workdir/graph_head | jq '.uid' > $workdir/uid_head
  18. echo Create a list of changed uids in the head graph...
  19. (cat $workdir/uid_head;(cat $workdir/uid_base;cat $workdir/uid_head) | sort | uniq -u) | sort | uniq -d > $workdir/uids_new
  20. echo Create ya.make
  21. echo "" > ya.make
  22. echo Generate list of test shard names from the head graph based on the list of uids...
  23. cat $workdir/graph_head | jq -r --slurpfile uids $workdir/uids_new 'select( ."node-type"=="test") | select( any( .uid; .==$uids[] )) | .kv.path' | sort | uniq > $workdir/testsuites
  24. echo Number of test suites:
  25. cat $workdir/testsuites | wc -l
  26. echo Removing test suite name from the list to get target names...
  27. sed -E 's/\/[^/]*$//g;/^null$/d' $workdir/testsuites > $workdir/ts2
  28. echo Append into ya.make RECURSE_FOR_TESTS to all required tests...
  29. cat $workdir/ts2 | (echo 'RECURSE_FOR_TESTS(';cat;echo ')') >> ya.make
  30. echo Generate list of module names from the head graph based on the list of uids...
  31. cat $workdir/graph_head | jq -r --slurpfile uids $workdir/uids_new 'select( ."target_properties"."module_type" != null) | select( ( ."target_properties"."module_tag" // "-" | strings | contains("proto") ) | not ) | select( any( .uid; .==$uids[] )) | .target_properties.module_dir' | sort | uniq > $workdir/modules
  32. echo Number of modules:
  33. cat $workdir/modules | wc -l
  34. echo Filter only modules in ydb
  35. cat $workdir/modules | { grep "^ydb" || true; } > $workdir/modules2
  36. echo Number of modules:
  37. cat $workdir/modules2 | wc -l
  38. echo Append into ya.make RECURSE to all required modules...
  39. cat $workdir/modules2 | (echo 'RECURSE(';cat;echo ')') >> ya.make
  40. echo "ya.make content:"
  41. cat ya.make