Skip to content

Commit

Permalink
build: add macos packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
u8slvn committed Aug 26, 2024
1 parent c91b96b commit 26b9ba5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 17 deletions.
55 changes: 54 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: Create dmg
run: |
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 }}-{{ matrix.arch-name }}.app"
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: macos-${{ matrix.arch-name }}
path: ${{ github.workspace }}/doggo-*.dmg
41 changes: 25 additions & 16 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand All @@ -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


Expand Down Expand Up @@ -138,30 +144,33 @@ def generate_versionfile(package_version: str, output_filename: str) -> Path:
"--os",
metavar="os",
required=True,
choices=["win32", "win64"],
choices=["win32", "win64", "macos"],
type=str,
)

args = parser.parse_args()

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,
Expand Down

0 comments on commit 26b9ba5

Please sign in to comment.