Skip to content

Commit

Permalink
chore: fixed build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
V1p3rOne committed Oct 20, 2024
1 parent 0861110 commit 21a3007
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
pip install pyinstaller
- name: Run Windows Build Script
run: scripts\build_windows.bat
run: scripts/workflow/build_windows.bat
shell: cmd

- name: Upload Artifacts
Expand All @@ -59,10 +59,10 @@ jobs:
pip install pyinstaller
- name: Make Build Script Executable
run: chmod +x scripts/build_linux.sh
run: chmod +x scripts/workflow/build_linux.sh

- name: Run Linux Build Script
run: scripts/build_linux.sh
run: scripts/workflow/build_linux.sh
shell: bash

- name: Upload Artifacts
Expand All @@ -88,10 +88,10 @@ jobs:
pip install pyinstaller
- name: Make Build Script Executable
run: chmod +x scripts/build_mac.sh
run: chmod +x scripts/workflow/build_mac.sh

- name: Run macOS Build Script
run: scripts/build_mac.sh
run: scripts/workflow/build_mac.sh
shell: bash

- name: Upload Artifacts
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
110 changes: 110 additions & 0 deletions scripts/workflow/build_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

echo "========= OnTheSpot Linux Build Script ========="

# Get the directory of the script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Change to the project root directory (parent of scripts directory)
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_ROOT"

echo "Current directory: $(pwd)"

# Clean up previous builds
echo " => Cleaning up!"
rm -f ./dist/onthespot_linux ./dist/onthespot_linux_ffm
rm -f ./dist/onthespot_linux.tar.gz
rm -f ./dist/OnTheSpot.AppImage
rm -rf ./AppDir

# Check for FFmpeg and set build options
if [ -f "ffbin_nix/ffmpeg" ]; then
echo " => Found 'ffbin_nix' directory and ffmpeg binary. Including FFmpeg in the build."
FFBIN="--add-binary=ffbin_nix/*:onthespot/bin/ffmpeg"
NAME="onthespot_linux_ffm"
else
echo " => FFmpeg binary not found. Building without it."
FFBIN=""
NAME="onthespot_linux"
fi

# Run PyInstaller
echo " => Running PyInstaller..."
pyinstaller --onefile \
--hidden-import=zeroconf._utils.ipaddress \
--hidden-import=zeroconf._handlers.answers \
--add-data="src/onthespot/gui/qtui/*.ui:onthespot/gui/qtui" \
--add-data="src/onthespot/resources/icons/*.png:onthespot/resources/icons" \
--add-data="src/onthespot/resources/themes/*.qss:onthespot/resources/themes" \
--add-data="src/onthespot/resources/translations/*.qm:onthespot/resources/translations" \
$FFBIN \
--paths="src/onthespot" \
--name="$NAME" \
--icon="src/onthespot/resources/icons/onthespot.png" \
src/portable.py

# Check if the build was successful
if [ -f "./dist/$NAME" ]; then
# Set executable permissions
echo " => Setting executable permissions..."
chmod +x "./dist/$NAME"
else
echo " => Build failed or output file not found."
exit 1
fi

# Create .tar.gz archive
echo " => Creating tar.gz archive..."
cd dist
tar -czvf "$NAME.tar.gz" "$NAME"
cd ..

# Build AppImage
echo " => Building AppImage..."

# Download linuxdeploy
wget -q https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x linuxdeploy-x86_64.AppImage

# Create AppDir structure
mkdir -p AppDir/usr/bin
cp "dist/$NAME" AppDir/usr/bin/onthespot

# Copy desktop file and icon
mkdir -p AppDir/usr/share/applications
mkdir -p AppDir/usr/share/icons/hicolor/256x256/apps

cp src/onthespot/resources/icons/onthespot.png AppDir/usr/share/icons/hicolor/256x256/apps/onthespot.png

# Create desktop file
cat > AppDir/usr/share/applications/onthespot.desktop <<EOF
[Desktop Entry]
Name=OnTheSpot
Exec=onthespot
Icon=onthespot
Type=Application
Categories=Utility;
EOF

# Run linuxdeploy to create AppImage
./linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage

# Move the AppImage to dist
mv OnTheSpot*.AppImage dist/OnTheSpot.AppImage

# Move the artifacts to artifacts folder
echo " => Moving artifacts to artifacts folder..."
mkdir -p artifacts/linux
mv dist/"$NAME.tar.gz" artifacts/linux/
mv dist/OnTheSpot.AppImage artifacts/linux/

# Clean up
rm linuxdeploy-x86_64.AppImage
rm -rf AppDir

# Clean up unnecessary files
echo " => Cleaning up temporary files..."
rm -rf __pycache__ build *.spec

echo " => Done!"
69 changes: 69 additions & 0 deletions scripts/workflow/build_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

echo "========= OnTheSpot MacOS Build Script =========="

# Get the directory of the script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Change to the project root directory (parent of scripts directory)
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_ROOT"

echo "Current directory: $(pwd)"

# Clean up previous builds
echo " => Cleaning up!"
rm -rf ./dist/OnTheSpot.app
rm -f ./dist/OnTheSpot.dmg

# Check for FFmpeg binary and set build options
if [ -f "ffbin_mac/ffmpeg" ]; then
echo " => Found 'ffbin_mac' directory and ffmpeg binary. Including FFmpeg in the build."
FFBIN='--add-binary=ffbin_mac/*:onthespot/bin/ffmpeg'
else
echo " => FFmpeg binary not found. Building without it."
FFBIN=""
fi

# Run PyInstaller to create the app
echo " => Running PyInstaller..."
pyinstaller --windowed \
--hidden-import=zeroconf._utils.ipaddress \
--hidden-import=zeroconf._handlers.answers \
--add-data="src/onthespot/gui/qtui/*.ui:onthespot/gui/qtui" \
--add-data="src/onthespot/resources/icons/*.png:onthespot/resources/icons" \
--add-data="src/onthespot/resources/themes/*.qss:onthespot/resources/themes" \
--add-data="src/onthespot/resources/translations/*.qm:onthespot/resources/translations" \
$FFBIN \
--paths="src/onthespot" \
--name="OnTheSpot" \
--icon="src/onthespot/resources/icons/onthespot.icns" \
src/portable.py

# Check if the build was successful
if [ -d "./dist/OnTheSpot.app" ]; then
# Set executable permissions
echo " => Setting executable permissions..."
chmod +x "./dist/OnTheSpot.app"
else
echo " => Build failed or output app not found."
exit 1
fi

# Create .dmg file
echo " => Creating DMG file..."
mkdir -p dist/dmg_contents
cp -R dist/OnTheSpot.app dist/dmg_contents/
hdiutil create -volname "OnTheSpot" -srcfolder dist/dmg_contents -ov -format UDZO dist/OnTheSpot.dmg
rm -rf dist/dmg_contents

# Move the DMG to artifacts folder
echo " => Moving DMG to artifacts folder..."
mkdir -p artifacts/macos
mv dist/OnTheSpot.dmg artifacts/macos/

# Clean up unnecessary files
echo " => Cleaning up temporary files..."
rm -rf __pycache__ build *.spec

echo " => Done!"
76 changes: 76 additions & 0 deletions scripts/workflow/build_windows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@echo off

echo ========= OnTheSpot Windows Build Script =========

REM Navigate to the root directory if in scripts
set FOLDER_NAME=%cd%
for %%F in ("%cd%") do set FOLDER_NAME=%%~nxF
if /i "%FOLDER_NAME%"=="scripts" (
echo You are in the scripts folder. Changing to the parent directory...
cd ..
)

REM Clean up previous builds
echo => Cleaning up previous builds...
del /F /Q dist\* 2>nul

REM Bundle ffmpeg
echo => Downloading FFmpeg binary...
mkdir build
curl -L https://github.com/GyanD/codexffmpeg/releases/download/7.1/ffmpeg-7.1-essentials_build.zip -o build\ffmpeg.zip || (
echo Failed to download FFmpeg. Exiting...
exit /b 1
)

powershell -Command "Expand-Archive -Path build\ffmpeg.zip -DestinationPath build\ffmpeg" || (
echo Failed to extract FFmpeg. Exiting...
exit /b 1
)

mkdir ffbin_win

REM Find the extracted FFmpeg directory
set FFMPEG_DIR=
for /d %%D in ("build\ffmpeg\*") do set FFMPEG_DIR=%%D
if defined FFMPEG_DIR (
copy "%FFMPEG_DIR%\bin\ffmpeg.exe" ffbin_win\ || (
echo Failed to copy FFmpeg binary. Exiting...
exit /b 1
)
) else (
echo Failed to find extracted FFmpeg directory. Exiting...
exit /b 1
)

REM Build with PyInstaller
echo => Building executable with PyInstaller...
pyinstaller --onefile --noconsole --noconfirm ^
--hidden-import=zeroconf._utils.ipaddress ^
--hidden-import=zeroconf._handlers.answers ^
--add-data="src/onthespot/resources/translations/*.qm;onthespot/resources/translations" ^
--add-data="src/onthespot/resources/themes/*.qss;onthespot/resources/themes" ^
--add-data="src/onthespot/gui/qtui/*.ui;onthespot/gui/qtui" ^
--add-data="src/onthespot/resources/icons/*.png;onthespot/resources/icons" ^
--add-binary="ffbin_win/ffmpeg.exe;onthespot/bin/ffmpeg" ^
--paths=src/onthespot ^
--name=onthespot_windows ^
--icon=src/onthespot/resources/icons/onthespot.png ^
src\portable.py || (
echo PyInstaller build failed. Exiting...
exit /b 1
)

REM Move the executable to artifacts folder
echo => Moving executable to artifacts folder...
mkdir artifacts
mkdir artifacts\windows
move dist\onthespot_windows.exe artifacts\windows\

REM Clean up unnecessary files
echo => Cleaning up temporary files...
del /F /Q *.spec 2>nul
rd /s /q build 2>nul
rd /s /q __pycache__ 2>nul
rd /s /q ffbin_win 2>nul

echo => Done!

0 comments on commit 21a3007

Please sign in to comment.