action.yml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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: 8
  27. description: "link threads count"
  28. test_size:
  29. type: string
  30. default: "small,medium,large"
  31. test_type:
  32. type: string
  33. default: "unittest,py3test,py2test,pytest"
  34. increment:
  35. type: boolean
  36. required: true
  37. 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.
  38. folder_prefix:
  39. type: string
  40. default: "ya-"
  41. put_build_results_to_cache:
  42. type: boolean
  43. default: true
  44. secs:
  45. type: string
  46. default: ""
  47. vars:
  48. type: string
  49. default: ""
  50. defaults:
  51. run:
  52. shell: bash
  53. runs:
  54. using: "composite"
  55. steps:
  56. - name: comment-build-start
  57. if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
  58. shell: bash
  59. env:
  60. BUILD_PRESET: ${{ inputs.build_preset }}
  61. GITHUB_TOKEN: ${{ github.token }}
  62. run: |
  63. jobs_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/jobs"
  64. # tricky: we are searching job with name that contains build_preset
  65. check_url=$(curl -s $jobs_url | jq --arg n "$BUILD_PRESET" -r '.jobs[] | select(.name | contains($n)) | .html_url')
  66. echo "Pre-commit [check]($check_url) for $(git rev-parse HEAD) has started." | .github/scripts/tests/comment-pr.py --rewrite
  67. - name: Prepare s3cmd
  68. uses: ./.github/actions/s3cmd
  69. with:
  70. s3_bucket: ${{ fromJSON( inputs.vars ).AWS_BUCKET }}
  71. s3_endpoint: ${{ fromJSON( inputs.vars ).AWS_ENDPOINT }}
  72. s3_key_id: ${{ fromJSON( inputs.secs ).AWS_KEY_ID }}
  73. s3_key_secret: ${{ fromJSON( inputs.secs ).AWS_KEY_VALUE }}
  74. folder_prefix: ya-
  75. build_preset: ${{ inputs.build_preset }}
  76. - name: Build
  77. uses: ./.github/actions/build_ya
  78. id: build
  79. if: ${{ inputs.run_build == 'true' }}
  80. with:
  81. build_target: ${{ inputs.build_target }}
  82. build_preset: ${{ inputs.build_preset }}
  83. bazel_remote_uri: ${{ fromJSON( inputs.vars ).REMOTE_CACHE_URL || '' }}
  84. bazel_remote_username: ${{ inputs.put_build_results_to_cache && fromJSON( inputs.secs ).REMOTE_CACHE_USERNAME || '' }}
  85. bazel_remote_password: ${{ inputs.put_build_results_to_cache && fromJSON( inputs.secs ).REMOTE_CACHE_PASSWORD || '' }}
  86. link_threads: ${{ inputs.link_threads }}
  87. - name: Generate ya.make with affected test suites list
  88. if: inputs.run_tests == 'true' && inputs.increment == 'true'
  89. uses: ./.github/actions/graph_compare
  90. - name: Check if there's a list of tests to run
  91. id: test_run_choice
  92. shell: bash
  93. run: |
  94. if [ -f ya.make ];then
  95. echo "target='.'" >> $GITHUB_OUTPUT
  96. echo "Listed test targets: "
  97. cat ya.make
  98. else
  99. echo "target=${{ inputs.build_target }}" >> $GITHUB_OUTPUT
  100. fi
  101. - name: Run tests
  102. uses: ./.github/actions/test_ya
  103. if: ${{ inputs.run_tests == 'true' && (steps.build.outputs.success == 'true' || inputs.run_tests_if_build_fails == 'true') }}
  104. with:
  105. build_target: ${{ steps.test_run_choice.outputs.target }}
  106. build_preset: ${{ inputs.build_preset }}
  107. test_size: ${{ inputs.test_size }}
  108. testman_token: ${{ fromJSON( inputs.secs ).TESTMO_TOKEN }}
  109. testman_url: ${{ fromJSON( inputs.vars ).TESTMO_URL }}
  110. testman_project_id: ${{ fromJSON( inputs.vars ).TESTMO_PROJECT_ID }}
  111. link_threads: ${{ inputs.link_threads }}
  112. test_threads: ${{ inputs.test_threads }}
  113. - name: Notify about failed build
  114. if: ${{ steps.build.outputs.success != 'true' && inputs.run_tests == 'true' && inputs.run_tests_if_build_fails == 'false' }}
  115. shell: bash
  116. run: |
  117. echo 'Build failed. See the [build log](${{ steps.build.outputs.log_url }}).' >> $GITHUB_STEP_SUMMARY
  118. if [[ "$GITHUB_EVENT_NAME" =~ ^pull_request ]]; then
  119. echo "Tests run skipped." | .github/scripts/tests/comment-pr.py --fail
  120. fi
  121. exit 1
  122. - name: comment-if-cancel
  123. shell: bash
  124. if: cancelled() && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
  125. env:
  126. BUILD_PRESET: ${{ inputs.build_preset }}
  127. GITHUB_TOKEN: ${{ github.token }}
  128. run: echo "Check cancelled" | .github/scripts/tests/comment-pr.py --color black