Skip to content

Commit

Permalink
Adding Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
frievoe97 committed Aug 27, 2024
1 parent 97865a7 commit 0d7178e
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 7 deletions.
47 changes: 40 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ permissions:
contents: write

jobs:
build:
build-macos:
runs-on: macos-latest

steps:
Expand All @@ -23,13 +23,13 @@ jobs:
- name: Install Dependencies with Constraint
run: python -m pip install -r requirements.txt

- name: Run Build Script
run: python build_script.py # Führt dein Build-Skript aus
- name: Run Build Script for macOS
run: python build_script_macos.py # Führt das macOS-Build-Skript aus

- name: Zip the .app file
run: |
cd dist
zip -r Mastermind.zip Mastermind.app
zip -r Mastermind-mac.zip Mastermind.app
- name: Create Release
id: create_release
Expand All @@ -42,12 +42,45 @@ jobs:
draft: false
prerelease: false

- name: Upload Build Artifact
- name: Upload macOS Build Artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/Mastermind.zip # Pfad zur erstellten .app Datei
asset_name: Mastermind.zip
asset_path: dist/Mastermind-mac.zip
asset_name: Mastermind-mac.zip
asset_content_type: application/zip

build-windows:
runs-on: windows-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

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

- name: Install Dependencies with Constraint
run: python -m pip install -r requirements.txt

- name: Run Build Script for Windows
run: python build_script_windows.py # Führt das Windows-Build-Skript aus

- name: Zip the .exe file
run: |
cd dist
zip -r Mastermind-win.zip Mastermind
- name: Upload Windows Build Artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/Mastermind-win.zip
asset_name: Mastermind-win.zip
asset_content_type: application/zip
File renamed without changes.
69 changes: 69 additions & 0 deletions build_script_windows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import subprocess
import os
import shutil

# Definiere den Pfad zum Icon (ändere auf .ico-Datei für Windows)
icon_path = "icon.ico" # Ersetze "icon.ico" durch den tatsächlichen Namen deiner .ico-Datei

# Schritt 1: PyInstaller ausführen, um eine `.spec`-Datei zu generieren
subprocess.run([
"pyinstaller",
"--name", "Mastermind",
"--windowed",
"--onedir",
"--noconfirm", # Automatische Bestätigung ohne Nachfragen
"--add-data", "retro.png;.", # Windows verwendet ; statt :
"--add-data", "PressStart2P-Regular.ttf;.",
"--add-data", "config;config",
"--add-data", "gui;gui",
"--add-data", "logic;logic",
"--add-data", "network;network",
"--hidden-import=pkg_resources",
"--hidden-import=pkg_resources.py2_warn",
"--hidden-import=background_manager",
"--hidden-import=config.config",
"--hidden-import=config.game_config",
"--hidden-import=gui.board_view",
"--hidden-import=gui.menu_controller",
"--hidden-import=gui.menu_model",
"--hidden-import=gui.menu_view",
"--hidden-import=gui.menu_view_update",
"--hidden-import=gui.mvc_online_settings.controller",
"--hidden-import=gui.mvc_online_settings.model",
"--hidden-import=gui.mvc_online_settings.view",
"--hidden-import=logic.color_mapping",
"--hidden-import=logic.computer_guesser",
"--hidden-import=logic.computer_local_coder",
"--hidden-import=logic.computer_network_coder",
"--hidden-import=logic.player_coder",
"--hidden-import=logic.player_guesser",
"--hidden-import=pygame_gui",
"--hidden-import=pygame",
"--icon", icon_path, # Pfad zur .ico-Datei hinzufügen
"--specpath", ".",
"main.py"
])

# `.spec`-Datei anpassen (nicht notwendig, wenn du die Option richtig übergibst)
spec_file_name = "Mastermind.spec"
with open(spec_file_name, "r") as file:
lines = file.readlines()

# Anpassungen spezifisch für Windows nicht notwendig, aber du kannst sie hier einfügen, falls erforderlich

# Speichere die Änderungen in der spec-Datei
with open(spec_file_name, "w") as file:
file.writelines(lines)

print("Spec-Datei angepasst.")

# Schritt 3: Angepasste `.spec`-Datei verwenden, um die Anwendung zu bauen
subprocess.run(["pyinstaller", "--noconfirm", spec_file_name])

# Schritt 4: Lösche den zusätzlichen Ordner im `dist`-Verzeichnis (optional)
dist_folder = os.path.join("dist", "Mastermind")
if os.path.exists(dist_folder):
shutil.rmtree(dist_folder)
print(f"Ordner '{dist_folder}' wurde gelöscht.")
else:
print(f"Ordner '{dist_folder}' nicht gefunden.")
Binary file added icon.ico
Binary file not shown.

0 comments on commit 0d7178e

Please sign in to comment.