action.yml 4.9 KB

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