pr_check.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. name: PR-check
  2. on:
  3. pull_request_target:
  4. branches:
  5. - 'main'
  6. - 'stable-*'
  7. paths-ignore:
  8. - 'ydb/docs/**'
  9. - '.github/**'
  10. - '*'
  11. types:
  12. - 'opened'
  13. - 'synchronize'
  14. - 'reopened'
  15. - 'labeled'
  16. concurrency:
  17. group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
  18. cancel-in-progress: true
  19. jobs:
  20. check-running-allowed:
  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.YDB_PLATFORM_BOT_TOKEN_REPO }}
  30. script: |
  31. // This is used primarily in forks. Repository owner
  32. // should be allowed to run anything.
  33. const userLogin = context.payload.pull_request.user.login;
  34. // How to interpret membership status code:
  35. // https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-organization-membership-for-a-user
  36. const isOrgMember = async function () {
  37. try {
  38. const response = await github.rest.orgs.checkMembershipForUser({
  39. org: context.payload.organization.login,
  40. username: userLogin,
  41. });
  42. return response.status == 204;
  43. } catch (error) {
  44. if (error.status && error.status == 404) {
  45. return false;
  46. }
  47. throw error;
  48. }
  49. }
  50. if (context.payload.repository.owner.login == userLogin) {
  51. return true;
  52. }
  53. if (await isOrgMember()) {
  54. return true;
  55. }
  56. const labels = context.payload.pull_request.labels;
  57. const okToTestLabel = labels.find(
  58. label => label.name == 'ok-to-test'
  59. );
  60. return okToTestLabel !== undefined;
  61. - name: comment-if-waiting-on-ok
  62. if: steps.check-ownership-membership.outputs.result == 'false' &&
  63. github.event.action == 'opened'
  64. uses: actions/github-script@v6
  65. with:
  66. script: |
  67. github.rest.issues.createComment({
  68. issue_number: context.issue.number,
  69. owner: context.repo.owner,
  70. repo: context.repo.repo,
  71. 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!'
  72. });
  73. - name: cleanup-test-label
  74. uses: actions/github-script@v6
  75. with:
  76. script: |
  77. const { owner, repo } = context.repo;
  78. const prNumber = context.payload.pull_request.number;
  79. const labelToRemove = 'ok-to-test';
  80. try {
  81. const result = await github.rest.issues.removeLabel({
  82. owner,
  83. repo,
  84. issue_number: prNumber,
  85. name: labelToRemove
  86. });
  87. } catch(e) {
  88. // ignore the 404 error that arises
  89. // when the label did not exist for the
  90. // organization member
  91. console.log(e);
  92. }
  93. build_and_test:
  94. needs:
  95. - check-running-allowed
  96. if: needs.check-running-allowed.outputs.result == 'true'
  97. uses: ./.github/workflows/build_and_test_ondemand.yml
  98. with:
  99. run_functional_tests: false
  100. test_label_regexp: '(SMALL|MEDIUM)'
  101. secrets: inherit