Skip to content

Trying to fix...

Trying to fix... #16

name: Build All Platforms
on:
# Run the workflow on pushes to main and on pull requests
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
# Use a matrix to spin up jobs on Windows, macOS and Linux
strategy:
matrix:
include:
# Linux build (Ubuntu runners come with GCC/Clang)
- os: ubuntu-latest
build_type: Release
cmake_args: -DCMAKE_BUILD_TYPE=Release
# macOS build
- os: macos-latest
build_type: Release
cmake_args: -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DCMAKE_BUILD_TYPE=Release
# Windows build with Visual Studio
- os: windows-latest
build_type: Release
cmake_args: -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release
runs-on: ${{ matrix.os }}
steps:
# Checkout the repository with submodules (assets and external code)
- name: Checkout source
uses: actions/checkout@v3
with:
submodules: recursive
# Install build dependencies on Linux (Ubuntu). These packages are
# listed in the repository README as required for raylib and C++.
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
# Essential build tools and CMake
sudo apt-get install -y build-essential git cmake \
libasound2-dev libx11-dev libxrandr-dev libxi-dev \
libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev \
libxinerama-dev libwayland-dev libxkbcommon-dev \
zip wget dpkg-dev
# Install dependencies on macOS. Homebrew is used to install CMake.
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew update
# Ensure CMake is available; Xcode is preinstalled on the runner
brew install cmake
# Install dependencies on Windows. Visual Studio 2022 is preinstalled
# on GitHub runners; ensure CMake is available via Chocolatey.
- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: |
choco install cmake --installargs "ADD_CMAKE_TO_PATH=System" -y
# Configure the build. The matrix.cmake_args handles generator and
# architecture differences. On Linux and macOS we rely on the
# default Makefile generator; on Windows we use Visual Studio.
- name: Configure CMake
run: cmake -S . -B build ${{ matrix.cmake_args }}
# Build the project. Use parallel builds when possible.
- name: Build (Windows)
if: runner.os == 'Windows'
run: cmake --build build --config ${{ matrix.build_type }} --parallel
# Package release for Windows: create a zip archive with the executable and assets
- name: Package release (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Create staging directory
New-Item -ItemType Directory -Force -Path packaged | Out-Null
# Copy the Windows executable
Copy-Item -Path "build\${{ matrix.build_type }}\mw_recreation.exe" -Destination packaged
# Copy the assets directory
Copy-Item -Path "assets" -Destination "packaged\assets" -Recurse
# Create a zip archive containing the executable and assets
Compress-Archive -Path packaged\* -DestinationPath "windows-latest.zip"
# Upload packaged release for Windows
- name: Upload release (Windows)
if: runner.os == 'Windows'
uses: actions/upload-artifact@v4
with:
name: windows-latest
path: windows-latest.zip
- name: Build (Unix)
if: runner.os != 'Windows'
run: cmake --build build --parallel
# Package release for macOS: create a zip archive with the executable and assets
# Generate a macOS .app bundle using the provided generator script and package it
- name: Package .app (macOS)
if: runner.os == 'macOS'
run: |
set -e
# Ensure the generator script is executable
chmod +x tools/macos_app_generator.sh
# Run the script with the built binary and assets as arguments. This script
# should create a .app bundle in the current directory or in a known location.
tools/macos_app_generator.sh build/mw_recreation assets
# Find the generated .app bundle (assumes only one .app is generated)
APP_PATH=$(find . -name '*.app' -type d -print -quit)
if [ -z "$APP_PATH" ]; then
echo "No .app bundle found after running macos_app_generator.sh" && exit 1
fi
# Compress the .app bundle into a zip for distribution
zip -r macos-latest.zip "$APP_PATH"
# Upload packaged .app for macOS
- name: Upload release (macOS)
if: runner.os == 'macOS'
uses: actions/upload-artifact@v4
with:
name: macos-latest
path: macos-latest.zip
# Package release for Linux: create a tar.gz archive with the executable and assets
- name: Package release (Linux)
if: runner.os == 'Linux'
run: |
mkdir -p packaged
cp build/mw_recreation packaged/
cp -r assets packaged/assets
tar -czf linux-latest.tar.gz -C packaged .
# Upload packaged release for Linux
- name: Upload release (Linux)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: linux-latest
path: linux-latest.tar.gz
# Build and package additional Linux distributions: AppImage and .deb
- name: Package Linux AppImage
if: runner.os == 'Linux'
run: |
set -e
# Prepare AppDir structure for linuxdeploy
mkdir -p appimage-build/AppDir/usr/bin
cp build/mw_recreation appimage-build/AppDir/usr/bin/mw_recreation
cp -r assets appimage-build/AppDir/usr/bin/assets
# Create desktop entry for the AppImage
mkdir -p appimage-build/AppDir/usr/share/applications
cat > appimage-build/AppDir/usr/share/applications/mw_recreation.desktop <<'EOF'
[Desktop Entry]
Name=Music World Recreation
Exec=mw_recreation
Icon=mw_recreation
Type=Application
Categories=Game;
EOF
# Download linuxdeploy to bundle the AppImage
wget -q https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage -O linuxdeploy.AppImage
chmod +x linuxdeploy.AppImage
# Build the AppImage; this produces a .AppImage file
# Select an icon to embed into the AppImage.
# Prefer icons from assets/sprites/icons directory (icon_256x256.png or icon_512x512.png). If neither exists,
# use the first PNG in assets/sprites/icons if present, otherwise first PNG anywhere in assets.
if [ -f assets/sprites/icons/icon_256x256.png ]; then
ICON_FILE="assets/sprites/icons/icon_256x256.png"
elif [ -f assets/sprites/icons/icon_512x512.png ]; then
ICON_FILE="assets/sprites/icons/icon_512x512.png"
else
if [ -d assets/sprites/icons ]; then
ICON_FILE=$(find assets/sprites/icons -type f -name "*.png" -print -quit)
fi
if [ -z "$ICON_FILE" ]; then
ICON_FILE=$(find assets -type f -name "*.png" -print -quit)
fi
fi
# Copy the selected icon into AppDir for linuxdeploy to embed
cp "$ICON_FILE" appimage-build/AppDir/mw_recreation.png
# Run linuxdeploy to build the AppImage
./linuxdeploy.AppImage \
--appdir appimage-build/AppDir \
--desktop-file appimage-build/AppDir/usr/share/applications/mw_recreation.desktop \
--icon-file appimage-build/AppDir/mw_recreation.png \
--output appimage
# Rename the generated .AppImage file to a predictable name
APPIMG=$(ls -1 *.AppImage | head -n 1)
if [ -n "$APPIMG" ]; then
mv "$APPIMG" mw_recreation.AppImage
else
echo "No AppImage file generated" && exit 1
fi
- name: Package Linux .deb
if: runner.os == 'Linux'
run: |
set -e
# Prepare debian package directory structure
mkdir -p debpkg/usr/bin
cp build/mw_recreation debpkg/usr/bin/
mkdir -p debpkg/usr/share/mw_recreation
cp -r assets debpkg/usr/share/mw_recreation/
mkdir -p debpkg/DEBIAN
cat > debpkg/DEBIAN/control <<'EOF'
Package: mw-recreation
Version: 1.0.0
Section: games
Priority: optional
Architecture: amd64
Maintainer: Unknown
Description: Music World Recreation game built with raylib
EOF
# Build the Debian package
dpkg-deb --build debpkg mw_recreation.deb
- name: Upload Linux AppImage
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: linux-appimage
path: mw_recreation.AppImage
- name: Upload Linux deb
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: linux-deb
path: mw_recreation.deb
# Upload build artifacts. Separate steps are used for Windows and
# non‑Windows because the executable is generated into different
# directories on Visual Studio.
- name: Upload artifact (Windows)
if: runner.os == 'Windows'
uses: actions/upload-artifact@v4
with:
name: mw_recreation-windows
path: build\${{ matrix.build_type }}\mw_recreation.exe
- name: Upload artifact (Unix)
if: runner.os != 'Windows'
uses: actions/upload-artifact@v4
with:
name: mw_recreation-${{ matrix.os }}
path: build/mw_recreation