Switch from zip to tar, fix prep

This commit is contained in:
2026-06-09 13:00:53 +03:00
parent e65989af40
commit c4e1133b15
6 changed files with 34 additions and 74 deletions

2
.gitattributes vendored
View File

@@ -1 +1 @@
LocalMods.zip filter=lfs diff=lfs merge=lfs -text
LocalMods.tar.gz filter=lfs diff=lfs merge=lfs -text

View File

@@ -28,13 +28,12 @@ jobs:
-e "ssh -i ~/.ssh/deploy_key" \
./ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:/opt/barotrauma/
- name: Unzip LocalMods on server
- name: Extract LocalMods on server
run: |
ssh -i ~/.ssh/deploy_key \
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \
"cd /opt/barotrauma && \
apt-get install -y -qq unzip 2>/dev/null; \
[ -f LocalMods.zip ] && unzip -o LocalMods.zip && rm -f LocalMods.zip && echo 'LocalMods extracted' || echo 'No LocalMods.zip'"
[ -f LocalMods.tar.gz ] && tar -xzf LocalMods.tar.gz && rm -f LocalMods.tar.gz && echo 'LocalMods extracted' || echo 'No LocalMods.tar.gz'"
- name: Restart server
run: |

3
LocalMods.tar.gz Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f17f7bab21a55065f6bd0a7df69caba7af69bd5dcff90508aad798c425ad5280
size 965179803

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2dd15e8e70921976b33e76c085c9062ac0280c939218c353f8ffa4511b5b5570
size 969188423

63
prep Normal file → Executable file
View File

@@ -1,16 +1,15 @@
#!/usr/bin/env python3
"""Prepare local mods, zip them, generate config, and commit."""
"""Prepare local mods, tar them, generate config, and commit."""
import os
import subprocess
import sys
BASE = os.path.dirname(os.path.abspath(__file__))
SCRIPTS = os.path.join(BASE, "scripts")
PREPARE_LOCAL = os.path.join(BASE, "prepare_local")
AUTOGEN = os.path.join(SCRIPTS, "autogen_config.py")
AUTOGEN = os.path.join(BASE, "scripts", "autogen_config.py")
LOCALMODS_DIR = os.path.join(BASE, "LocalMods")
ZIP_PATH = os.path.join(BASE, "LocalMods.zip")
TAR_PATH = os.path.join(BASE, "LocalMods.tar.gz")
def log_ok(msg):
@@ -22,65 +21,37 @@ def log_info(msg):
def log_err(msg):
print(f"\033[91m✗\033[0m {msg}", file=sys.stderr)
def run(cmd, cwd=None):
result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
if result.returncode != 0:
print(result.stdout)
print(result.stderr, file=sys.stderr)
sys.exit(result.returncode)
return result.stdout.strip()
def zip_localmods():
import zipfile
log_info(f"Zipping {LOCALMODS_DIR} → {ZIP_PATH}")
if os.path.exists(ZIP_PATH):
os.remove(ZIP_PATH)
count = 0
with zipfile.ZipFile(ZIP_PATH, "w", zipfile.ZIP_DEFLATED) as zf:
for root, dirs, files in os.walk(LOCALMODS_DIR):
for fn in files:
full = os.path.join(root, fn)
arcname = os.path.relpath(full, BASE)
zf.write(full, arcname)
count += 1
size = os.path.getsize(ZIP_PATH)
log_ok(f"Zipped {count} files ({size / 1024:.1f} KB)")
def main():
msg = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else "Update LocalMods"
print()
print("╔════════════════════════════════════╗")
print("║ Prep: mods → zip → commit ║")
print("║ Prep: mods → tar → commit ║")
print("╚════════════════════════════════════╝")
print()
# 1. Run prepare_local
log_info("Step 1: Copy mods from workshop...")
run([sys.executable, PREPARE_LOCAL])
log_info("Step 1/4: Copy mods from workshop...")
subprocess.run([sys.executable, PREPARE_LOCAL], check=True)
log_ok("LocalMods ready")
print()
# 2. Zip LocalMods
log_info("Step 2: Zipping LocalMods/...")
zip_localmods()
log_info("Step 2/4: Taring LocalMods/...")
if os.path.exists(TAR_PATH):
os.remove(TAR_PATH)
subprocess.run(["tar", "-czf", TAR_PATH, "-C", BASE, "LocalMods"], check=True)
size = os.path.getsize(TAR_PATH)
log_ok(f"Created {TAR_PATH} ({size / 1024:.1f} KB)")
print()
# 3. Run autogen_config
log_info("Step 3: Generating config_player.xml...")
run([sys.executable, AUTOGEN])
log_info("Step 3/4: Generating config_player.xml...")
subprocess.run([sys.executable, AUTOGEN], check=True)
log_ok("config_player.xml generated")
print()
# 4. Git add and commit (no push)
log_info("Step 4: Committing...")
run(["git", "add", "-A"], cwd=BASE)
run(["git", "commit", "-m", msg], cwd=BASE)
log_info("Step 4/4: Committing...")
subprocess.run(["git", "add", "-A"], cwd=BASE, check=True)
subprocess.run(["git", "commit", "-m", msg], cwd=BASE, check=True)
log_ok(f"Committed: {msg}")
print()

32
unpack Normal file → Executable file
View File

@@ -1,13 +1,12 @@
#!/usr/bin/env python3
"""Unpack LocalMods.zip into LocalMods/ and remove the archive."""
"""Unpack LocalMods.tar.gz into LocalMods/ and remove the archive."""
import os
import subprocess
import sys
import zipfile
BASE = os.path.dirname(os.path.abspath(__file__))
ZIP_PATH = os.path.join(BASE, "LocalMods.zip")
LOCALMODS_DIR = os.path.join(BASE, "LocalMods")
TAR_PATH = os.path.join(BASE, "LocalMods.tar.gz")
def log_ok(msg):
@@ -16,9 +15,6 @@ def log_ok(msg):
def log_info(msg):
print(f"• {msg}")
def log_warn(msg):
print(f"\033[93m⚠\033[0m {msg}")
def log_err(msg):
print(f"\033[91m✗\033[0m {msg}", file=sys.stderr)
@@ -26,23 +22,17 @@ def log_err(msg):
def main():
print()
if not os.path.isfile(ZIP_PATH):
log_err(f"Not found: {ZIP_PATH}")
if not os.path.isfile(TAR_PATH):
log_err(f"Not found: {TAR_PATH}")
sys.exit(1)
log_info(f"Unzipping: {ZIP_PATH}")
with zipfile.ZipFile(ZIP_PATH, "r") as zf:
zf.extractall(BASE)
log_info(f"Extracting: {TAR_PATH}")
subprocess.run(["tar", "-xzf", TAR_PATH, "-C", BASE], check=True)
size = os.path.getsize(ZIP_PATH)
file_count = 0
for root, dirs, files in os.walk(LOCALMODS_DIR):
file_count += len(files)
log_ok(f"Extracted {file_count} files to {LOCALMODS_DIR}/")
os.remove(ZIP_PATH)
log_ok(f"Removed: {ZIP_PATH} ({size / 1024:.1f} KB freed)")
size = os.path.getsize(TAR_PATH)
os.remove(TAR_PATH)
log_ok(f"Extracted to {os.path.join(BASE, 'LocalMods')}/")
log_ok(f"Removed archive ({size / 1024:.1f} KB freed)")
print()