Skip to content

Commit

Permalink
ci: add pyinstaller workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Jul 11, 2024
1 parent 1167974 commit 6160ec4
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 4 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/generate-executable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import logging
import os
import site
import sys
from pathlib import Path

import coloredlogs
import PyInstaller.__main__

import pymobiledevice3.__main__
import pymobiledevice3.cli
import pymobiledevice3.resources

coloredlogs.install(level=logging.DEBUG)

ROOT = Path(__file__).parent.parent.parent
DEFAULT_OUTPUT = ROOT / Path('dist/__main__').with_suffix('.exe' if sys.platform == 'win32' else '')
OUTPUT = (ROOT / 'dist/pymobiledevice3').with_suffix('.exe' if sys.platform == 'win32' else '')


def main() -> None:
site_packages_path = site.getsitepackages()[0]
resources_dir = Path(pymobiledevice3.resources.__file__).parent
pymobiledevice3_cli_path = Path(pymobiledevice3.cli.__file__).parent

hidden_imports = []

for module in pymobiledevice3_cli_path.iterdir():
if module.name.endswith('.py') and module.name != '__init__.py': # Avoid including the __init__.py
# Create the module name to be added to hidden imports
module_name = 'pymobiledevice3.cli.' + os.path.splitext(module.name)[0]
hidden_imports.append('--hidden-import=' + module_name)

pyinstaller_args = [
pymobiledevice3.__main__.__file__,
'--hidden-import=ipsw_parser',
'--hidden-import=zeroconf',
'--hidden-import=pyimg4',
'--hidden-import=zeroconf._utils.ipaddress',
'--hidden-import=zeroconf._handlers.answers',
'--hidden-import=readchar',
'--copy-metadata=pyimg4',
'--copy-metadata=readchar',
'--copy-metadata=apple_compress',
'--onefile',
]
if sys.platform == 'win32':
pyinstaller_args.extend([
'--add-binary', f'{site_packages_path}/Lib/site-packages/pytun_pmd3/wintun/*;pytun_pmd3/wintun/bin',
'--add-binary', f'{resources_dir}/webinspector;pymobiledevice3/resources/webinspector',
])
else:
pyinstaller_args.extend([
'--add-binary', f'{site_packages_path}/pytun_pmd3:pytun_pmd3',
'--add-binary', f'{resources_dir}/webinspector:pymobiledevice3/resources/webinspector',
])
pyinstaller_args.extend(hidden_imports)
PyInstaller.__main__.run(pyinstaller_args)
DEFAULT_OUTPUT.rename(OUTPUT)


if __name__ == '__main__':
main()
84 changes: 80 additions & 4 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
Expand All @@ -11,13 +8,15 @@ on:
- 'pymobiledevice3/**'
- 'requirements.txt'
- 'pyproject.toml'
release:
types: [ created ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
test:
if: '! github.event.pull_request.draft'
runs-on: ${{ matrix.os }}

Expand All @@ -44,3 +43,80 @@ jobs:
python -m pip install -U '.[test]'
- name: Test show usage
run: pytest -m cli

pyinstaller:
needs: [ 'test' ]
if: '! github.event.pull_request.draft'
runs-on: ${{ matrix.os }}

strategy:
matrix:
python-version: [ "3.12" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U . coloredlogs pyinstaller apple_compress
- name: Build
run: |
python .github/workflows/generate-executable.py
- if: matrix.os == 'ubuntu-latest'
name: Test ubuntu artifact
run: |
./dist/pymobiledevice3
- if: matrix.os == 'macos-latest'
name: Test macos artifact
run: |
./dist/pymobiledevice3
- if: matrix.os == 'windows-latest'
name: Test windows artifact
run: |
./dist/pymobiledevice3.exe
- if: matrix.os == 'ubuntu-latest'
name: Rename ubuntu artifact
run: |
mv ./dist/pymobiledevice3 ./dist/pymobiledevice3_ubuntu
- if: matrix.os == 'macos-latest'
name: Rename macos artifact
run: |
mv ./dist/pymobiledevice3 ./dist/pymobiledevice3_macos
- if: matrix.os == 'ubuntu-latest'
name: Upload ubuntu artifact
uses: actions/upload-artifact@v3
with:
name: pymobiledevice3_ubuntu
path: ./dist/pymobiledevice3_ubuntu
- if: matrix.os == 'macos-latest'
name: Upload macos artifact
uses: actions/upload-artifact@v3
with:
name: pymobiledevice3_macosx
path: ./dist/pymobiledevice3_macos
- if: matrix.os == 'windows-latest'
name: Upload windows artifact
uses: actions/upload-artifact@v3
with:
name: pymobiledevice3_windows.exe
path: ./dist/pymobiledevice3.exe

- name: Upload server artifacts to GitHub Release
if: github.event_name == 'release'
uses: softprops/action-gh-release@v1
with:
files: |
dist/pymobiledevice3_macos
dist/pymobiledevice3_ubuntu
dist/pymobiledevice3.exe
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ debug/
*.egg-info/
pymobiledevice3/_version.py
.python-version
__main__.spec

0 comments on commit 6160ec4

Please sign in to comment.