Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set stability tolerance based on installing module #100

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ckan_meta_tester/ckan_meta_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
26 changes: 16 additions & 10 deletions ckan_meta_tester/dummy_game_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)

Expand All @@ -34,35 +37,38 @@ 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)
+ sum(f.stat().st_size for f in self.cache_path.rglob('*'))
) // 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')
Expand All @@ -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')
19 changes: 10 additions & 9 deletions tests/dummy_game_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
])
Loading