Newer
Older
dub_jkp / scripts / ci / summary_comment_diff.sh
@WebFreak001 WebFreak001 on 9 Mar 2023 2 KB add pr_info GitHub actions run
  1. #!/usr/bin/env bash
  2.  
  3. set -u
  4.  
  5. EMPTY=1
  6.  
  7. ADDED=$(diff --new-line-format='%L' --old-line-format='' --unchanged-line-format='' "$1" "$2")
  8. REMOVED=$(diff --new-line-format='' --old-line-format='%L' --unchanged-line-format='' "$1" "$2")
  9. TOTAL=$(cat "$2")
  10.  
  11. STATS_OLD=$(grep -E '^STAT:' "$1" | sed -E 's/^STAT://')
  12. STATS_NEW=$(grep -E '^STAT:' "$2" | sed -E 's/^STAT://')
  13.  
  14. STATS_DIFFED=$(diff --new-line-format='+%L' --old-line-format='-%L' --unchanged-line-format=' %L' <(echo "$STATS_OLD") <(echo "$STATS_NEW"))
  15.  
  16. ADDED_DEPRECATIONS=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$ADDED")
  17. REMOVED_DEPRECATIONS=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$REMOVED")
  18. ADDED_WARNINGS=$(grep -Pi '\b(warn|warning)\b' <<< "$ADDED")
  19. REMOVED_WARNINGS=$(grep -Pi '\b(warn|warning)\b' <<< "$REMOVED")
  20.  
  21. DEPRECATION_COUNT=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$TOTAL" | wc -l)
  22. WARNING_COUNT=$(grep -Pi '\b(warn|warning)\b' <<< "$TOTAL" | wc -l)
  23.  
  24. if [ -z "$ADDED_DEPRECATIONS" ]; then
  25. # no new deprecations
  26. true
  27. else
  28. echo "⚠️ This PR introduces new deprecations:"
  29. echo
  30. echo '```'
  31. echo "$ADDED_DEPRECATIONS"
  32. echo '```'
  33. echo
  34. EMPTY=0
  35. fi
  36.  
  37. if [ -z "$ADDED_WARNINGS" ]; then
  38. # no new deprecations
  39. true
  40. else
  41. echo "⚠️ This PR introduces new warnings:"
  42. echo
  43. echo '```'
  44. echo "$ADDED_WARNINGS"
  45. echo '```'
  46. echo
  47. EMPTY=0
  48. fi
  49.  
  50. if grep "BUILD FAILED" <<< "$TOTAL"; then
  51. echo '❌ Basic `dub build` failed! Please check your changes again.'
  52. echo
  53. else
  54. if [ -z "$REMOVED_DEPRECATIONS" ]; then
  55. # no removed deprecations
  56. true
  57. else
  58. echo "✅ This PR fixes following deprecations:"
  59. echo
  60. echo '```'
  61. echo "$REMOVED_DEPRECATIONS"
  62. echo '```'
  63. echo
  64. EMPTY=0
  65. fi
  66.  
  67. if [ -z "$REMOVED_WARNINGS" ]; then
  68. # no removed warnings
  69. true
  70. else
  71. echo "✅ This PR fixes following warnings:"
  72. echo
  73. echo '```'
  74. echo "$REMOVED_WARNINGS"
  75. echo '```'
  76. echo
  77. EMPTY=0
  78. fi
  79.  
  80. if [ $EMPTY == 1 ]; then
  81. echo "✅ PR OK, no changes in deprecations or warnings"
  82. echo
  83. fi
  84.  
  85. echo "Total deprecations: $DEPRECATION_COUNT"
  86. echo
  87. echo "Total warnings: $WARNING_COUNT"
  88. echo
  89. fi
  90.  
  91. if [ -z "$STATS_DIFFED" ]; then
  92. # no statistics?
  93. true
  94. else
  95. echo "Build statistics:"
  96. echo
  97. echo '```diff'
  98. echo "$STATS_DIFFED"
  99. echo '```'
  100. echo
  101. fi
  102.  
  103. echo '<details>'
  104. echo
  105. echo '<summary>Full build output</summary>'
  106. echo
  107. echo '```'
  108. echo "$TOTAL"
  109. echo '```'
  110. echo
  111. echo '</details>'