Skip to content

Add multi-platform GitHub Actions workflow with manual trigger #1

Add multi-platform GitHub Actions workflow with manual trigger

Add multi-platform GitHub Actions workflow with manual trigger #1

name: Build All Platforms
# Manual trigger that works on any branch
on:
workflow_dispatch:
inputs:
platforms:
description: 'Platforms to build (comma-separated: ubuntu,macos,windows or "all")'
required: true
default: 'all'
type: string
commit_libraries:
description: 'Commit generated libraries back to branch'
required: true
default: true
type: boolean
jobs:
build-matrix:
strategy:
matrix:
include:
- os: ubuntu-latest
platform: linux
library_extension: so
swift_setup: |
# Install Swift for Linux
wget https://download.swift.org/swift-6.0.3-release/ubuntu2404/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-ubuntu24.04.tar.gz
tar xzf swift-6.0.3-RELEASE-ubuntu24.04.tar.gz
sudo mv swift-6.0.3-RELEASE-ubuntu24.04 /usr/local/swift
echo "/usr/local/swift/usr/bin" >> $GITHUB_PATH
# Install build dependencies
sudo apt update
sudo apt install -y build-essential libc6-dev
- os: macos-latest
platform: macos
library_extension: dylib
swift_setup: |
# Swift is pre-installed on macOS runners
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
- os: windows-latest
platform: windows
library_extension: dll
swift_setup: |
# Install Swift for Windows
choco install swift
runs-on: ${{ matrix.os }}
# Skip this job if platform not requested
if: |
github.event.inputs.platforms == 'all' ||
contains(github.event.inputs.platforms, matrix.platform)
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Swift for ${{ matrix.platform }}
run: ${{ matrix.swift_setup }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install pytest numpy pandas
- name: Build Swift library for ${{ matrix.platform }}
run: |
# Ensure dlibs directory structure exists
mkdir -p loop_to_python_api/dlibs/${{ matrix.platform }}
# Run the build script
chmod +x build.sh
./build.sh
- name: Run tests to verify build
run: |
pytest python_tests/tests.py::test_initialize_exception_handlers -v
- name: Upload library artifact
uses: actions/upload-artifact@v4
with:
name: library-${{ matrix.platform }}
path: loop_to_python_api/dlibs/${{ matrix.platform }}/libLoopAlgorithmToPython.${{ matrix.library_extension }}
retention-days: 30
commit-libraries:
needs: build-matrix
runs-on: ubuntu-latest
if: github.event.inputs.commit_libraries == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Download all library artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Copy libraries to dlibs structure
run: |
# Ensure dlibs directory structure exists
mkdir -p loop_to_python_api/dlibs/{linux,macos,windows}
# Copy libraries from artifacts
if [ -d "artifacts/library-linux" ]; then
cp artifacts/library-linux/* loop_to_python_api/dlibs/linux/ || true
fi
if [ -d "artifacts/library-macos" ]; then
cp artifacts/library-macos/* loop_to_python_api/dlibs/macos/ || true
fi
if [ -d "artifacts/library-windows" ]; then
cp artifacts/library-windows/* loop_to_python_api/dlibs/windows/ || true
fi
- name: Commit and push generated libraries
run: |
git config --local user.name "GitHub Action"
git config --local user.email "action@github.com"
# Add all library files
git add loop_to_python_api/dlibs/
# Commit if there are changes
if git diff --staged --quiet; then
echo "No library changes to commit"
else
git commit -m "🤖 Update cross-platform libraries
Built libraries for platforms: ${{ github.event.inputs.platforms }}
Generated with [GitHub Actions](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})

Check failure on line 142 in .github/workflows/build-all-platforms.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build-all-platforms.yml

Invalid workflow file

You have an error in your yaml syntax on line 142
Co-Authored-By: GitHub Actions <noreply@github.com>"
git push origin ${{ github.ref_name }}
fi