diff options
author | Alexander Smirnov <alexv-smirnov@yandex-team.ru> | 2023-05-31 19:05:05 +0200 |
---|---|---|
committer | Alexander Smirnov <alexv-smirnov@yandex-team.ru> | 2023-05-31 19:05:05 +0200 |
commit | 10ba5cc0c3d130ce4b33d307d265b937dd572c39 (patch) | |
tree | f5de7deac53b0989332e9e8571d75c8916239f3f /.github/workflows/pr_check.yml | |
parent | 1db08b73476ce8a181ff6163ec91305fe7a8cc56 (diff) | |
download | ydb-10ba5cc0c3d130ce4b33d307d265b937dd572c39.tar.gz |
bring workflows from main
Diffstat (limited to '.github/workflows/pr_check.yml')
-rw-r--r-- | .github/workflows/pr_check.yml | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml new file mode 100644 index 0000000000..c50690b1de --- /dev/null +++ b/.github/workflows/pr_check.yml @@ -0,0 +1,90 @@ +name: PR check +on: + pull_request_target: + branches: + - 'main' + - 'stable-*' + paths-ignore: + - 'ydb/docs/**' + types: + - 'opened' + - 'synchronize' + - 'reopened' + - 'labeled' +jobs: + + check-running-allowed: + runs-on: ubuntu-latest + outputs: + result: ${{ steps.check-ownership-membership.outputs.result }} + steps: + - name: Check if running tests is allowed + id: check-ownership-membership + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + script: | + // This is used primarily in forks. Repository owner + // should be allowed to run anything. + const userLogin = context.payload.pull_request.user.login; + if (context.payload.repository.owner.login == userLogin) { + return true; + } + + const response = await github.rest.orgs.checkMembershipForUser({ + org: context.payload.organization.login, + username: userLogin, + }); + + // How to interpret membership status code: + // https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-organization-membership-for-a-user + if (response.status == '204') { + return true; + } + + const labels = context.payload.pull_request.labels; + const okToTestLabel = labels.find( + label => label.name == 'ok-to-test' + ); + return okToTestLabel !== undefined; + - name: comment-if-waiting-on-ok + if: steps.check-ownership-membership.outputs.result == 'false' && + github.event.action == 'opened' + uses: actions/github-script@v6 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + 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!' + }); + - name: cleanup-test-label + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + script: | + const { owner, repo } = context.repo; + const prNumber = context.payload.pull_request.number; + const labelToRemove = 'ok-to-test'; + try { + const result = await github.rest.issues.removeLabel({ + owner, + repo, + issue_number: prNumber, + name: labelToRemove + }); + } catch(e) { + // ignore the 404 error that arises + // when the label did not exist for the + // organization member + console.log(e); + } + build_and_test: + needs: + - check-running-allowed + if: needs.check-running-allowed.outputs.result == 'true' + uses: ./.github/workflows/build_and_test_ondemand.yml + with: + test_label_regexp: '(SMALL|MEDIUM)' + secrets: inherit |