123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- name: PR-check
- on:
- pull_request_target:
- branches:
- - 'main'
- - 'stable-*'
- paths-ignore:
- - 'ydb/docs/**'
- - '.github/**'
- - '*'
- types:
- - 'opened'
- - 'synchronize'
- - 'reopened'
- - 'labeled'
- concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
- cancel-in-progress: true
- 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.YDB_PLATFORM_BOT_TOKEN_REPO }}
- script: |
- // This is used primarily in forks. Repository owner
- // should be allowed to run anything.
- const userLogin = context.payload.pull_request.user.login;
- // How to interpret membership status code:
- // https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-organization-membership-for-a-user
- const isOrgMember = async function () {
- try {
- const response = await github.rest.orgs.checkMembershipForUser({
- org: context.payload.organization.login,
- username: userLogin,
- });
- return response.status == 204;
- } catch (error) {
- if (error.status && error.status == 404) {
- return false;
- }
- throw error;
- }
- }
- if (context.payload.repository.owner.login == userLogin) {
- return true;
- }
- if (await isOrgMember()) {
- 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:
- 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:
- run_functional_tests: false
- test_label_regexp: '(SMALL|MEDIUM)'
- secrets: inherit
|