From 964c61397e1cc67e1db08b4418a0c28304276ca7 Mon Sep 17 00:00:00 2001 From: u8slvn Date: Mon, 26 Aug 2024 18:11:46 +0200 Subject: [PATCH] build: add macos packaging --- .github/workflows/build.yml | 55 ++++++++++++++++++++++++++++++++++++- scripts/build.py | 41 ++++++++++++++++----------- 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4754621..2c6bc07 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: - "v*.*.*" jobs: build-windows: - name: build-${{ matrix.platform }} + name: build-windows-${{ matrix.arch }} runs-on: windows-latest strategy: fail-fast: false @@ -55,3 +55,56 @@ jobs: # if: startsWith(github.ref, 'refs/tags/') # with: # files: dist/doggo-*.exe + + build-macos: + name: build-macos-${{ matrix.arch }} + runs-on: macos-${{ matrix.os-version }} + strategy: + fail-fast: false + matrix: + os-version: [ 13, 14 ] + include: + - os-version: 13 + arch: x86_64 + arch-name: Intel + - os-version: 14 + arch: aarch64 + arch-name: AppleSilicon + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - name: Install poetry + run: curl -sSL https://install.python-poetry.org | python - -y + + - name: Update poetry path + run: echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Configure poetry + run: poetry config virtualenvs.in-project true + + - name: Install dependencies + run: poetry install + + - name: Build release + run: | + poetry run python scripts/build.py --os macos + + - name: Sign app + run: codesign --force --deep -s - ./dist/doggo-*.app +# brew install create-dmg +# VERSION=$(grep -m 1 version pyproject.toml | grep -e '\d.\d.\d' -o) +# create-dmg --volname "Doggo" --no-internet-enable "doggo-$VERSION-${{ matrix.arch-name }}.dmg" "./dist/doggo-$VERSION-macos.app" + + - name: Archive production artifacts + uses: actions/upload-artifact@v4 + with: + name: macos-${{ matrix.arch-name }} + path: ${{ github.workspace }}/dist/doggo-*.app diff --git a/scripts/build.py b/scripts/build.py index 94f771b..0a25ba2 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -79,19 +79,24 @@ def build_pyinstaller_args( build_args += ["--icon", f"{ASSETS_PATH.joinpath('icon-42.png')}"] logger.info(f"Add assets folder: {ASSETS_PATH}") - build_args += ["--add-data", f"{ASSETS_PATH}/*;./{ASSETS_FOLDER}"] + build_args += ["--add-data", f"{ASSETS_PATH}:./{ASSETS_FOLDER}"] for items in ASSETS_PATH.glob("**/*"): if not items.is_dir(): continue logger.info(f"Add data: {items};./{ASSETS_FOLDER}/{items.name}") - build_args += ["--add-data", f"{items};./{ASSETS_FOLDER}/{items.name}"] + build_args += ["--add-data", f"{items}:./{ASSETS_FOLDER}/{items.name}"] - logger.info(f"Add splash image: {ASSETS_PATH.joinpath('splash.png')}") - build_args += ["--splash", f"{ASSETS_PATH.joinpath('splash.png')}"] + if os in ["win32", "win64"]: + logger.info(f"Add splash image: {ASSETS_PATH.joinpath('splash.png')}") + build_args += ["--splash", f"{ASSETS_PATH.joinpath('splash.png')}"] - logger.info("Build options: onefile, noconsole, clean") + logger.info("Build options: onefile") + build_args += [ + "--onefile", # One compressed output file + ] + + logger.info("Build options: noconsole, clean") build_args += [ - "--onefile", # One compressed output file "--noconsole", # Disable log window "--clean", # Clean cache and remove temp files ] @@ -104,6 +109,7 @@ def build_pyinstaller_args( logger.info(f"Versionfile path: {versionfile_path}") build_args += ["--version-file", f"{versionfile_path}"] + print(" ".join(build_args)) return build_args @@ -138,7 +144,7 @@ def generate_versionfile(package_version: str, output_filename: str) -> Path: "--os", metavar="os", required=True, - choices=["win32", "win64"], + choices=["win32", "win64", "macos"], type=str, ) @@ -146,22 +152,25 @@ def generate_versionfile(package_version: str, output_filename: str) -> Path: os = args.os - os_name = "windows" - if os == "win32": - arch = "x86" - else: - arch = "x64" - package_version = get_package_version() - output_filename = f"doggo-{package_version}-{os_name}-{arch}" + if os in ["macos"]: + output_filename = f"doggo-{package_version}-{os}" + elif os in ["win32", "win64"]: + arch = "x86" if os == "win32" else "x64" + output_filename = f"doggo-{package_version}-windows-{arch}" + else: + raise ValueError(f"Unsupported OS: {os}") versionfile_path = None - if os_name == "windows": + upx_path = None + + if os in ["win32", "win64"]: versionfile_path = generate_versionfile( package_version=package_version, output_filename=output_filename, ) - upx_path = install_upx(version=UPX_VERSION, os=os) + upx_path = install_upx(version=UPX_VERSION, os=os) + build_args = build_pyinstaller_args( output_filename=output_filename, upx_path=upx_path,