def release(self): java_dir = self._get_java_dir() # Run this first to fail-fast if we're not in the java repo. print('\nAdapted from manual release procedure:\n{}\n'.format(SQUARE_RELEASE_WIKI)) with self._setup_pants_repo() as pants_git: release_name = self._run_release_script(java_dir) BinaryUtils.pause('You should check to see if BUILD.tools or pants.ini need updating now.') self._test_exemplar(pants_git, java_dir, release_name) self._print_closing_info(release_name)
def _test_exemplar(self, pants_git, java_dir, release_name): logger.info('\nTesting on exemplar:\n') env = os.environ.copy() env['SQPANTS_VERSION'] = release_name if 'PANTS_DEV' in env: env.pop('PANTS_DEV') env['PANTS_SRC'] = pants_git.cwd java_pants = Command('./pants', cwd=java_dir, env=env) success = True if not java_pants('binary', 'service/exemplar', pipe=False): BinaryUtils.pause('Building service/exemplar failed.') success = False elif not java_pants('test', 'service/exemplar', pipe=False): BinaryUtils.pause('Testing service/exemplar failed.') success = False return success
def _run_release_script(self, java_dir): """Invokes pants_release.sh.""" default_release_name=date.today().strftime(SQUARE_RELEASE_FORMAT) release_name = raw_input('Release name (default is {}): '.format(default_release_name)) release_name = release_name.strip() or default_release_name releaser = Command(BinaryUtils.squarepants_binary('pants_release.sh'), cwd=java_dir) if not releaser(*(self.release_script_args+[release_name]), pipe=False): raise RunError('{} failed.'.format(releaser.name)) return release_name
def _setup_pants_repo(self): """Cleans the pants repo and applies patches, yielding the Git command for the repo.""" git = PantsGit() if self.use_dirty: yield git raise StopIteration if not git.is_clean(): raise RunError('Pants source not clean: please stash or commit changes in {}.' .format(git.cwd)) self._assert_square_exists(git) pants_upstream = self._get_upstream_remote(git) git('checkout', 'master') git('fetch', pants_upstream) git('reset', '--hard', '{}/master'.format(pants_upstream)) git('clean', '-fdx') with git.apply_patches(PANTS_PATCHES, on_branch=SQUARE_RELEASE_BRANCH, commit=True): git('push', '-f', 'square') BinaryUtils.pause('Patches applied. It is recommended that you run either:"\n' ' full CI: {cwd}/build-support/bin/ci.sh\n' ' or just the unit tests: cd {cwd} ; ./pants test tests/python/pants_test:all\n' 'before continuing.'.format(cwd=git.cwd)) yield git
def run_pants(cls, options, args, patches): """Run PANTS_DEV=1 ./pants with the given arguments, after applying the given list of patches. """ git = PantsGit() with git.apply_patches(patches, commit=options.commit_patches): BinaryUtils.run_dev_pants(args)
def _get_java_dir(self): """Returns the current working directory if it is the java repo, otherwise raises an error.""" java_dir = BinaryUtils.find_java_dir() if not java_dir: raise RunError('Not in java repo.') return java_dir