diff options
author | tarasov-egor <jorres.tarasov@gmail.com> | 2023-05-12 13:02:42 +0000 |
---|---|---|
committer | tarasov-egor <jorres.tarasov@ydb.tech> | 2023-05-12 16:02:42 +0300 |
commit | ca989b656060070f8add05eae3b6668ae0e06de4 (patch) | |
tree | 2a95cd252e594a959ecc8312be757290a7d144d3 /.github/workflows | |
parent | f0addd0481e841b7c4a4e0ad0d25ed85e4930508 (diff) | |
download | ydb-ca989b656060070f8add05eae3b6668ae0e06de4.tar.gz |
"External contributor pipeline"
"External contributor pipeline"
Pull Request resolved: #204
Diffstat (limited to '.github/workflows')
-rw-r--r-- | .github/workflows/build_and_test_ondemand.yml | 21 | ||||
-rw-r--r-- | .github/workflows/pr_check.yml | 57 |
2 files changed, 76 insertions, 2 deletions
diff --git a/.github/workflows/build_and_test_ondemand.yml b/.github/workflows/build_and_test_ondemand.yml index eb5e54923e..4daea429c9 100644 --- a/.github/workflows/build_and_test_ondemand.yml +++ b/.github/workflows/build_and_test_ondemand.yml @@ -52,6 +52,27 @@ jobs: core-fraction: 100 zone-id: ru-central1-b subnet-id: ${{secrets.YC_SUBNET}} + - 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); + } prepare-vm: name: Prepare runner diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml index a259efee92..6ddffa59c8 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr_check.yml @@ -5,11 +5,64 @@ on: - 'main' 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!' + }); build_and_test: + needs: + - check-running-allowed + if: needs.check-running-allowed.outputs.result == 'true' uses: ./.github/workflows/build_and_test_ondemand.yml - if: github.event.review.state == 'approved' with: test_label_regexp: '(SMALL|MEDIUM)' secrets: inherit |