name: Build hacktiv8

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    name: Build ${{ matrix.file_name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: windows-latest
            file_name: "hacktiv8_windows"
          - os: ubuntu-latest
            file_name: "hacktiv8_linux"
          - os: macos-latest
            file_name: "hacktiv8_macos_arm64"
          - os: macos-15-intel
            file_name: "hacktiv8_macos_intel"

    steps:
    - uses: actions/checkout@v6

    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: '3.11'

    - name: Install Dependencies
      run: pip install PyQt5 pymobiledevice3==7.8.3 pyinstaller

    - name: Install DMG Creator
      if: runner.os == 'macOS'
      run: brew install create-dmg

    - name: Build with PyInstaller
      env:
        MACOSX_DEPLOYMENT_TARGET: "10.13"
      run: |
        pyinstaller --noconfirm --onefile --windowed --name "${{ matrix.file_name }}" --add-data "payload.sql:." --hidden-import "pymobiledevice3" main.py

    - name: Package macOS DMG
      if: runner.os == 'macOS'
      run: |
        cd dist
        plutil -replace LSMinimumSystemVersion -string "10.13" "${{ matrix.file_name }}.app/Contents/Info.plist"
        codesign --force --deep --sign - "${{ matrix.file_name }}.app"
        create-dmg --volname "hacktiv8" --window-pos 200 120 --window-size 600 300 --icon-size 100 --text-size 12 --hide-extension "${{ matrix.file_name }}.app" --app-drop-link 450 140 --icon "${{ matrix.file_name }}.app" 150 140 "${{ matrix.file_name }}.dmg" "${{ matrix.file_name }}.app"

    - name: Upload Artifacts
      uses: actions/upload-artifact@v6
      with:
        name: ${{ matrix.file_name }}
        path: |
          dist/*.dmg
          dist/*.exe
          dist/${{ matrix.file_name }}