diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1590327..6cea486 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -88,6 +88,8 @@ jobs: name: "${{ format('ComicTagger-{0}', runner.os) }}" path: | dist/*.zip + dist/*.tar.gz + dist/*.dmg dist/*.AppImage - name: PyTest diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml index e95904c..aea9fc2 100644 --- a/.github/workflows/package.yaml +++ b/.github/workflows/package.yaml @@ -70,5 +70,7 @@ jobs: # upload the single application zip file for each OS and include the wheel built on linux files: | dist/*.zip + dist/*.tar.gz + dist/*.dmg dist/*${{ fromJSON('["never", ""]')[runner.os == 'Linux'] }}.whl dist/*.AppImage diff --git a/build-tools/dmgbuild.conf b/build-tools/dmgbuild.conf new file mode 100644 index 0000000..c4c4bc6 --- /dev/null +++ b/build-tools/dmgbuild.conf @@ -0,0 +1,24 @@ +import pathlib +import platform +from comictaggerlib.ctversion import __version__ + +app = "ComicTagger" +exe = app.casefold() +ver = platform.mac_ver() +os_version = f"osx-{ver[0]}-{ver[2]}" +app_name = f"{app}.app" +final_name = f"{app}-{__version__}-{os_version}" +path = pathlib.Path(f"dist/{app_name}") +zip_file = pathlib.Path(f"dist/{final_name}.zip") + +format = 'ULMO' +files = (str(path),) + +symlinks = {'Applications': '/Applications'} + +icon = pathlib.Path().cwd() / 'build-tools' / 'mac' / 'volume.icns' + +icon_locations = { + app_name: (100, 100), + 'Applications': (300, 100) +} diff --git a/build-tools/zip_artifacts.py b/build-tools/zip_artifacts.py index 1fa26c0..dd6acce 100644 --- a/build-tools/zip_artifacts.py +++ b/build-tools/zip_artifacts.py @@ -3,28 +3,13 @@ from __future__ import annotations import os import pathlib import platform +import runpy +import sys +import tarfile import zipfile from comictaggerlib.ctversion import __version__ -app = "ComicTagger" -exe = app.casefold() -if platform.system() == "Windows": - os_version = f"win-{platform.machine()}" - app_name = f"{exe}.exe" - final_name = f"{app}-{__version__}-{os_version}.exe" -elif platform.system() == "Darwin": - ver = platform.mac_ver() - os_version = f"osx-{ver[0]}-{ver[2]}" - app_name = f"{app}.app" - final_name = f"{app}-{__version__}-{os_version}.app" -else: - app_name = exe - final_name = f"ComicTagger-{__version__}-{platform.system()}" - -path = f"dist/{app_name}" -zip_file = pathlib.Path(f"dist/{final_name}.zip") - def addToZip(zf: zipfile.ZipFile, path: str, zippath: str) -> None: if os.path.isfile(path): @@ -34,14 +19,69 @@ def addToZip(zf: zipfile.ZipFile, path: str, zippath: str) -> None: zf.write(path, zippath) for nm in sorted(os.listdir(path)): addToZip(zf, os.path.join(path, nm), os.path.join(zippath, nm)) - # else: ignore -zip_file.unlink(missing_ok=True) -with zipfile.ZipFile(zip_file, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=8) as zf: - zippath = os.path.basename(path) - if not zippath: - zippath = os.path.basename(os.path.dirname(path)) - if zippath in ("", os.curdir, os.pardir): - zippath = "" - addToZip(zf, path, zippath) +def Zip(zip_file: pathlib.Path, path: pathlib.Path) -> None: + zip_file.unlink(missing_ok=True) + with zipfile.ZipFile(f"{zip_file}.zip", "w", compression=zipfile.ZIP_DEFLATED, compresslevel=8) as zf: + zippath = os.path.basename(path) + if not zippath: + zippath = os.path.basename(os.path.dirname(path)) + if zippath in ("", os.curdir, os.pardir): + zippath = "" + addToZip(zf, str(path), zippath) + + +def addToTar(tf: tarfile.TarFile, path: str, zippath: str) -> None: + if os.path.isfile(path): + tf.add(path, zippath) + elif os.path.isdir(path): + if zippath: + tf.add(path, zippath, recursive=False) + for nm in sorted(os.listdir(path)): + addToTar(tf, os.path.join(path, nm), os.path.join(zippath, nm)) + + +def Tar(tar_file: pathlib.Path, path: pathlib.Path) -> None: + tar_file.unlink(missing_ok=True) + with tarfile.TarFile(f"{tar_file}.tar.gz", "w:gz") as tf: # type: ignore[arg-type] + zippath = os.path.basename(path) + if not zippath: + zippath = os.path.basename(os.path.dirname(path)) + if zippath in ("", os.curdir, os.pardir): + zippath = "" + addToTar(tf, str(path), zippath) + + +if __name__ == "__main__": + app = "ComicTagger" + exe = app.casefold() + if platform.system() == "Windows": + os_version = f"win-{platform.machine()}" + app_name = f"{exe}.exe" + final_name = f"{app}-{__version__}-{os_version}.exe" + elif platform.system() == "Darwin": + ver = platform.mac_ver() + os_version = f"osx-{ver[0]}-{ver[2]}" + app_name = f"{app}.app" + final_name = f"{app}-{__version__}-{os_version}" + else: + app_name = exe + final_name = f"ComicTagger-{__version__}-{platform.system()}" + + path = pathlib.Path(f"dist/{app_name}") + zip_file = pathlib.Path(f"dist/{final_name}") + + if platform.system() == "Darwin": + sys.argv = [ + "zip_artifacts", + "-s", + str(pathlib.Path(__file__).parent / "dmgbuild.conf"), + f"{app} {__version__}", + f"{final_name}.dmg", + ] + runpy.run_module("dmgbuild", alter_sys=True) + elif platform.system() == "Windows": + Zip(zip_file, path) + else: + Tar(zip_file, path) diff --git a/setup.cfg b/setup.cfg index 9c1bfbe..c1ef328 100644 --- a/setup.cfg +++ b/setup.cfg @@ -234,6 +234,7 @@ depends = pypi-upload deps = pyinstaller>=5.6.2,!=6.0.0 + dmgbuild extras = all commands =