action.yml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. name: Ya-Build-and-Test
  2. inputs:
  3. build_target:
  4. type: string
  5. default: "ydb/"
  6. description: "limit build and test to specific target"
  7. build_preset:
  8. type: string
  9. run_build:
  10. type: boolean
  11. default: true
  12. description: "run build"
  13. run_tests:
  14. type: boolean
  15. default: true
  16. description: "run tests"
  17. run_tests_if_build_fails:
  18. default: "true"
  19. description: "run tests if build fails"
  20. test_threads:
  21. type: string
  22. default: 28
  23. description: "Test threads count"
  24. link_threads:
  25. type: string
  26. default: 12
  27. description: "link threads count"
  28. test_size:
  29. type: string
  30. default: "small,medium,large"
  31. test_type:
  32. type: string
  33. default: ""
  34. description: "run only specific test types (or all by default)"
  35. increment:
  36. type: boolean
  37. required: true
  38. description: If true, compares build graphs between the current and previous commits to find a list of test suites to run. Otherwise, runs all tests.
  39. folder_prefix:
  40. type: string
  41. default: "ya-"
  42. put_build_results_to_cache:
  43. type: boolean
  44. default: true
  45. additional_ya_make_args:
  46. type: string
  47. default: ""
  48. secs:
  49. type: string
  50. default: ""
  51. vars:
  52. type: string
  53. default: ""
  54. defaults:
  55. run:
  56. shell: bash
  57. runs:
  58. using: "composite"
  59. steps:
  60. - name: comment-build-start
  61. if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
  62. shell: bash
  63. env:
  64. BUILD_PRESET: ${{ inputs.build_preset }}
  65. GITHUB_TOKEN: ${{ github.token }}
  66. run: |
  67. jobs_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/jobs"
  68. # tricky: we are searching job with name that contains build_preset
  69. check_url=$(curl -s $jobs_url | jq --arg n "$BUILD_PRESET" -r '.jobs[] | select(.name | contains($n)) | .html_url')
  70. echo "Pre-commit [check]($check_url) for $(git rev-parse HEAD) has started." | .github/scripts/tests/comment-pr.py --rewrite
  71. curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
  72. https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
  73. -d '{"state":"pending","description":"The check has been started","context":"build_${{inputs.build_preset}}"}'
  74. if [[ "${{inputs.run_tests}}" == "true" ]];then
  75. curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
  76. https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
  77. -d '{"state":"pending","description":"The check has been started","context":"test_${{inputs.build_preset}}"}'
  78. fi
  79. - name: Prepare s3cmd
  80. uses: ./.github/actions/s3cmd
  81. with:
  82. s3_bucket: ${{ fromJSON( inputs.vars ).AWS_BUCKET }}
  83. s3_endpoint: ${{ fromJSON( inputs.vars ).AWS_ENDPOINT }}
  84. s3_key_id: ${{ fromJSON( inputs.secs ).AWS_KEY_ID }}
  85. s3_key_secret: ${{ fromJSON( inputs.secs ).AWS_KEY_VALUE }}
  86. folder_prefix: ya-
  87. build_preset: ${{ inputs.build_preset }}
  88. - name: Generate ya.make with affected test suites and modules list
  89. if: inputs.increment == 'true'
  90. uses: ./.github/actions/graph_compare
  91. - name: Change target in case of incremental (tests)
  92. id: target_choice
  93. shell: bash
  94. run: |
  95. if [ "${{ inputs.increment }}" == "true" ]; then
  96. echo "target=." >> $GITHUB_OUTPUT
  97. else
  98. echo "target=${{ inputs.build_target }}" >> $GITHUB_OUTPUT
  99. fi
  100. - name: Build
  101. uses: ./.github/actions/build_ya
  102. id: build
  103. if: ${{ inputs.run_build == 'true' }}
  104. with:
  105. build_target: ${{ steps.target_choice.outputs.target }}
  106. build_preset: ${{ inputs.build_preset }}
  107. bazel_remote_uri: ${{ fromJSON( inputs.vars ).REMOTE_CACHE_URL || '' }}
  108. bazel_remote_username: ${{ fromJSON( inputs.secs ).REMOTE_CACHE_USERNAME || '' }}
  109. bazel_remote_password: ${{ fromJSON( inputs.secs ).REMOTE_CACHE_PASSWORD || '' }}
  110. put_build_results_to_cache: ${{ inputs.put_build_results_to_cache }}
  111. link_threads: ${{ inputs.link_threads }}
  112. additional_ya_make_args: ${{ inputs.additional_ya_make_args }}
  113. - name: Run tests
  114. uses: ./.github/actions/test_ya
  115. if: ${{ inputs.run_tests == 'true' && (steps.build.outputs.success == 'true' || inputs.run_tests_if_build_fails == 'true') }}
  116. with:
  117. build_target: ${{ steps.target_choice.outputs.target }}
  118. build_preset: ${{ inputs.build_preset }}
  119. test_size: ${{ inputs.test_size }}
  120. test_type: ${{ inputs.test_type }}
  121. testman_token: ${{ fromJSON( inputs.secs ).TESTMO_TOKEN2 }}
  122. testman_url: ${{ fromJSON( inputs.vars ).TESTMO_URL }}
  123. testman_project_id: ${{ fromJSON( inputs.vars ).TESTMO_PROJECT_ID }}
  124. link_threads: ${{ inputs.link_threads }}
  125. additional_ya_make_args: ${{ inputs.additional_ya_make_args }}
  126. test_threads: ${{ inputs.test_threads }}
  127. bazel_remote_uri: ${{ fromJSON( inputs.vars ).REMOTE_CACHE_URL || '' }}
  128. - name: Notify about failed build
  129. if: ${{ steps.build.outputs.success != 'true' && inputs.run_tests == 'true' && inputs.run_tests_if_build_fails == 'false' }}
  130. shell: bash
  131. env:
  132. GITHUB_TOKEN: ${{ github.token }}
  133. run: |
  134. echo 'Build failed. See the [build log](${{ steps.build.outputs.log_url }}).' >> $GITHUB_STEP_SUMMARY
  135. if [[ "$GITHUB_EVENT_NAME" =~ ^pull_request ]]; then
  136. echo "Tests run skipped." | .github/scripts/tests/comment-pr.py --fail
  137. fi
  138. exit 1
  139. - name: build_stats
  140. shell: bash
  141. continue-on-error: true
  142. if: always()
  143. run: |
  144. set -x
  145. export build_preset="${{ inputs.build_preset }}"
  146. export commit_git_sha="$(git rev-parse HEAD)"
  147. python3 -m pip install ydb ydb[yc]
  148. python3 .github/scripts/send_build_stats.py
  149. - name: show_build_size_diff
  150. shell: bash
  151. continue-on-error: true
  152. if: always()
  153. env:
  154. GITHUB_TOKEN: ${{ github.token }}
  155. run: |
  156. set -x
  157. export build_preset="${{ inputs.build_preset }}"
  158. export branch_to_compare="$GITHUB_REF_NAME"
  159. export yellow_treshold=102400
  160. export red_treshold=2097152
  161. export commit_git_sha="$(git rev-parse HEAD)"
  162. python3 -m pip install ydb ydb[yc] humanize
  163. get_sizes_comment_script=.github/scripts/get_build_diff.py
  164. comment_raw=`$get_sizes_comment_script`
  165. IFS=';;;'
  166. read -ra comment_arr <<< "$comment_raw"
  167. printf "$comment"
  168. if [[ ${comment_raw} != "Error"* ]];then
  169. color=${comment_arr[0]}
  170. replace=$color";;;"
  171. comment=${comment_raw/$replace/""}
  172. printf "$comment" | .github/scripts/tests/comment-pr.py --color $color
  173. else
  174. echo "Skipped build size difference, comment_raw = ${comment_raw}"
  175. fi
  176. - name: comment-if-cancel
  177. shell: bash
  178. if: cancelled() && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
  179. env:
  180. BUILD_PRESET: ${{ inputs.build_preset }}
  181. GITHUB_TOKEN: ${{ github.token }}
  182. run: echo "Check cancelled" | .github/scripts/tests/comment-pr.py --color black