示例#1
0
 def checkout(self, branch=None, commit=None, tag=None, pr=None):
     if branch or commit:
         cmd = ['git', 'checkout', branch or commit]
     elif tag:
         cmd = ['git', 'checkout', 'tags/%s' % tag]
     else:
         cmd = ['git', 'fetch', 'origin', 'pull/%s/head:%s' % (pr, pr)]
         p = call(cmd, cwd=self._root)
         if p.returncode:
             return p.returncode
         cmd = ['git', 'checkout', str(pr)]
     return call(cmd, cwd=self._root).returncode
示例#2
0
 def __init__(self, root, clone=None):
     root = root if os.path.isabs(root) else os.path.join(os.getcwd(), root)
     self._root = root
     self.clone_code = None
     if clone:
         cmd = ['git', 'clone', clone, self._root]
         self.clone_code = call(cmd).returncode
示例#3
0
def main():
    cmd = ['python', '-m', ARGS.action] + OTHER_ARGS
    cwd = os.path.dirname(os.path.realpath(__file__))

    with open(ACTION_OUT, 'w') as out:
        with open(ACTION_ERR, 'w') as err:
            p = call(cmd, cwd=cwd, stdout=out, stderr=err)
    logging.info('Return code = %s', p.returncode)

    logging.info('Uploading logs to gs://%s/%s/', constants.BUCKET, OBJ_DIR)
    gcs_action_out = os.path.join(OBJ_DIR, ACTION_OUT)
    gcs_action_err = os.path.join(OBJ_DIR, ACTION_ERR)
    gcs.upload_file(ACTION_OUT, gcs_action_out, 'text/plain')
    gcs.upload_file(ACTION_ERR, gcs_action_err, 'text/plain')
    return p.returncode
示例#4
0
def main():
    logging.info(os.getcwd())
    logging.info('Downloading Daisy repo.')
    code = call(['go', 'get', constants.GOPACKAGE]).returncode
    if code:
        return code

    if ARGS.golint:
        logging.info('Downloading golint.')
        code = call(['go', 'get', GOLINT_PACKAGE]).returncode
        if code:
            return code

    if ARGS.gotest:
        logging.info('Downloading go-junit-report.')
        code = call(['go', 'get', GOJUNIT_PACKAGE]).returncode
        if code:
            return code

    logging.info('Checking out PR #%s', ARGS.pr)
    repo = git.Repo(constants.GOPACKAGE_PATH)
    code = repo.checkout(pr=ARGS.pr)
    if code:
        return code

    logging.info('Pulling dependencies.')
    code = call(['go', 'get', '-t', './...'], cwd=repo.root).returncode
    if code:
        return code

    logging.info('Running checks.')
    if ARGS.gofmt:
        code = call(['gofmt', '-l', '.'], cwd=repo.root).returncode
        if code:
            return code
    if ARGS.govet:
        code = call(['go', 'vet', './...'], cwd=repo.root).returncode
        if code:
            return code
    if ARGS.golint:
        cmd = ['golint', '-set_exit_status', './...']
        code = call(cmd, cwd=repo.root).returncode
        if code:
            return code
    if ARGS.gotest:
        commit = repo.commit
        package = constants.GOPACKAGE
        res = result.PR(ARGS.pr, commit)
        res.started()
        cmd = ['./unit_tests.sh', package, commit, str(ARGS.pr)]
        code = call(cmd, cwd=THIS_DIR).returncode
        if code:
            res.finished('FAILURE')
            res.build_log(build_log.read())
            return code
        res.finished('SUCCESS')

        for path in glob.glob(os.path.join(THIS_DIR, '*.xml')):
            name = os.path.basename(path)
            with open(path) as f:
                data = f.read()
            res.artifact('junit_%s' % name,
                         data=data,
                         content_type='application/xml')

        res.build_log(build_log.getvalue())

    return 0
示例#5
0
 def commit(self):
     p = call(['git', 'rev-parse', 'HEAD'], cwd=self._root, stdout=PIPE)
     out, _ = p.communicate()
     return out.strip()