From 795a5f9365a085d80d8903eeefe42fe7eb05d7f6 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 28 May 2025 11:21:24 +0200 Subject: [PATCH] Add steamwarci.yml --- build.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ steamwarci.yml | 8 ++++++ 2 files changed, 77 insertions(+) create mode 100644 build.py create mode 100644 steamwarci.yml diff --git a/build.py b/build.py new file mode 100644 index 0000000..210f393 --- /dev/null +++ b/build.py @@ -0,0 +1,69 @@ +import os +import shutil +import tempfile +import hashlib +import time +import zipfile + +# https://packs.steamwar.de/hello.txt + +current_dir = os.getcwd() + +def getVersions(): + directories = [name for name in os.listdir(current_dir) if os.path.isdir(os.path.join(current_dir, name)) and not name.startswith(".")] + packVersions = [] + for s in directories: + try: + num = int(s) + packVersions.append(num) + except ValueError: + pass + packVersions.sort() + return packVersions + +def buildPack(dir, version): + current_path = os.path.join(current_dir, str(version)) + copyFiles(current_path, dir) + + zip_folder(dir, current_path + ".zip") + # shutil.make_archive(current_path, "zip", dir) + current_path = current_path + ".zip" + + timestamp = time.mktime(time.strptime('1970-01-01 00:00:00', '%Y-%m-%d %H:%M:%S')) + os.utime(current_path, (timestamp, timestamp)) + + sha1 = sha1_of_file(current_path) + os.rename(current_path, os.path.join(current_dir, str(version) + "_" + sha1 + ".zip")) + +def copyFiles(src, dst): + for root, dirs, files in os.walk(src): + # Create corresponding path in destination + rel_path = os.path.relpath(root, src) + dest_path = os.path.join(dst, rel_path) + os.makedirs(dest_path, exist_ok=True) + + for file in files: + src_file = os.path.join(root, file) + dst_file = os.path.join(dest_path, file) + shutil.copy2(src_file, dst_file) # Overwrites if exists + +def zip_folder(folder_path, zip_file_path): + with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf: + for root, dirs, files in os.walk(folder_path): + for file in files: + abs_path = os.path.join(root, file) + rel_path = os.path.relpath(abs_path, folder_path) + zipf.write(abs_path, rel_path) + +def sha1_of_file(filepath): + sha1 = hashlib.sha1() + with open(filepath, 'rb') as f: + while chunk := f.read(8192): # read in 8KB chunks + sha1.update(chunk) + return sha1.hexdigest() + +if __name__ == "__main__": + versions=getVersions() + with tempfile.TemporaryDirectory() as tmpdirname: + for version in versions: + buildPack(tmpdirname, version) diff --git a/steamwarci.yml b/steamwarci.yml new file mode 100644 index 0000000..2679d7a --- /dev/null +++ b/steamwarci.yml @@ -0,0 +1,8 @@ +build: + - "python build.py" + +artifacts: {} + +release: + - "rm /var/www/packs/*" + - "mv *.zip /var/www/packs/"