From 2cf3c341f651d2eb4a820a7168a5724ea8912758 Mon Sep 17 00:00:00 2001 From: Reshetnikov_AS Date: Fri, 1 Mar 2024 00:23:02 +0400 Subject: [PATCH] check status from _update.log use xterm --- .github/workflows/ci-test-run.yml | 2 +- _AutoinstallCreator/test_update.py | 65 ++++++++++++++++-------------- update.sh | 6 +-- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci-test-run.yml b/.github/workflows/ci-test-run.yml index bf65b500..58d300e5 100644 --- a/.github/workflows/ci-test-run.yml +++ b/.github/workflows/ci-test-run.yml @@ -31,7 +31,7 @@ jobs: if: matrix.artifact == 'ubuntu' run: | apt update - apt install -y busybox dos2unix libarchive-tools python3 git + apt install -y busybox dos2unix libarchive-tools python3 git xterm git config --global --add safe.directory '*' - name: Install Alpine packages diff --git a/_AutoinstallCreator/test_update.py b/_AutoinstallCreator/test_update.py index 392c60f5..6ddb22dc 100644 --- a/_AutoinstallCreator/test_update.py +++ b/_AutoinstallCreator/test_update.py @@ -7,11 +7,13 @@ _self_path: str = os.path.dirname(os.path.realpath(__file__)) +_self_body_path = os.path.join(os.path.dirname(_self_path), 'body.md') + _self_tmp_path: str = os.path.join(_self_path, '.tmp') _root_path: str = os.path.dirname(_self_path) _tools_path: str = os.path.join(_root_path, '.tools') -busybox_exe_path_arg: list[str] = ['x-terminal-emulator', '-e'] +busybox_exe_path_arg: list[str] = ['xterm', '-e'] update_script_name: str = 'update.sh' package_name = 'AutoinstallCreator.sh' if sys.platform.startswith('win'): @@ -25,49 +27,55 @@ from _AutoinstallCreator import io_tools -def get_version_from_stdout(b_stdout: bytes) -> str: - for b_line in b_stdout.splitlines(): - if b_line.startswith(b'version created:'): - version_line = b_line.decode().strip() - prefix, _, raw_version = version_line.partition(':') - return raw_version.strip() - - def update_completed(update_log_path: str, version_str: str) -> bool: update_log = io_tools.read_text(update_log_path) return update_log.endswith(f'\nUpdate complete: {version_str}\n') +def version_is_up_to_date(update_log_path: str, version_str: str) -> bool: + update_log = io_tools.read_text(update_log_path).strip() + return update_log == f'Version is up to date: {version_str}' + + class TestUpdate(unittest.TestCase): @classmethod def setUpClass(cls) -> None: pathlib.Path(os.path.join(_self_path, 'AutoinstallCreator.sh')).unlink(missing_ok=True) pathlib.Path(os.path.join(_self_path, 'AutoinstallCreator.sh.bat')).unlink(missing_ok=True) + pathlib.Path(_self_body_path).unlink(missing_ok=True) - result = subprocess.run(busybox_exe_path_arg + [os.path.join(_self_path, 'release.sh')], - check=True, stdout=subprocess.PIPE) - cls.version_str = get_version_from_stdout(result.stdout) + subprocess.run(busybox_exe_path_arg + [os.path.join(_self_path, 'release.sh')], + check=True) + cls.version_str = io_tools.read_text(_self_body_path).strip('\r\n') + if not cls.version_str: + raise ValueError('cannot get version from release.sh') def setUp(self): self.test_old_version = 'AutoinstallCreator.11.test_old_version' self.assertTrue(self.version_str.startswith('AutoinstallCreator.')) self.assertTrue(io_tools.try_create_or_clean_dir(_self_tmp_path)) self.package_filepath = os.path.join(_self_tmp_path, package_name) + self.old_update_log_filepath = os.path.join(_self_tmp_path, self.test_old_version, '_update.log') + self.update_log_filepath = os.path.join(_self_tmp_path, self.version_str, '_update.log') shutil.copy2(os.path.join(_self_path, package_name), self.package_filepath) + pathlib.Path(self.old_update_log_filepath).unlink(missing_ok=True) + pathlib.Path(self.update_log_filepath).unlink(missing_ok=True) + + def test_version_up_to_date(self): subprocess.run(busybox_exe_path_arg + [self.package_filepath], cwd=_self_tmp_path, check=True) - result = subprocess.run(busybox_exe_path_arg + [os.path.join(_self_tmp_path, self.version_str, 'update.sh')], - env={ - 'MOCK_AUTOINSTALLCREATOR_VERSION_BODY': self.version_str, - 'MOCK_AUTOINSTALLCREATOR_PACKAGE_FILEPATH': self.package_filepath - }, - check=True, stdout=subprocess.PIPE) - self.assertTrue(result.stdout.endswith(b'\nVersion is up to date\n')) + subprocess.run(busybox_exe_path_arg + [os.path.join(_self_tmp_path, self.version_str, 'update.sh')], + env={ + 'MOCK_AUTOINSTALLCREATOR_VERSION_BODY': self.version_str, + 'MOCK_AUTOINSTALLCREATOR_PACKAGE_FILEPATH': self.package_filepath + }, + check=True) + self.assertTrue(version_is_up_to_date(self.update_log_filepath, self.version_str)) def test_update_to_new_version(self): subprocess.run(busybox_exe_path_arg + [self.package_filepath, '--target', self.test_old_version], @@ -76,18 +84,15 @@ def test_update_to_new_version(self): io_tools.write_text(os.path.join(_self_tmp_path, self.test_old_version, '_AutoinstallCreator', 'version.txt'), self.test_old_version) - result = subprocess.run([os.path.join(_self_tmp_path, self.test_old_version, update_script_name)], - env={ - **os.environ, - 'MOCK_AUTOINSTALLCREATOR_VERSION_BODY': self.version_str, - 'MOCK_AUTOINSTALLCREATOR_PACKAGE_FILEPATH': self.package_filepath - }, - check=True, stdout=subprocess.PIPE) - - self.assertIn(f'\nFound new version: {self.test_old_version} -> {self.version_str}\n'.encode(), result.stdout) + subprocess.run([os.path.join(_self_tmp_path, self.test_old_version, update_script_name)], + env={ + **os.environ, + 'MOCK_AUTOINSTALLCREATOR_VERSION_BODY': self.version_str, + 'MOCK_AUTOINSTALLCREATOR_PACKAGE_FILEPATH': self.package_filepath + }, + check=True) - update_log_filepath = os.path.join(_self_tmp_path, self.test_old_version, '_update.log') - self.assertTrue(io_tools.wait_for(lambda: update_completed(update_log_filepath, self.version_str), + self.assertTrue(io_tools.wait_for(lambda: update_completed(self.old_update_log_filepath, self.version_str), err_message='Update failed', timeout=10, retry_timeout=0.5, diff --git a/update.sh b/update.sh index 0a8c23c7..eee33d6d 100755 --- a/update.sh +++ b/update.sh @@ -88,7 +88,7 @@ version_hash=$(echo "$version_body" | "$grep" --only-matching "(?<=$self_name\.$ } if [[ $self_version_count -eq $version_count ]] && [[ $self_version_hash == $version_hash ]]; then - echo "Version is up to date" + echo "Version is up to date: $version_body" > $dp0/_update.log 2>&1 exit 0 fi @@ -116,9 +116,9 @@ if [[ -z $MOCK_AUTOINSTALLCREATOR_PACKAGE_FILEPATH ]]; then fi echo "Extracting to: $dp0/_$self_name/$version_body" -"$package_filepath" --target "$dp0/_$self_name/tmp_$version_body" +"$package_filepath" --target "$dp0/_$self_name/tmp_$version_body" > $dp0/_update.log 2>&1 echo "Running extracted 'update.sh'" -"$dp0/_$self_name/tmp_$version_body/update.sh" "$dp0" >& $dp0/_update.log +"$dp0/_$self_name/tmp_$version_body/update.sh" "$dp0" >> $dp0/_update.log 2>&1