Esempio n. 1
0
      raise Exception('Require project argument if metadata specified')
    with open('diff.json') as diffFile:
      buildCommands = get_build_commands(json.loads(args.metadata), args.repository, json.load(diffFile), 'head')
  elif args.buildCommand and args.cleanupCommand:
    buildCommands = { 'build': [args.buildCommand], 'finally': args.cleanupCommand }
  else:
    parser.print_help()
    raise Exception('buildCommand, and cleanupCommand are required')

  try:
    os.mkdir('/home/buildguy/aggregate-metrics/working-dir')
    with open(args.directory + '/aggregate-metrics/commands.json', 'w') as of:
      json.dump(buildCommands, of)
    os.chdir(args.directory + '/build-dir/base')
    for buildCommand in buildCommands['build']:
      call_and_check(buildCommand, "Build failed", shell = True)
    call_and_check('{ find ./ -name \'surefire-reports\' -print0 && find ./ -name \'failsafe-reports\' -print0 && find ./ -wholename \'*bin/reports/*test/xml*\' -type d -print0; } | xargs -0 -I {} find {} -name \'*.xml\' -print0 | xargs -0 python /scripts/lib/test.py > ~/aggregate-metrics/working-dir/beforeTests.json', 'Couldn\'t aggregate surefire output before merge', shell= True)
    call_and_check('find ./ -name \'jacoco\' -print0 | xargs -0 -I {} find {} -name \'*.csv\' -print0 | xargs -0 python /scripts/lib/jacoco.py  > ~/aggregate-metrics/working-dir/jacocoUnitBefore.json', 'Couldn\'t aggregate jacoco unit test output before merge', shell= True)
    call_and_check('{ find ./ -name \'jacoco-integration\' -print0; } | xargs -0 -I {} find {} -name \'*.csv\' -print0 | xargs -0 python /scripts/lib/jacoco.py  > ~/aggregate-metrics/working-dir/jacocoIntegrationBefore.json', 'Couldn\'t aggregate jacoco integration test output before merge', shell= True)
  finally:
    if 'finally' in buildCommands:
      call_and_check(buildCommands['finally'], "Cleanup failed", shell = True)

  try:
    os.chdir('../head')
    with open('/home/buildguy/aggregate-metrics/headerViolations.json', 'w+') as violationsFile:
      json.dump(checkHeaders(args.directory + '/build-dir/diff.json'), violationsFile)
    for buildCommand in buildCommands['build']:
      call_and_check(buildCommand, "Build failed", shell = True)
    call_and_check('cat checkdiff.out | xargs /scripts/lib/checkstyle.py > ~/aggregate-metrics/checkstyle.json', 'Couldn\'t aggregate checkstyle output', shell= True)
    call_and_check('{ find ./ -name \'surefire-reports\' -print0 && find ./ -name \'failsafe-reports\' -print0 && find ./ -wholename \'*bin/reports/*test/xml*\' -type d -print0; } | xargs -0 -I {} find {} -name \'*.xml\' -print0 | xargs -0 python /scripts/lib/test.py > ~/aggregate-metrics/working-dir/afterTests.json', 'Couldn\'t aggregate surefire output after merge', shell= True)
Esempio n. 2
0
  parser.add_argument("-w", "--originOwner", help="Owner of origin repo")
  parser.add_argument("-t", "--branchToBuild", help="Branch to build")
  parser.add_argument("-b", "--buildCommand", help="Build command")
  parser.add_argument("-c", "--cleanupCommand", help="Cleanup command")
  parser.add_argument("-m", "--metadata", help="Metadata (automatic build target detection)")
  parser.add_argument("-o", "--stdout", action='store_true', default=False, help="Print to stdout instead of posting")
  args, unknown = parser.parse_known_args()
  args = vars(args)
  apiToken = os.environ.get('API_TOKEN')
  if apiToken:
    args['apiToken'] = apiToken

  print('Performing setup as root')

  print('Fetching git repo as gitguy')
  call_and_check(add_args(args, ['sudo', '-i', '-H', '-u', 'gitguy', '--', '/scripts/git.py', '-d', '/home/gitguy'], ['apiToken', 'repository', 'pullRequest', 'upstream', 'originOwner', 'branchToBuild']), 'Unable to fetch git repository')

  print('Preparing build resources')
  chown('/home/buildguy/.m2/', 'buildguy', 'buildguy', True)
  chown('/home/buildguy/.ivy2/', 'buildguy', 'buildguy', True)
  chown('/home/buildguy/aggregate-metrics/', 'buildguy', 'buildguy', True)

  call_and_check('find /home/gitguy -name \'.git\' | xargs rm -r', 'Unable to remove .git metadata folders', shell = True)
  call_and_check(['mv', '/home/gitguy/build-dir', '/home/buildguy/build-dir'], 'Unable to move build directory to buildguy\'s home dir')
  chown('/home/buildguy/build-dir', 'buildguy', 'buildguy', True)

  print('Running build as buildguy')
  call_and_check(add_args(args, ['sudo', '-i', '-H', '-u', 'buildguy', '--', '/scripts/build.py', '-d', '/home/buildguy'], ['buildCommand', 'cleanupCommand', 'metadata', 'repository']), 'Build failed')

  print('Posting results as gitguy')
  cp('/home/buildguy/aggregate-metrics/', '/home/gitguy/aggregate-metrics/', True)
Esempio n. 3
0
        buildCommands = {
            'build': [args.buildCommand],
            'finally': args.cleanupCommand
        }
    else:
        parser.print_help()
        raise Exception('buildCommand, and cleanupCommand are required')

    try:
        os.mkdir('/home/buildguy/aggregate-metrics/working-dir')
        with open(args.directory + '/aggregate-metrics/commands.json',
                  'w') as of:
            json.dump(buildCommands, of)
        os.chdir(args.directory + '/build-dir/base')
        for buildCommand in buildCommands['build']:
            call_and_check(buildCommand, "Build failed", shell=True)
        call_and_check(
            '{ find ./ -name \'surefire-reports\' -print0 && find ./ -name \'failsafe-reports\' -print0 && find ./ -wholename \'*bin/reports/*test/xml*\' -type d -print0; } | xargs -0 -I {} find {} -name \'*.xml\' -print0 | xargs -0 python /scripts/lib/test.py > ~/aggregate-metrics/working-dir/beforeTests.json',
            'Couldn\'t aggregate surefire output before merge',
            shell=True)
        call_and_check(
            'find ./ -name \'jacoco\' -print0 | xargs -0 -I {} find {} -name \'*.csv\' -print0 | xargs -0 python /scripts/lib/jacoco.py  > ~/aggregate-metrics/working-dir/jacocoUnitBefore.json',
            'Couldn\'t aggregate jacoco unit test output before merge',
            shell=True)
        call_and_check(
            '{ find ./ -name \'jacoco-integration\' -print0; } | xargs -0 -I {} find {} -name \'*.csv\' -print0 | xargs -0 python /scripts/lib/jacoco.py  > ~/aggregate-metrics/working-dir/jacocoIntegrationBefore.json',
            'Couldn\'t aggregate jacoco integration test output before merge',
            shell=True)
    finally:
        if 'finally' in buildCommands:
            call_and_check(buildCommands['finally'],
Esempio n. 4
0
                        action='store_true',
                        default=False,
                        help="Print to stdout instead of posting")
    args, unknown = parser.parse_known_args()
    args = vars(args)
    apiToken = os.environ.get('API_TOKEN')
    if apiToken:
        args['apiToken'] = apiToken

    print('Performing setup as root')

    print('Fetching git repo as gitguy')
    call_and_check(
        add_args(args, [
            'sudo', '-i', '-H', '-u', 'gitguy', '--', '/scripts/git.py', '-d',
            '/home/gitguy'
        ], [
            'apiToken', 'repository', 'pullRequest', 'upstream', 'originOwner',
            'branchToBuild'
        ]), 'Unable to fetch git repository')

    print('Preparing build resources')
    chown('/home/buildguy/.m2/', 'buildguy', 'buildguy', True)
    chown('/home/buildguy/.ivy2/', 'buildguy', 'buildguy', True)
    chown('/home/buildguy/aggregate-metrics/', 'buildguy', 'buildguy', True)

    call_and_check('find /home/gitguy -name \'.git\' | xargs rm -r',
                   'Unable to remove .git metadata folders',
                   shell=True)
    call_and_check(
        ['mv', '/home/gitguy/build-dir', '/home/buildguy/build-dir'],
        'Unable to move build directory to buildguy\'s home dir')
Esempio n. 5
0
        elif pr_info['merged']:
            raise Exception('PR has already been merged')
        merge_commit_sha = pr_info['merge_commit_sha']
    else:
        baseLabel = ':'.join([args.repository.split('/')[0], args.upstream])
        headLabel = ':'.join([args.originOwner, args.branchToBuild])
        branch_to_apply = args.upstream
        compare_info = get_compare_info(args.repository, headLabel, baseLabel,
                                        args.apiToken)
        reverse_compare_info = get_compare_info(args.repository, baseLabel,
                                                headLabel, args.apiToken)
        originRepo = repositoryPrefix + args.originOwner + '/' + args.repository.split(
            '/')[1] + '.git'

    call_and_check([
        'git', 'config', '--global', 'user.email',
        '*****@*****.**'
    ], "Couldn't set email")
    call_and_check(
        ['git', 'config', '--global', 'user.name', 'docker-buildguy'],
        "Couldn't set email")
    call_and_check([
        'git', 'clone',
        '--depth=' + str(int(reverse_compare_info['ahead_by']) + 10),
        '--branch', branch_to_apply, repository, 'build-dir/base'
    ], "Couldn't clone repo")
    with open(os.path.join(os.getcwd(), 'build-dir', 'diff.json'), 'w') as f:
        json.dump([diffFile['filename'] for diffFile in compare_info['files']],
                  f)
    call_and_check(['cp', '-r', 'build-dir/base', 'build-dir/head'],
                   "Couldn't clone repo")
    os.chdir('build-dir/head')