pr_check.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. name: PR-check
  2. on:
  3. pull_request_target:
  4. branches:
  5. - 'main'
  6. - 'stable-*'
  7. paths-ignore:
  8. - 'ydb/docs/**'
  9. - '*'
  10. types:
  11. - 'opened'
  12. - 'synchronize'
  13. - 'reopened'
  14. - 'labeled'
  15. concurrency:
  16. group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
  17. cancel-in-progress: true
  18. jobs:
  19. check-running-allowed:
  20. if: ${{vars.CHECKS_SWITCH != '' && fromJSON(vars.CHECKS_SWITCH).pr_check == true}}
  21. runs-on: ubuntu-latest
  22. outputs:
  23. result: ${{ steps.check-ownership-membership.outputs.result }}
  24. steps:
  25. - name: Check if running tests is allowed
  26. id: check-ownership-membership
  27. uses: actions/github-script@v6
  28. with:
  29. github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
  30. script: |
  31. const labels = context.payload.pull_request.labels;
  32. const okToTestLabel = labels.find(
  33. label => label.name == 'ok-to-test'
  34. );
  35. console.log("okToTestLabel=%o", okToTestLabel !== undefined);
  36. if (okToTestLabel !== undefined) {
  37. return true;
  38. }
  39. // This is used primarily in forks. Repository owner
  40. // should be allowed to run anything.
  41. const userLogin = context.payload.pull_request.user.login;
  42. // How to interpret membership status code:
  43. // https://docs.github.com/rest/collaborators/collaborators#check-if-a-user-is-a-repository-collaborator
  44. const isRepoCollaborator = async function () {
  45. try {
  46. const response = await github.rest.repos.checkCollaborator({
  47. owner: context.payload.repository.owner.login,
  48. repo: context.payload.repository.name,
  49. username: userLogin,
  50. });
  51. return response.status == 204;
  52. } catch (error) {
  53. if (error.status && error.status == 404) {
  54. return false;
  55. }
  56. throw error;
  57. }
  58. }
  59. if (context.payload.repository.owner.login == userLogin) {
  60. console.log("You are the repository owner!");
  61. return true;
  62. }
  63. if (await isRepoCollaborator()) {
  64. console.log("You are a collaborator!");
  65. return true;
  66. }
  67. return false;
  68. - name: comment-if-waiting-on-ok
  69. if: steps.check-ownership-membership.outputs.result == 'false' &&
  70. github.event.action == 'opened'
  71. uses: actions/github-script@v6
  72. with:
  73. script: |
  74. github.rest.issues.createComment({
  75. issue_number: context.issue.number,
  76. owner: context.repo.owner,
  77. repo: context.repo.repo,
  78. body: 'Hi! Thank you for contributing!\nThe tests on this PR will run after a maintainer adds an `ok-to-test` label to this PR manually. Thank you for your patience!'
  79. });
  80. - name: cleanup-test-label
  81. uses: actions/github-script@v6
  82. with:
  83. script: |
  84. const { owner, repo } = context.repo;
  85. const prNumber = context.payload.pull_request.number;
  86. const labelToRemove = 'ok-to-test';
  87. try {
  88. const result = await github.rest.issues.removeLabel({
  89. owner,
  90. repo,
  91. issue_number: prNumber,
  92. name: labelToRemove
  93. });
  94. } catch(e) {
  95. // ignore the 404 error that arises
  96. // when the label did not exist for the
  97. // organization member
  98. console.log(e);
  99. }
  100. build_and_test:
  101. needs:
  102. - check-running-allowed
  103. if: needs.check-running-allowed.outputs.result == 'true'
  104. strategy:
  105. fail-fast: false
  106. matrix:
  107. build_preset: ["relwithdebinfo", "release-asan"]
  108. name: Build and test ${{ matrix.build_preset }}
  109. uses: ./.github/workflows/build_and_test_ya_provisioned.yml
  110. with:
  111. build_preset: ${{ matrix.build_preset }}
  112. build_target: "ydb/"
  113. test_size: "small,medium"
  114. test_type: "unittest,py3test,py2test,pytest"
  115. test_threads: 52
  116. runner_label: auto-provisioned
  117. put_build_results_to_cache: true
  118. secrets: inherit