def handle(self): self.app.check_configure_file_exists() print_header('Running Test') if self.app.ci_reports['test']: os.makedirs('.framgia-ci-reports', exist_ok=True) test_commands = self.app.ci_reports['test'] results = {} for tool, options in test_commands.items(): if options.get('enable', True): to_run_cmds = [] if isinstance(options['command'], str): to_run_cmds.append(options['command']) elif isinstance(options['command'], list): to_run_cmds = options['command'] general_result = 0 for command in to_run_cmds: general_result = run_command(command) if general_result: break results[tool] = { 'exit_code': general_result, 'comment': options.get('comment', True), 'ignore': options.get('ignore', False) == True } write_results(results, self.app.temp_file_name) sys.exit(0)
def handle(self): is_good_build = True result_text = '' for tool, result in read_results(self.app.temp_file_name).items(): if result['exit_code'] != 0: if result['ignore'] == True: if 'execute_time' in result: format_str = "[!] %s: failed but ignored - [t] execute time: "+ result["execute_time"] + "\n" else: format_str = "[!] %s: failed but ignored \n" else: if 'execute_time' in result: format_str = "[x] %s: failed - [t] execute time: " + result["execute_time"] + "\n" else: format_str = "[!] %s: failed \n" is_good_build = False else: if 'execute_time' in result: format_str = "[o] %s: success - [t] execute time: " + result["execute_time"] + "\n" else: format_str = "[!] %s: success \n" result_text += format_str % tool if is_good_build: print_header('[o] Build Success!') print(result_text) sys.exit(0) else: print_header('[x] Build Fail!') print(result_text) sys.exit(1)
def handle(self): print_header('Sending Notifications') base_api_url = self.app.ci_reports['url'] + '/api/notifications' params = build_params() print( call_api(base_api_url, True, params, ['Content-Type: application/json'])) sys.exit(0)
def handle(self): rspec = 'bundle exec rspec' if exec_command('type rspec').returncode == 0: rspec = 'bundle exec rspec' elif exec_command('type bundle exec rspec').returncode == 0: rspec = 'bundle exec rspec' else: print('Program rspec not found!') sys.exit(1) print_header('Run RSPEC') # Get spec directory from option, resolve extra slash. spec_dir = '/'.join(self.option('spec-dir').strip('/').split('/')) output_dir = '/'.join(self.option('output-dir').strip('/').split('/')) exit_code = 0 if self.option('all'): general_result = run_command(rspec + " --format html --out " + output_dir + "/rspec.html " + spec_dir) exit_code = general_result.returncode else: exec_command_silent( "git --no-pager diff HEAD~1 --name-only --output=.framgia-ci-run-rspec.yml" ) diff_files = open('.framgia-ci-run-rspec.yml', 'r') no_change = 1 for file in diff_files: split_file_name = file.rstrip().replace('.rb', '_spec.rb').split('/') split_file_name[0] = 'spec' target_file = '/'.join(split_file_name) if os.path.isfile('./' + target_file): no_change = 0 print('---\n[!] Run rspec: ' + target_file + '\n---') command_result = exec_command(rspec + ' --format html --out ' + output_dir + '/framgia-ci/rspec.html ' + target_file) if command_result.returncode != 0: exit_code = 1 if no_change: print('Commit doesn\'t have any changed file \n') diff_files.close() print("\n[!] Exit code: " + str(exit_code)) sys.exit(exit_code)
def handle(self): self.app.check_configure_file_exists() print_header('Running Test') if self.app.ci_reports['test']: if not os.path.exists('.framgia-ci-reports'): try: oldmask = os.umask(000) os.makedirs('.framgia-ci-reports', 777) os.umask(oldmask) except OSError as exc: # Guard against race condition if exc.errno != errno.EEXIST: raise test_commands = self.app.ci_reports['test'] results = {} for tool, options in test_commands.items(): if options.get('enable', True): to_run_cmds = [] if isinstance(options['command'], str): to_run_cmds.append(options['command']) try: to_run_cmds.append(options['auto_fix']) except KeyError: pass elif isinstance(options['command'], list): to_run_cmds = options['command'] try: to_run_cmds.append(options['auto_fix']) except KeyError: pass general_result = 0 is_require = False for command in to_run_cmds: #Check current command is require tool. for require_tool in self.REQUIRE_TOOLS: is_require = require_tool in command if is_require: break if self.option('logs'): general_result = run_command(command) else: general_result = run_command_silent(command) results[tool] = { 'exit_code': general_result["cmd"].returncode, 'execute_time': general_result["time"], 'comment': options.get('comment', True), 'ignore': False if is_require else (options.get('ignore', False) == True) # If command is require tool, cant Ignore. } write_results(results, self.app.temp_file_name) sys.exit(0)
def handle(self): print_header('Sending Reports') base_api_url = self.app.ci_reports['url'] + '/api/queues' params = build_params() params['project_type'] = self.app.ci_reports[ 'project_type'] if 'project_type' in self.app.ci_reports else None params['test_result'] = read_results(self.app.temp_file_name) queue_id, token = self.create_report_queue(base_api_url, params) if queue_id and token: self.track_queue(queue_id, token, base_api_url) else: sys.exit(1) sys.exit(0)
def handle(self): self.app.check_configure_file_exists() print_header('Build project') client = docker.DockerClient(base_url='unix://var/run/docker.sock') thread = threading.Thread(target=listen_event, args=(client,)) thread.daemon = True thread.start() network = client.networks.create("FramgiaCI-" + str(time.time()), driver="bridge") build_commands = self.app.ci_reports['build'] containers = [] for build, details in build_commands.items(): self.start_service(client, network, details['services'], containers) main_container = self.start_container(client, network, details, main_container=True) try: main_container.restart() except Exception as e: print(e) print_header('Preparing..') framgia_ci_run_exist = False for command in details['prepare']: print("[+] Running: ", command) if 'framgia-ci run' == command: command += ' --local' framgia_ci_run_exist = True output = main_container.exec_run(command, workdir=self.workspace, tty=True, privileged=True, stream=True, socket=True) for line in output[1]: print(line.decode('utf-8'), end="\n") if framgia_ci_run_exist == False: print("[+] Running: ", 'framgia-ci run --local') output = main_container.exec_run('framgia-ci run --local', workdir=self.workspace, tty=True, privileged=True, stream=True, socket=True) for line in output[1]: print(line.decode('utf-8'), end="\n") containers.append(main_container.id) self.clean(client, network, containers)
def handle(self): print_header('Build and upload reports') base_api_url = self.app.ci_reports['url'] + '/api/reports' params = build_params() params['project_type'] = self.app.ci_reports[ 'project_type'] if 'project_type' in self.app.ci_reports else None params['test_result'] = read_results(self.app.temp_file_name) self.build_zip_file(params) print('[+] Bundle Size: %s bytes' % os.stat('bundle_reports.zip').st_size) bundle = zipfile.ZipFile('bundle_reports.zip', 'r') print('[+] Bundle Content:') for file in bundle.namelist(): print('[?]', file) bundle.close() result = call_api(base_api_url, True, params, [], [('report_file', 'bundle_reports.zip')]) print('[+] Finish upload with result: ', result)