예제 #1
0
def test_merges_approved_pr(tmpdir):
    BRANCH_NAME = 'test_merges_approved_pr'
    pr_number = None
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'
            },
            'name': 'master'
        }, True]]
        os.chdir(tmpdir)
        call(
            [
                'git', 'clone',
                f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'
            ],
            # do not leak the token
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call([
            'git', 'config', 'user.email',
            '*****@*****.**'
        ])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        call(['git', 'checkout', '-b', BRANCH_NAME])
        call(['git', 'commit', '--allow-empty', '-m', 'foo'])
        call(['git', 'push', 'origin', BRANCH_NAME])
        source_sha = rev_parse(BRANCH_NAME)
        gh_pr = post_repo(FQ_REPO,
                          'pulls',
                          json={
                              "title": "foo",
                              "head": BRANCH_NAME,
                              "base": "master"
                          },
                          status_code=201)
        pr_number = str(gh_pr['number'])
        post_repo(FQ_REPO,
                  f'pulls/{pr_number}/reviews',
                  json={
                      "commit_id": source_sha,
                      "event": "APPROVE"
                  },
                  status_code=200,
                  token=oauth_tokens['user2'])
        get_repo(FQ_REPO,
                 f'pulls/{pr_number}/reviews',
                 status_code=200,
                 token=oauth_tokens['user1'])
        time.sleep(7)
        poll_github_until_merged(pr_number)

        call(['git', 'fetch', 'origin'])
        merged_sha = rev_parse('origin/master')

        # deploy job takes some time
        time.sleep(7)

        deploy_artifact = run(
            ['gsutil', 'cat', f'gs://hail-ci-test/{merged_sha}'],
            stdout=subprocess.PIPE,
            check=True)
        deploy_artifact = deploy_artifact.stdout.decode('utf-8').strip()
        assert f'commit {merged_sha}' in deploy_artifact
    finally:
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        if pr_number is not None:
            patch_repo(FQ_REPO,
                       f'pulls/{pr_number}',
                       json={"state": "closed"},
                       status_code=200)
예제 #2
0
def test_pull_request_trigger(tmpdir):
    BRANCH_NAME = 'test_pull_request_trigger'
    pr_number = None
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'
            },
            'name': 'master'
        }, True]]
        os.chdir(tmpdir)
        call(
            [
                'git', 'clone',
                f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'
            ],
            # do not leak the token
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call([
            'git', 'config', 'user.email',
            '*****@*****.**'
        ])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        call(['git', 'checkout', '-b', BRANCH_NAME])
        call(['git', 'commit', '--allow-empty', '-m', 'foo'])
        call(['git', 'push', 'origin', BRANCH_NAME])
        source_sha = rev_parse(BRANCH_NAME)
        target_sha = rev_parse('master')
        data = post_repo(FQ_REPO,
                         'pulls',
                         json={
                             "title": "foo",
                             "head": BRANCH_NAME,
                             "base": "master"
                         },
                         status_code=201,
                         token=oauth_tokens['user1'])
        pr_number = str(data['number'])
        time.sleep(7)
        pr = poll_until_finished_pr(BRANCH_NAME)
        assertDictHasKVs(
            pr.to_json(), {
                "target": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": "master"
                    },
                    "sha": target_sha
                },
                "source": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": BRANCH_NAME
                    },
                    "sha": source_sha
                },
                "review": "pending",
                "build": {
                    "type": "Mergeable",
                    "target_sha": target_sha
                },
                "number": pr_number
            })
    finally:
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        if pr_number is not None:
            patch_repo(FQ_REPO,
                       f'pulls/{pr_number}',
                       json={"state": "closed"},
                       status_code=200,
                       token=oauth_tokens['user1'])
예제 #3
0
def test_push_while_building(tmpdir):
    BRANCH_NAME = 'test_push_while_building'
    SLOW_BRANCH_NAME = 'test_push_while_building_slow'
    pr_number = {}
    source_sha = {}
    gh_pr = {}
    pr = {}
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'
            },
            'name': 'master'
        }, True]]
        os.chdir(tmpdir)

        call(
            [
                'git', 'clone',
                f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'
            ],
            # do not leak the token
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call([
            'git', 'config', 'user.email',
            '*****@*****.**'
        ])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        # start slow branch
        call(['git', 'checkout', 'master'])
        first_target_sha = rev_parse('master')
        call(['git', 'checkout', '-b', SLOW_BRANCH_NAME])
        with open('hail-ci-build.sh', 'w') as f:
            f.write('sleep 45')
        call(['git', 'add', 'hail-ci-build.sh'])
        call(['git', 'commit', '-m', 'foo'])
        source_sha[SLOW_BRANCH_NAME] = push(SLOW_BRANCH_NAME)
        gh_pr[SLOW_BRANCH_NAME] = create_pull_request('foo', SLOW_BRANCH_NAME)
        pr_number[SLOW_BRANCH_NAME] = gh_pr[SLOW_BRANCH_NAME]['number']

        # get details on first job of slow branch
        pr[SLOW_BRANCH_NAME] = poll_until_pr_exists_and(
            SLOW_BRANCH_NAME, lambda x: x.is_building())
        assertDictHasKVs(
            pr[SLOW_BRANCH_NAME].to_json(), {
                "target": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": "master"
                    },
                    "sha": first_target_sha
                },
                "source": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": SLOW_BRANCH_NAME
                    },
                    "sha": source_sha[SLOW_BRANCH_NAME]
                },
                "review": "pending",
                "build": {
                    "type": "Building",
                    "target_sha": first_target_sha
                },
                "number": str(pr_number[SLOW_BRANCH_NAME])
            })
        first_slow_job_id = pr[SLOW_BRANCH_NAME].build.job.id
        assert first_slow_job_id is not None

        # start fast branch
        source_sha[BRANCH_NAME] = create_and_push_empty_commit(BRANCH_NAME)
        gh_pr[BRANCH_NAME] = create_pull_request('foo', BRANCH_NAME)
        pr_number[BRANCH_NAME] = gh_pr[BRANCH_NAME]['number']
        approve(pr_number[BRANCH_NAME], source_sha[BRANCH_NAME])

        poll_github_until_merged(pr_number[BRANCH_NAME])

        call(['git', 'fetch', 'origin'])
        second_target_sha = rev_parse('origin/master')

        time.sleep(10)  # allow deploy job to run

        deploy_artifact = run(
            ['gsutil', 'cat', f'gs://hail-ci-test/{second_target_sha}'],
            stdout=subprocess.PIPE)
        deploy_artifact = deploy_artifact.stdout.decode('utf-8').strip()
        assert f'commit {second_target_sha}' in deploy_artifact

        time.sleep(5)  # allow github push notification to be sent

        pr[SLOW_BRANCH_NAME] = poll_until_finished_pr(SLOW_BRANCH_NAME)
        assertDictHasKVs(
            pr[SLOW_BRANCH_NAME].to_json(), {
                "target": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": "master"
                    },
                    "sha": second_target_sha
                },
                "source": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": SLOW_BRANCH_NAME
                    },
                    "sha": source_sha[SLOW_BRANCH_NAME]
                },
                "review": "pending",
                "build": {
                    "type": "Mergeable",
                    "target_sha": second_target_sha
                },
                "number": str(pr_number[SLOW_BRANCH_NAME])
            })
    finally:
        call(['git', 'push', 'origin', ':' + SLOW_BRANCH_NAME])
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        for pr_number in pr_number.values():
            patch_repo(FQ_REPO,
                       f'pulls/{pr_number}',
                       json={"state": "closed"},
                       status_code=200,
                       token=oauth_tokens['user1'])
예제 #4
0
파일: test-ci.py 프로젝트: lfrancioli/hail
def test_merges_approved_pr(tmpdir):
    BRANCH_NAME = 'test_merges_approved_pr'
    pr_number = None
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'},
            'name': 'master'}, True]]
        os.chdir(tmpdir)
        call(['git', 'clone', f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'],
             # do not leak the token
             stdout=subprocess.DEVNULL,
             stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call(['git', 'config', 'user.email', '*****@*****.**'])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        call(['git', 'checkout', '-b', BRANCH_NAME])
        call(['git', 'commit', '--allow-empty', '-m', 'foo'])
        call(['git', 'push', 'origin', BRANCH_NAME])
        source_sha = rev_parse(BRANCH_NAME)
        gh_pr = post_repo(
            FQ_REPO,
            'pulls',
            json={
                "title": "foo",
                "head": BRANCH_NAME,
                "base": "master"
            },
            status_code=201)
        pr_number = str(gh_pr['number'])
        post_repo(
            FQ_REPO,
            f'pulls/{pr_number}/reviews',
            json={
                "commit_id": source_sha,
                "event": "APPROVE"
            },
            status_code=200,
            token=oauth_tokens['user2'])
        get_repo(
            FQ_REPO,
            f'pulls/{pr_number}/reviews',
            status_code=200,
            token=oauth_tokens['user1'])
        time.sleep(7)
        poll_github_until_merged(pr_number)

        call(['git', 'fetch', 'origin'])
        merged_sha = rev_parse('origin/master')

        # deploy job takes some time
        time.sleep(7)

        deploy_artifact = run(['gsutil', 'cat', f'gs://hail-ci-test/{merged_sha}'], stdout=subprocess.PIPE, check=True)
        deploy_artifact = deploy_artifact.stdout.decode('utf-8').strip()
        assert f'commit {merged_sha}' in deploy_artifact
    finally:
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        if pr_number is not None:
            patch_repo(
                FQ_REPO,
                f'pulls/{pr_number}',
                json={"state": "closed"},
                status_code=200)
예제 #5
0
파일: test-ci.py 프로젝트: lfrancioli/hail
def test_push_while_building(tmpdir):
    BRANCH_NAME = 'test_push_while_building'
    SLOW_BRANCH_NAME = 'test_push_while_building_slow'
    pr_number = {}
    source_sha = {}
    gh_pr = {}
    pr = {}
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'},
            'name': 'master'}, True]]
        os.chdir(tmpdir)

        call(['git', 'clone', f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'],
             # do not leak the token
             stdout=subprocess.DEVNULL,
             stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call(['git', 'config', 'user.email', '*****@*****.**'])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        # start slow branch
        call(['git', 'checkout', 'master'])
        first_target_sha = rev_parse('master')
        call(['git', 'checkout', '-b', SLOW_BRANCH_NAME])
        with open('hail-ci-build.sh', 'w') as f:
            f.write('sleep 45')
        call(['git', 'add', 'hail-ci-build.sh'])
        call(['git', 'commit', '-m', 'foo'])
        source_sha[SLOW_BRANCH_NAME] = push(SLOW_BRANCH_NAME)
        gh_pr[SLOW_BRANCH_NAME] = create_pull_request(
            'foo',
            SLOW_BRANCH_NAME)
        pr_number[SLOW_BRANCH_NAME] = gh_pr[SLOW_BRANCH_NAME]['number']

        # get details on first job of slow branch
        pr[SLOW_BRANCH_NAME] = poll_until_pr_exists_and(
            SLOW_BRANCH_NAME,
            lambda x: x.is_building())
        assertDictHasKVs(
            pr[SLOW_BRANCH_NAME].to_json(),
            {
                "target": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": "master"
                    },
                    "sha": first_target_sha
                },
                "source": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": SLOW_BRANCH_NAME
                    },
                    "sha": source_sha[SLOW_BRANCH_NAME]
                },
                "review": "pending",
                "build": {
                    "type": "Building",
                    "target_sha": first_target_sha
                },
                "number": str(pr_number[SLOW_BRANCH_NAME])
            })
        first_slow_job_id = pr[SLOW_BRANCH_NAME].build.job.id
        assert first_slow_job_id is not None

        # start fast branch
        source_sha[BRANCH_NAME] = create_and_push_empty_commit(
            BRANCH_NAME)
        gh_pr[BRANCH_NAME] = create_pull_request(
            'foo',
            BRANCH_NAME)
        pr_number[BRANCH_NAME] = gh_pr[BRANCH_NAME]['number']
        approve(pr_number[BRANCH_NAME], source_sha[BRANCH_NAME])

        poll_github_until_merged(pr_number[BRANCH_NAME])

        call(['git', 'fetch', 'origin'])
        second_target_sha = rev_parse('origin/master')

        time.sleep(10)  # allow deploy job to run

        deploy_artifact = run(['gsutil', 'cat', f'gs://hail-ci-test/{second_target_sha}'], stdout=subprocess.PIPE)
        deploy_artifact = deploy_artifact.stdout.decode('utf-8').strip()
        assert f'commit {second_target_sha}' in deploy_artifact

        time.sleep(5)  # allow github push notification to be sent

        pr[SLOW_BRANCH_NAME] = poll_until_finished_pr(
            SLOW_BRANCH_NAME)
        assertDictHasKVs(
            pr[SLOW_BRANCH_NAME].to_json(),
            {
                "target": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": "master"
                    },
                    "sha": second_target_sha
                },
                "source": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": SLOW_BRANCH_NAME
                    },
                    "sha": source_sha[SLOW_BRANCH_NAME]
                },
                "review": "pending",
                "build": {
                    "type": "Mergeable",
                    "target_sha": second_target_sha
                },
                "number": str(pr_number[SLOW_BRANCH_NAME])
            })
    finally:
        call(['git', 'push', 'origin', ':' + SLOW_BRANCH_NAME])
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        for pr_number in pr_number.values():
            patch_repo(
                FQ_REPO,
                f'pulls/{pr_number}',
                json={"state": "closed"},
                status_code=200,
                token=oauth_tokens['user1'])
예제 #6
0
파일: test-ci.py 프로젝트: lfrancioli/hail
def test_pull_request_trigger(tmpdir):
    BRANCH_NAME = 'test_pull_request_trigger'
    pr_number = None
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'},
            'name': 'master'}, True]]
        os.chdir(tmpdir)
        call(['git', 'clone', f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'],
             # do not leak the token
             stdout=subprocess.DEVNULL,
             stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call(['git', 'config', 'user.email', '*****@*****.**'])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        call(['git', 'checkout', '-b', BRANCH_NAME])
        call(['git', 'commit', '--allow-empty', '-m', 'foo'])
        call(['git', 'push', 'origin', BRANCH_NAME])
        source_sha = rev_parse(BRANCH_NAME)
        target_sha = rev_parse('master')
        data = post_repo(
            FQ_REPO,
            'pulls',
            json={
                "title": "foo",
                "head": BRANCH_NAME,
                "base": "master"
            },
            status_code=201,
            token=oauth_tokens['user1'])
        pr_number = str(data['number'])
        time.sleep(7)
        pr = poll_until_finished_pr(BRANCH_NAME)
        assertDictHasKVs(
            pr.to_json(),
            {
                "target": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": "master"
                    },
                    "sha": target_sha
                },
                "source": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": BRANCH_NAME
                    },
                    "sha": source_sha
                },
                "review": "pending",
                "build": {
                    "type": "Mergeable",
                    "target_sha": target_sha
                },
                "number": pr_number
            })
    finally:
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        if pr_number is not None:
            patch_repo(
                FQ_REPO,
                f'pulls/{pr_number}',
                json={"state": "closed"},
                status_code=200,
                token=oauth_tokens['user1'])
예제 #7
0
    def test_merges_approved_pr(self):
        BRANCH_NAME = 'test_merges_approved_pr'
        with tempfile.TemporaryDirectory() as d:
            pr_number = None
            try:
                status = ci_get('/status', status_code=200)
                self.assertIn('_watched_targets', status)
                assert status['_watched_targets'] == [[{
                    'repo': {
                        'name': self.repo_name,
                        'owner': 'hail-ci-test'},
                    'name': 'master'}, True]]
                os.chdir(d)
                call(['git', 'clone', f'[email protected]:hail-ci-test/{self.repo_name}.git'])
                os.chdir(self.repo_name)
                call(['git', 'remote', '-v'])

                call(['git', 'checkout', '-b', BRANCH_NAME])
                call(['git', 'commit', '--allow-empty', '-m', 'foo'])
                call(['git', 'push', 'origin', BRANCH_NAME])
                source_sha = self.rev_parse(BRANCH_NAME)
                gh_pr = post_repo(
                    self.fq_repo,
                    'pulls',
                    json={
                        "title": "foo",
                        "head": BRANCH_NAME,
                        "base": "master"
                    },
                    status_code=201)
                pr_number = str(gh_pr['number'])
                post_repo(
                    self.fq_repo,
                    f'pulls/{pr_number}/reviews',
                    json={
                        "commit_id": source_sha,
                        "event": "APPROVE"
                    },
                    status_code=200,
                    token=oauth_tokens['user2'])
                get_repo(
                    self.fq_repo,
                    f'pulls/{pr_number}/reviews',
                    status_code=200,
                    token=oauth_tokens['user1'])
                time.sleep(7)
                self.poll_github_until_merged(pr_number)

                call(['git', 'fetch', 'origin'])
                merged_sha = self.rev_parse('origin/master')

                # deploy job takes some time
                time.sleep(7)

                deploy_artifact = run(['gsutil', 'cat', f'gs://hail-ci-test/{merged_sha}'], stdout=subprocess.PIPE, check=True)
                deploy_artifact = deploy_artifact.stdout.decode('utf-8').strip()
                assert f'commit {merged_sha}' in deploy_artifact
            finally:
                call(['git', 'push', 'origin', ':' + BRANCH_NAME])
                if pr_number is not None:
                    patch_repo(
                        self.fq_repo,
                        f'pulls/{pr_number}',
                        json={"state": "closed"},
                        status_code=200)
예제 #8
0
    def test_pull_request_trigger(self):
        BRANCH_NAME = 'test_pull_request_trigger'
        with tempfile.TemporaryDirectory() as d:
            pr_number = None
            try:
                status = ci_get('/status', status_code=200)
                self.assertIn('_watched_targets', status)
                self.assertEqual(status['_watched_targets'],
                                 [[{'repo': {
                                     'name': self.repo_name,
                                     'owner': 'hail-ci-test'},
                                    'name': 'master'}, True]])
                os.chdir(d)
                call(['git', 'clone', f'[email protected]:hail-ci-test/{self.repo_name}.git'])
                os.chdir(self.repo_name)
                call(['git', 'remote', '-v'])

                call(['git', 'checkout', '-b', BRANCH_NAME])
                call(['git', 'commit', '--allow-empty', '-m', 'foo'])
                call(['git', 'push', 'origin', BRANCH_NAME])
                source_sha = self.rev_parse(BRANCH_NAME)
                target_sha = self.rev_parse('master')
                data = post_repo(
                    self.fq_repo,
                    'pulls',
                    json={
                        "title": "foo",
                        "head": BRANCH_NAME,
                        "base": "master"
                    },
                    status_code=201,
                    token=oauth_tokens['user1'])
                pr_number = str(data['number'])
                time.sleep(7)
                pr = self.poll_until_finished_pr(BRANCH_NAME)
                assertDictHasKVs(
                    pr.to_json(),
                    {
                        "target": {
                            "ref": {
                                "repo": {
                                    "owner": "hail-ci-test",
                                    "name": self.repo_name
                                },
                                "name": "master"
                            },
                            "sha": target_sha
                        },
                        "source": {
                            "ref": {
                                "repo": {
                                    "owner": "hail-ci-test",
                                    "name": self.repo_name
                                },
                                "name": BRANCH_NAME
                            },
                            "sha": source_sha
                        },
                        "review": "pending",
                        "build": {
                            "type": "Mergeable",
                            "target_sha": target_sha
                        },
                        "number": pr_number
                    })
            finally:
                call(['git', 'push', 'origin', ':' + BRANCH_NAME])
                if pr_number is not None:
                    patch_repo(
                        self.fq_repo,
                        f'pulls/{pr_number}',
                        json={"state": "closed"},
                        status_code=200,
                        token=oauth_tokens['user1'])