From 63b172563b4215f5c6c74943ab8504da9fc57cc8 Mon Sep 17 00:00:00 2001 From: u8slvn Date: Thu, 29 Aug 2024 09:59:17 +0200 Subject: [PATCH] build: refactor upx install --- .github/workflows/release.yaml | 11 ++++++++--- scripts/build.py | 35 +++------------------------------- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 152ab54..3b81aa0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,7 +5,7 @@ on: - "v*.*.*" jobs: release-windows: - name: build-${{ matrix.platform }} + name: build-windows-${{ matrix.platform }} runs-on: windows-2022 strategy: fail-fast: false @@ -22,6 +22,11 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install UPX + uses: crazy-max/ghaction-upx@v3 + with: + install-only: true + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: @@ -34,7 +39,7 @@ jobs: os: windows - name: Build release - run: poetry run python scripts/build.py --os ${{ matrix.platform }} + run: poetry run python scripts/build.py --os windows - name: Rename artifact run: ./scripts/rename-release-file.sh windows @@ -53,7 +58,7 @@ jobs: # files: dist/doggo-*.exe release-macos: - name: build-${{ matrix.platform }} + name: build-macos-${{ matrix.platform }} runs-on: ${{ matrix.image }} strategy: fail-fast: false diff --git a/scripts/build.py b/scripts/build.py index ccc9f3a..89b3f92 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -3,8 +3,6 @@ import argparse import logging -import urllib.request -import zipfile from importlib import metadata from pathlib import Path @@ -19,7 +17,6 @@ APP_NAME = "Doggo" PACKAGE_NAME = "doggo" ASSETS_FOLDER = "assets" -UPX_VERSION = "4.0.2" # ------ Versionfile info ------ COMPANY_NAME = "u8slvn" @@ -36,27 +33,8 @@ ASSETS_PATH = PACKAGE_PATH.joinpath(ASSETS_FOLDER) -def install_upx(version: str, os: str | None = None) -> Path: - logger.info("Install UPX.") - upx_filename = f"upx-{version}" - upx_filename = f"{upx_filename}-{os}" if os is not None else upx_filename - upx_zipfile = f"{upx_filename}.zip" - upx_url = f"https://github.com/upx/upx/releases/download/v{version}/{upx_zipfile}" - upx_path = BUILD_PATH.joinpath(upx_filename) - - logger.info(f"Downloading UPX: {upx_url}") - urllib.request.urlretrieve(url=upx_url, filename=upx_zipfile) - - logger.info(f"Extract UPX to: {BUILD_PATH}") - with zipfile.ZipFile(upx_zipfile, "r") as zip_ref: - zip_ref.extractall(BUILD_PATH) - - return upx_path - - def build_pyinstaller_args( output_filename: str, - upx_path: Path | None = None, versionfile_path: Path | None = None, ) -> list[str]: logger.info("Build Pyinstaller args.") @@ -86,7 +64,7 @@ def build_pyinstaller_args( logger.info(f"Add data: {items};./{ASSETS_FOLDER}/{items.name}") build_args += ["--add-data", f"{items}:./{ASSETS_FOLDER}/{items.name}"] - if os in ["win32", "win64"]: + if os == "windows": logger.info(f"Add splash image: {ASSETS_PATH.joinpath('splash.png')}") build_args += ["--splash", f"{ASSETS_PATH.joinpath('splash.png')}"] @@ -101,10 +79,6 @@ def build_pyinstaller_args( "--clean", # Clean cache and remove temp files ] - if upx_path is not None: - logger.info(f"Upx path: {upx_path}") - build_args += ["--upx-dir", f"{upx_path}"] - if versionfile_path is not None: logger.info(f"Versionfile path: {versionfile_path}") build_args += ["--version-file", f"{versionfile_path}"] @@ -144,7 +118,7 @@ def generate_versionfile(package_version: str, output_filename: str) -> Path: "--os", metavar="os", required=True, - choices=["win32", "win64", "macos"], + choices=["windows", "macos"], type=str, ) @@ -156,18 +130,15 @@ def generate_versionfile(package_version: str, output_filename: str) -> Path: output_filename = PACKAGE_NAME.title() versionfile_path = None - upx_path = None - if os in ["win32", "win64"]: + if os == "windows": versionfile_path = generate_versionfile( package_version=package_version, output_filename=output_filename, ) - upx_path = install_upx(version=UPX_VERSION, os=os) build_args = build_pyinstaller_args( output_filename=output_filename, - upx_path=upx_path, versionfile_path=versionfile_path, ) run_pyinstaller(build_args=build_args)