diff --git a/ckan_meta_tester/ckan_meta_tester.py b/ckan_meta_tester/ckan_meta_tester.py index 5d02c1d..64c7497 100644 --- a/ckan_meta_tester/ckan_meta_tester.py +++ b/ckan_meta_tester/ckan_meta_tester.py @@ -202,9 +202,10 @@ def install_ckan(self, file: Path, orig_file: Path, pr_body: Optional[str], meta print(f'::error file={orig_file}::{file} is not compatible with any game versions!', flush=True) return False - with DummyGameInstance( - Path('/game-instance'), self.CKAN_PATH, self.TINY_REPO, - versions[-1], versions[:-1], self.CACHE_PATH, self.game): + with DummyGameInstance(Path('/game-instance'), self.CKAN_PATH, + self.TINY_REPO, versions[-1], versions[:-1], + self.CACHE_PATH, self.game, + getattr(ckan, 'release_status', None)): return self.run_for_file( orig_file, @@ -223,7 +224,7 @@ def install_identifiers(self, identifiers: List[str], pr_body: Optional[str]) -> with DummyGameInstance( Path('/game-instance'), self.CKAN_PATH, self.TINY_REPO, - versions[-1], versions[:-1], self.CACHE_PATH, self.game): + versions[-1], versions[:-1], self.CACHE_PATH, self.game, None): return self.run_for_file( None, diff --git a/ckan_meta_tester/dummy_game_instance.py b/ckan_meta_tester/dummy_game_instance.py index 0ba7f6a..19255b2 100644 --- a/ckan_meta_tester/dummy_game_instance.py +++ b/ckan_meta_tester/dummy_game_instance.py @@ -3,7 +3,7 @@ from shutil import rmtree, copy, disk_usage from subprocess import run from types import TracebackType -from typing import Type, List +from typing import Type, List, Optional from .game import Game from .game_version import GameVersion @@ -12,7 +12,9 @@ class DummyGameInstance: SAVED_REGISTRY=Path('/tmp/registry.json') - def __init__(self, where: Path, ckan_exe: Path, addl_repo: Path, main_ver: GameVersion, other_versions: List[GameVersion], cache_path: Path, game: Game) -> None: + def __init__(self, where: Path, ckan_exe: Path, addl_repo: Path, + main_ver: GameVersion, other_versions: List[GameVersion], + cache_path: Path, game: Game, stability_tolerance: Optional[str]) -> None: self.where = where self.registry_path = self.where.joinpath('CKAN').joinpath('registry.json') self.ckan_exe = ckan_exe @@ -21,6 +23,7 @@ def __init__(self, where: Path, ckan_exe: Path, addl_repo: Path, main_ver: GameV self.other_versions = other_versions self.cache_path = cache_path self.game = game + self.stability_tolerance = stability_tolerance # Hide ckan.exe output unless debugging is enabled self.capture = not logging.getLogger().isEnabledFor(logging.DEBUG) @@ -34,15 +37,15 @@ def __enter__(self) -> 'DummyGameInstance': '--set-default', '--headless', 'dummy', self.where, str(self.main_ver), *self.game.dlc_cmdline_flags(self.main_ver)], - capture_output=self.capture) + capture_output=self.capture, check=False) for ver in self.other_versions: logging.debug('Setting version %s compatible', ver) run(['mono', self.ckan_exe, 'compat', 'add', str(ver)], - capture_output=self.capture) + capture_output=self.capture, check=False) self.where.joinpath('CKAN').joinpath('downloads').symlink_to(self.cache_path.absolute()) logging.debug('Setting cache location to %s', self.cache_path.absolute()) run(['mono', self.ckan_exe, 'cache', 'set', self.cache_path.absolute(), '--headless'], - capture_output=self.capture) + capture_output=self.capture, check=False) # Free space plus existing cache minus 1 GB padding cache_mbytes = max(5000, (((disk_usage(self.cache_path)[2] if self.cache_path.is_dir() else 0) @@ -50,19 +53,22 @@ def __enter__(self) -> 'DummyGameInstance': ) // 1024 // 1024 - 1024)) logging.debug('Setting cache limit to %s', cache_mbytes) run(['mono', self.ckan_exe, 'cache', 'setlimit', str(cache_mbytes)], - capture_output=self.capture) + capture_output=self.capture, check=False) logging.debug('Adding repo %s', self.addl_repo.as_uri()) run(['mono', self.ckan_exe, 'repo', 'add', 'local', self.addl_repo.as_uri()], - capture_output=self.capture) + capture_output=self.capture, check=False) run(['mono', self.ckan_exe, 'repo', 'priority', 'local', '0'], - capture_output=self.capture) + capture_output=self.capture, check=False) + if self.stability_tolerance in ('testing', 'development'): + run(['mono', self.ckan_exe, 'stability', 'set', self.stability_tolerance], + capture_output=self.capture, check=False) if self.SAVED_REGISTRY.exists(): logging.debug('Restoring saved registry from %s', self.SAVED_REGISTRY) copy(self.SAVED_REGISTRY, self.registry_path) else: logging.debug('Updating registry') run(['mono', self.ckan_exe, 'update'], - capture_output=self.capture) + capture_output=self.capture, check=False) copy(self.registry_path, self.SAVED_REGISTRY) logging.debug('Saving registry to %s', self.SAVED_REGISTRY) logging.debug('Dummy instance is ready') @@ -72,7 +78,7 @@ def __exit__(self, exc_type: Type[BaseException], exc_value: BaseException, traceback: TracebackType) -> None: logging.debug('Removing instance from CKAN instance list') run(['mono', self.ckan_exe, 'instance', 'forget', 'dummy'], - capture_output=self.capture) + capture_output=self.capture, check=False) logging.debug('Deleting instance contents') rmtree(self.where) logging.info('Dummy game instance deleted') diff --git a/tests/dummy_game_instance.py b/tests/dummy_game_instance.py index c944379..e3da523 100644 --- a/tests/dummy_game_instance.py +++ b/tests/dummy_game_instance.py @@ -35,7 +35,8 @@ def test_dummy_game_instance_calls(self, GameVersion('1.8.1'), [GameVersion('1.8.0')], Path('/cache'), - Game.from_id('KSP')): + Game.from_id('KSP'), + None): pass @@ -57,21 +58,21 @@ def test_dummy_game_instance_calls(self, '--set-default', '--headless', 'dummy', PosixPath('/game-instance'), '1.8.1', '--MakingHistory', '1.1.0', '--BreakingGround', '1.0.0'], - capture_output=True), + capture_output=True, check=False), call(['mono', PosixPath('/ckan.exe'), 'compat', 'add', '1.8.0'], - capture_output=True), + capture_output=True, check=False), call(['mono', PosixPath('/ckan.exe'), 'cache', 'set', PosixPath('/cache'), '--headless'], - capture_output=True), + capture_output=True, check=False), call(['mono', PosixPath('/ckan.exe'), 'cache', 'setlimit', '5000'], - capture_output=True), + capture_output=True, check=False), call(['mono', PosixPath('/ckan.exe'), 'repo', 'add', 'local', 'file:///repo/metadata.tar.gz'], - capture_output=True), + capture_output=True, check=False), call(['mono', PosixPath('/ckan.exe'), 'repo', 'priority', 'local', '0'], - capture_output=True), + capture_output=True, check=False), call(['mono', PosixPath('/ckan.exe'), 'update'], - capture_output=True), + capture_output=True, check=False), call(['mono', PosixPath('/ckan.exe'), 'instance', 'forget', 'dummy'], - capture_output=True) + capture_output=True, check=False) ])