'dependencies', 'install', 'test', 'testresults' ] build_runner.config['build_plugins'] = { 'test': 'run_tests', 'dependencies': 'fetch_pip_dependencies' } else: # Store plugins build_runner.config['build_plugins'] = dict( [(k.split('[')[0], k.split('[')[1][:-1]) \ for k in build_runner.config.keys() if len(k.split('[')) == 2]) # Maybe we need cleaned step names. Remove the plugin names. build_runner.config['build_names'] = [k.split('[')[0] for k in build_runner.config.keys()] # Check if we have commands/input for every step. if not set(build_runner.config['build']).issubset( set(build_runner.config['build_names'])): raise InvalidConfigException( 'some build steps are not configured') # OK, we're done. return True, 0 # Register the plugin. registry.add_step('fetch_config', fetch_config)
# We need this because the production environment runs python2.5 from __future__ import with_statement from fabric.api import run from journeyman.buildrunner.registry import registry class InvalidRepositoryException(Exception): pass def fetch_repository(build_runner, **kwargs): # FIXME: support multiple vcs types if not build_runner.build.project.repository.startswith('git+'): raise InvalidRepositoryException( 'Invalid repository: %s' % build_runner.build.project.repository) # Generate the repo path. build_runner.build_src = '%s/src' % build_runner.build_ve_path # Execute the clone command. output = run('git clone --depth=1 %s %s' % ( ''.join(build_runner.build.project.repository.split('+')[1:]), build_runner.build_src)) # Pass the return code of the vcs. return output.return_code == 0, output.return_code # Register the plugin registry.add_step('fetch_repository', fetch_repository)
from journeyman.buildrunner.registry import registry def fetch_xunit_results(build_runner, **kwargs): with cd(build_runner.build_src): # Fetch the current directory. pwd = run('pwd') # Get all result xml files. files = kwargs.get('lines', []) for test_file in files: # Test if the result file exists. if exists(test_file): # Create a temp. file to download the xml local_test_file = tempfile.NamedTemporaryFile() # Loading... get('%s/%s' % (pwd, test_file), local_test_file.name) # Store the plain xml data to database. build_runner.build.buildresult_set.create( name=test_file, body=''.join(local_test_file.readlines()) ) # Close the temp file. local_test_file.close() # Return. return True, 0 # Register the plugin registry.add_step('fetch_xunit_results', fetch_xunit_results)
# We need this because the production environment runs python2.5 from __future__ import with_statement import tempfile from fabric.api import run from journeyman.buildrunner.registry import registry def prepare_virtualenv(build_runner, **kwargs): # Prepare some paths. build_runner.build_ve_name = 'journeyman.%s' % tempfile.mktemp(dir='') build_runner.build_ve_path = 'builds/%s' % build_runner.build_ve_name # Create the virtual env for testing. output = run('virtualenv %s' % build_runner.build_ve_path) # Return the exit code of virtualenv. return output.return_code == 0, output.return_code # Register the plugin registry.add_step('prepare_virtualenv', prepare_virtualenv)
# We need this because the production environment runs python2.5 from __future__ import with_statement from fabric.api import run, cd, prefix from journeyman.buildrunner.registry import registry def run_commands(build_runner, **kwargs): # Move to the repo directory with cd(build_runner.build_src): # Every command should get executed within the virtualenv. with prefix('source ../bin/activate'): for command in kwargs.get('lines', []): # Execute every command. output = run(command) # We assume that everything works, if not. Abort the step if output.return_code != 0: return False, output.return_code # Done. return True, 0 # Register the plugin registry.add_step('run_commands', run_commands)
# We need this because the production environment runs python2.5 from __future__ import with_statement from fabric.api import run, cd from journeyman.buildrunner.registry import registry def fetch_repository_commit_id(build_runner, **kwargs): # FIXME: support multiple vcs types if not build_runner.build.project.repository.startswith('git+'): raise InvalidRepositoryException( 'Invalid repository: %s' % build_runner.build.project.repository) # Move to the repo directory with cd(build_runner.build_src): # get the revision id and store in build runner instance output = run('git log --pretty="format:%H" -n 1') build_runner.repo_head_id = output output = run('git log --pretty="format:%h" -n 1') build_runner.repo_head_short_id = output # Pass the exit code of vcs. return output.return_code == 0, output.return_code # Register the plugin registry.add_step('fetch_repository_commit_id', fetch_repository_commit_id)
# We need this because the production environment runs python2.5 from __future__ import with_statement import tempfile from fabric.api import run from journeyman.buildrunner.registry import registry def teardown_virtualenv(build_runner, **kwargs): # Create the virtual env for testing. output = run('rm -rf %s' % build_runner.build_ve_path) # Return the exit code of virtualenv. return output.return_code == 0, output.return_code # Register the plugin registry.add_step('teardown_virtualenv', teardown_virtualenv)
# We need this because the production environment runs python2.5 from __future__ import with_statement from fabric.api import run, cd from journeyman.buildrunner.registry import registry def fetch_pip_dependencies(build_runner, **kwargs): # Move into the source/repo directory with cd(build_runner.build_src): # Get files from config files = kwargs.get('lines', []) for req_file in files: # do the pip install dance for every requirements file output = run('pip -E .. install -r %s' % req_file) # if anything else than 0 returned, abort. if output.return_code != 0: return False, output.return_code # Done! return True, 0 # Register the plugin registry.add_step('fetch_pip_dependencies', fetch_pip_dependencies)
# We need this because the production environment runs python2.5 from __future__ import with_statement from fabric.api import run, cd, prefix from journeyman.buildrunner.registry import registry def run_tests(build_runner, **kwargs): # Move to the repo directory with cd(build_runner.build_src): # Execute every command withing the virtualenv. with prefix("source ../bin/activate"): for command in kwargs.get("lines", []): # Execute the command. We ignore the results. output = run(command) # Its ok if errors occur. return True, 0 # Register the plugin registry.add_step("run_tests", run_tests)