def run_hooks(phase, cwd, env): info("Running hooks for phase '%s'" % phase) full_env = os.environ.copy() full_env.update(env) for x in phase_actions[phase]: print "[%s]: %s" % (phase, x) support.check_call(x, shell = True, cwd = cwd, env = full_env)
def testBinaryRelease(self): support.check_call(['tar', 'xzf', test_repo_c]) make_releases_dir(src_feed = '../c-prog/c-prog.xml', auto_upload = True) call_with_output_suppressed(['./make-release', '-k', 'Testing', '--builders=host'], '\nP\n\n') feed = self.get_public_feed('HelloWorld-in-C.xml', 'c-prog.xml') assert len(feed.implementations) == 2 src_impl, = [x for x in feed.implementations.values() if x.arch == '*-src'] host_impl, = [x for x in feed.implementations.values() if x.arch != '*-src'] assert src_impl.main == None assert host_impl.main == 'hello' archives = os.listdir('archives') assert os.path.basename(src_impl.download_sources[0].url) in archives, src_impl.download_sources[0].url host_download = host_impl.download_sources[0] self.assertEqual('http://TESTING/releases/1.1/helloworld-in-c-linux-x86_64-1.1.tar.bz2', host_download.url) host_archive = os.path.basename(host_download.url) assert host_archive in archives support.check_call(['tar', 'xjf', os.path.join('archives', host_archive)]) c = subprocess.Popen(['0launch', os.path.join(host_download.extract, '0install', 'feed.xml')], stdout = subprocess.PIPE) output, _ = c.communicate() self.assertEquals("Hello from C! (version 1.1)\n", output)
def testUncommitted(self): support.check_call(['tar', 'xzf', test_repo_actions]) make_releases_dir() unused, stderr = call_with_output_suppressed(['./make-release', '-k', 'Testing'], None, expect_failure = True, stderr = subprocess.PIPE) assert "Uncommitted changes!" in stderr
def build_slave(src_feed, archive_file, archive_dir_public_url, target_feed): try: COMPILE = [os.environ['0COMPILE']] except KeyError: # (build slave has an old 0release) COMPILE = [ '0launch', '--not-before=1.2', 'http://0install.net/2006/interfaces/0compile.xml' ] feed = support.load_feed(src_feed) src_feed = os.path.abspath(src_feed) archive_file = os.path.abspath(archive_file) target_feed = os.path.abspath(target_feed) impl, = feed.implementations.values() tmpdir = tempfile.mkdtemp(prefix='0release-') try: os.chdir(tmpdir) depdir = os.path.join(tmpdir, 'dependencies') os.mkdir(depdir) support.unpack_tarball(archive_file) portable_rename(impl.download_sources[0].extract, os.path.join(depdir, impl.id)) config = ConfigParser.RawConfigParser() config.add_section('compile') config.set('compile', 'download-base-url', archive_dir_public_url) config.set('compile', 'version-modifier', '') config.set('compile', 'interface', src_feed) config.set('compile', 'selections', '') config.set('compile', 'metadir', '0install') stream = open(os.path.join(tmpdir, '0compile.properties'), 'w') try: config.write(stream) finally: stream.close() support.check_call(COMPILE + ['build'], cwd=tmpdir) support.check_call(COMPILE + ['publish', '--target-feed', target_feed], cwd=tmpdir) # TODO: run unit-tests feed = support.load_feed(target_feed) impl = support.get_singleton_impl(feed) archive_file = support.get_archive_basename(impl) shutil.move(archive_file, os.path.join(os.path.dirname(target_feed), archive_file)) except: print "\nLeaving temporary directory %s for inspection...\n" % tmpdir raise else: shutil.rmtree(tmpdir)
def testUncommitted(self): support.check_call(['tar', 'xzf', test_repo_actions]) make_releases_dir() unused, stderr = call_with_output_suppressed( ['./make-release', '-k', 'Testing'], None, expect_failure=True, stderr=subprocess.PIPE) assert "Uncommitted changes!" in stderr
def testSimple(self): support.check_call(['tar', 'xzf', test_repo]) make_releases_dir() call_with_output_suppressed(['./make-release', '-k', 'Testing'], '\nP\n\n') call_with_output_suppressed(['./make-release', '-k', 'Testing'], '\nP\nY\n\n') assert 'Prints "Hello World"' in file('0.1/changelog-0.1').read() assert 'Prints "Hello World"' not in file('0.2/changelog-0.2').read() new_v = file('../hello/hello.py').read() assert '0.2-post' in new_v, new_v
def build_slave(src_feed, archive_file, archive_dir_public_url, target_feed): try: COMPILE = [os.environ['0COMPILE']] except KeyError: # (build slave has an old 0release) COMPILE = ['0launch', '--not-before=0.30', 'http://0install.net/2006/interfaces/0compile.xml'] feed = support.load_feed(src_feed) src_feed = os.path.abspath(src_feed) archive_file = os.path.abspath(archive_file) target_feed = os.path.abspath(target_feed) impl, = feed.implementations.values() tmpdir = tempfile.mkdtemp(prefix = '0release-') try: os.chdir(tmpdir) depdir = os.path.join(tmpdir, 'dependencies') os.mkdir(depdir) support.unpack_tarball(archive_file) portable_rename(impl.download_sources[0].extract, os.path.join(depdir, impl.id)) config = ConfigParser.RawConfigParser() config.add_section('compile') config.set('compile', 'download-base-url', archive_dir_public_url) config.set('compile', 'version-modifier', '') config.set('compile', 'interface', src_feed) config.set('compile', 'selections', '') config.set('compile', 'metadir', '0install') stream = open(os.path.join(tmpdir, '0compile.properties'), 'w') try: config.write(stream) finally: stream.close() support.check_call(COMPILE + ['build'], cwd = tmpdir) support.check_call(COMPILE + ['publish', '--target-feed', target_feed], cwd = tmpdir) # TODO: run unit-tests feed = support.load_feed(target_feed) impl = support.get_singleton_impl(feed) archive_file = support.get_archive_basename(impl) shutil.move(archive_file, os.path.join(os.path.dirname(target_feed), archive_file)) except: print "\nLeaving temporary directory %s for inspection...\n" % tmpdir raise else: shutil.rmtree(tmpdir)
def testActions(self): support.check_call(['tar', 'xzf', test_repo_actions]) os.chdir('hello') support.check_call(['git', 'commit', '-a', '-m', 'Added release instructions'], stdout = subprocess.PIPE) os.chdir('..') make_releases_dir() assert "version = '0.2'\n" not in file('../hello/hello.py').read() child = subprocess.Popen(['./make-release', '-k', 'Testing'], stdin = subprocess.PIPE, stdout = subprocess.PIPE) unused, unused = child.communicate('\nP\n\n') assert child.returncode == 0 assert "version = '0.2'\n" in file('../hello/hello.py').read()
def build_binaries(self): if not self.targets: return print "Source package, so generating binaries..." archive_file = support.get_archive_basename(self.src_impl) for target in self.targets: start = self.get('builder-' + target, 'start', None) command = self.config.get('builder-' + target, 'build') stop = self.get('builder-' + target, 'stop', None) binary_feed = 'binary-' + target + '.xml' if os.path.exists(binary_feed): print "Feed %s already exists; not rebuilding" % binary_feed else: print "\nBuilding binary with builder '%s' ...\n" % target if start: support.show_and_run(start, []) try: args = [ os.path.basename(self.src_feed_name), archive_file, self.archive_dir_public_url, binary_feed + '.new' ] if not command: assert target == 'host', 'Missing build command' support.check_call( [sys.executable, sys.argv[0], '--build-slave'] + args) else: support.show_and_run(command, args) finally: if stop: support.show_and_run(stop, []) bin_feed = support.load_feed(binary_feed + '.new') bin_impl = support.get_singleton_impl(bin_feed) bin_archive_file = support.get_archive_basename(bin_impl) bin_size = bin_impl.download_sources[0].size assert os.path.exists( bin_archive_file ), "Compiled binary '%s' not found!" % os.path.abspath( bin_archive_file) assert os.path.getsize( bin_archive_file ) == bin_size, "Compiled binary '%s' has wrong size!" % os.path.abspath( bin_archive_file) portable_rename(binary_feed + '.new', binary_feed)
def testActions(self): support.check_call(['tar', 'xzf', test_repo_actions]) os.chdir('hello') support.check_call( ['git', 'commit', '-a', '-m', 'Added release instructions'], stdout=subprocess.PIPE) os.chdir('..') make_releases_dir() assert "version = '0.2'\n" not in file('../hello/hello.py').read() child = subprocess.Popen(['./make-release', '-k', 'Testing'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) unused, unused = child.communicate('\nP\n\n') assert child.returncode == 0 assert "version = '0.2'\n" in file('../hello/hello.py').read()
def setUp(self): self.tmp = tempfile.mkdtemp(prefix='0release-') os.chdir(self.tmp) support.check_call(['tar', 'xzf', test_gpg]) os.mkdir('releases') os.environ['GNUPGHOME'] = self.tmp + '/gpg' os.chmod(os.environ['GNUPGHOME'], 0700) config_dir = os.path.join(self.tmp, 'config') injector_config = os.path.join(config_dir, '0install.net', 'injector') os.makedirs(injector_config) s = open(os.path.join(injector_config, 'global'), 'w') s.write(test_config) s.close() if 'ZEROINSTALL_PORTABLE_BASE' in os.environ: del os.environ['ZEROINSTALL_PORTABLE_BASE'] os.environ['XDG_CONFIG_HOME'] = config_dir imp.reload(basedir) assert basedir.xdg_config_home == config_dir
def setUp(self): self.tmp = tempfile.mkdtemp(prefix = '0release-') os.chdir(self.tmp) support.check_call(['tar', 'xzf', test_gpg]) os.mkdir('releases') os.environ['GNUPGHOME'] = self.tmp + '/gpg' os.chmod(os.environ['GNUPGHOME'], 0700) config_dir = os.path.join(self.tmp, 'config') injector_config = os.path.join(config_dir, '0install.net', 'injector') os.makedirs(injector_config) s = open(os.path.join(injector_config, 'global'), 'w') s.write(test_config) s.close() if 'ZEROINSTALL_PORTABLE_BASE' in os.environ: del os.environ['ZEROINSTALL_PORTABLE_BASE'] os.environ['XDG_CONFIG_HOME'] = config_dir imp.reload(basedir) assert basedir.xdg_config_home == config_dir
def testBinaryRelease(self): support.check_call(['tar', 'xzf', test_repo_c]) make_releases_dir(src_feed='../c-prog/c-prog.xml', auto_upload=True) call_with_output_suppressed( ['./make-release', '-k', 'Testing', '--builders=host'], '\nP\n\n') feed = self.get_public_feed('HelloWorld-in-C.xml', 'c-prog.xml') assert len(feed.implementations) == 2 src_impl, = [ x for x in feed.implementations.values() if x.arch == '*-src' ] host_impl, = [ x for x in feed.implementations.values() if x.arch != '*-src' ] assert src_impl.main == None assert host_impl.main == 'hello' archives = os.listdir('archives') assert os.path.basename(src_impl.download_sources[0].url ) in archives, src_impl.download_sources[0].url host_download = host_impl.download_sources[0] self.assertEqual( 'http://TESTING/releases/1.1/helloworld-in-c-linux-x86_64-1.1.tar.bz2', host_download.url) host_archive = os.path.basename(host_download.url) assert host_archive in archives support.check_call( ['tar', 'xjf', os.path.join('archives', host_archive)]) c = subprocess.Popen([ '0launch', os.path.join(host_download.extract, '0install', 'feed.xml') ], stdout=subprocess.PIPE) output, _ = c.communicate() self.assertEquals("Hello from C! (version 1.1)\n", output)
def build_binaries(self): if not self.targets: return print "Source package, so generating binaries..." archive_file = support.get_archive_basename(self.src_impl) for target in self.targets: start = self.get('builder-' + target, 'start', None) command = self.config.get('builder-' + target, 'build') stop = self.get('builder-' + target, 'stop', None) binary_feed = 'binary-' + target + '.xml' if os.path.exists(binary_feed): print "Feed %s already exists; not rebuilding" % binary_feed else: print "\nBuilding binary with builder '%s' ...\n" % target if start: support.show_and_run(start, []) try: args = [os.path.basename(self.src_feed_name), archive_file, self.archive_dir_public_url, binary_feed + '.new'] if not command: assert target == 'host', 'Missing build command' support.check_call([sys.executable, sys.argv[0], '--build-slave'] + args) else: support.show_and_run(command, args) finally: if stop: support.show_and_run(stop, []) bin_feed = support.load_feed(binary_feed + '.new') bin_impl = support.get_singleton_impl(bin_feed) bin_archive_file = support.get_archive_basename(bin_impl) bin_size = bin_impl.download_sources[0].size assert os.path.exists(bin_archive_file), "Compiled binary '%s' not found!" % os.path.abspath(bin_archive_file) assert os.path.getsize(bin_archive_file) == bin_size, "Compiled binary '%s' has wrong size!" % os.path.abspath(bin_archive_file) portable_rename(binary_feed + '.new', binary_feed)
if status.created_archive and os.path.isfile(archive_file): print "Archive already created" else: support.backup_if_exists(archive_file) scm.export(export_prefix, archive_file, status.head_at_release) has_submodules = scm.has_submodules() if phase_actions['generate-archive'] or has_submodules: try: support.unpack_tarball(archive_file) if has_submodules: scm.export_submodules(archive_name) run_hooks('generate-archive', cwd = archive_name, env = {'RELEASE_VERSION': status.release_version}) info("Regenerating archive (may have been modified by generate-archive hooks...") support.check_call(['tar', 'cjf', archive_file, archive_name]) except SafeException: scm.reset_hard(scm.get_current_branch()) fail_candidate() raise status.created_archive = 'true' status.save() if need_set_snapshot: set_to_snapshot(status.release_version + '-post') # Revert back to the original revision, so that any fixes the user makes # will get applied before the tag scm.reset_hard(scm.get_current_branch()) #backup_if_exists(archive_name)