Fix migration crashes.
continuous-integration/drone/push Build is failing Details

pull/8/head
Inex Code 2022-01-11 08:52:15 +03:00
parent 650032bdab
commit 07cf926e79
2 changed files with 37 additions and 21 deletions

View File

@ -20,4 +20,9 @@ def run_migrations():
for migration in migrations:
if migration.get_migration_name() not in skipped_migrations:
if migration.is_migration_needed():
try:
migration.migrate()
except Exception as e:
print(f"Error while migrating {migration.get_migration_name()}")
print(e)
print("Skipping this migration")

View File

@ -17,13 +17,20 @@ class FixNixosConfigBranch(Migration):
def is_migration_needed(self):
"""Check the current branch of /etc/nixos and return True if it is rolling-testing"""
current_working_directory = os.getcwd()
try:
os.chdir("/etc/nixos")
nixos_config_branch = subprocess.check_output(
["git", "rev-parse", "--abbrev-ref", "HEAD"], start_new_session=True
)
os.chdir(current_working_directory)
if nixos_config_branch.decode("utf-8").strip() == "rolling-testing":
return True
else:
return False
except subprocess.CalledProcessError:
os.chdir(current_working_directory)
return False
def migrate(self):
"""Affected server pulled the config with the --single-branch flag.
@ -32,6 +39,7 @@ class FixNixosConfigBranch(Migration):
"""
print("Fixing Nixos config branch")
current_working_directory = os.getcwd()
try:
os.chdir("/etc/nixos")
subprocess.check_output(
@ -45,6 +53,9 @@ class FixNixosConfigBranch(Migration):
subprocess.check_output(["git", "fetch", "--all"])
subprocess.check_output(["git", "pull"])
subprocess.check_output(["git", "checkout", "master"])
os.chdir(current_working_directory)
print("Done")
except subprocess.CalledProcessError:
os.chdir(current_working_directory)
print("Error")