Skip to content

Commit 1b0731f

Browse files
committed
Add multi-platform GitHub Actions workflow with manual trigger
Features: - workflow_dispatch trigger allows manual builds on any branch from GitHub UI - Matrix strategy builds for Linux (.so), macOS (.dylib), and Windows (.dll) - Platform selection via input parameter (specific platforms or 'all') - Automatic Swift toolchain setup for each platform - Generated libraries committed back to dlibs/ structure - Artifacts uploaded for manual download if needed Also updated: - Fixed existing ci.yml to use new dlibs/macos/ path structure - Removed redundant linux_setup.sh script (replaced by automated builds) Usage: Go to Actions tab → 'Build All Platforms' → Run workflow on desired branch
1 parent f6b4373 commit 1b0731f

3 files changed

Lines changed: 148 additions & 53 deletions

File tree

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Build All Platforms
2+
3+
# Manual trigger that works on any branch
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
platforms:
8+
description: 'Platforms to build (comma-separated: ubuntu,macos,windows or "all")'
9+
required: true
10+
default: 'all'
11+
type: string
12+
commit_libraries:
13+
description: 'Commit generated libraries back to branch'
14+
required: true
15+
default: true
16+
type: boolean
17+
18+
jobs:
19+
build-matrix:
20+
strategy:
21+
matrix:
22+
include:
23+
- os: ubuntu-latest
24+
platform: linux
25+
library_extension: so
26+
swift_setup: |
27+
# Install Swift for Linux
28+
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
29+
tar xzf swift-6.0.3-RELEASE-ubuntu24.04.tar.gz
30+
sudo mv swift-6.0.3-RELEASE-ubuntu24.04 /usr/local/swift
31+
echo "/usr/local/swift/usr/bin" >> $GITHUB_PATH
32+
# Install build dependencies
33+
sudo apt update
34+
sudo apt install -y build-essential libc6-dev
35+
- os: macos-latest
36+
platform: macos
37+
library_extension: dylib
38+
swift_setup: |
39+
# Swift is pre-installed on macOS runners
40+
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
41+
sudo xcodebuild -runFirstLaunch
42+
- os: windows-latest
43+
platform: windows
44+
library_extension: dll
45+
swift_setup: |
46+
# Install Swift for Windows
47+
choco install swift
48+
49+
runs-on: ${{ matrix.os }}
50+
51+
# Skip this job if platform not requested
52+
if: |
53+
github.event.inputs.platforms == 'all' ||
54+
contains(github.event.inputs.platforms, matrix.platform)
55+
56+
steps:
57+
- name: Checkout code
58+
uses: actions/checkout@v4
59+
60+
- name: Set up Swift for ${{ matrix.platform }}
61+
run: ${{ matrix.swift_setup }}
62+
63+
- name: Set up Python
64+
uses: actions/setup-python@v4
65+
with:
66+
python-version: '3.9'
67+
68+
- name: Install Python dependencies
69+
run: |
70+
python -m pip install --upgrade pip
71+
pip install pytest numpy pandas
72+
73+
- name: Build Swift library for ${{ matrix.platform }}
74+
run: |
75+
# Ensure dlibs directory structure exists
76+
mkdir -p loop_to_python_api/dlibs/${{ matrix.platform }}
77+
78+
# Run the build script
79+
chmod +x build.sh
80+
./build.sh
81+
82+
- name: Run tests to verify build
83+
run: |
84+
pytest python_tests/tests.py::test_initialize_exception_handlers -v
85+
86+
- name: Upload library artifact
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: library-${{ matrix.platform }}
90+
path: loop_to_python_api/dlibs/${{ matrix.platform }}/libLoopAlgorithmToPython.${{ matrix.library_extension }}
91+
retention-days: 30
92+
93+
commit-libraries:
94+
needs: build-matrix
95+
runs-on: ubuntu-latest
96+
if: github.event.inputs.commit_libraries == 'true'
97+
98+
steps:
99+
- name: Checkout code
100+
uses: actions/checkout@v4
101+
with:
102+
token: ${{ secrets.GITHUB_TOKEN }}
103+
fetch-depth: 0
104+
105+
- name: Download all library artifacts
106+
uses: actions/download-artifact@v4
107+
with:
108+
path: artifacts/
109+
110+
- name: Copy libraries to dlibs structure
111+
run: |
112+
# Ensure dlibs directory structure exists
113+
mkdir -p loop_to_python_api/dlibs/{linux,macos,windows}
114+
115+
# Copy libraries from artifacts
116+
if [ -d "artifacts/library-linux" ]; then
117+
cp artifacts/library-linux/* loop_to_python_api/dlibs/linux/ || true
118+
fi
119+
if [ -d "artifacts/library-macos" ]; then
120+
cp artifacts/library-macos/* loop_to_python_api/dlibs/macos/ || true
121+
fi
122+
if [ -d "artifacts/library-windows" ]; then
123+
cp artifacts/library-windows/* loop_to_python_api/dlibs/windows/ || true
124+
fi
125+
126+
- name: Commit and push generated libraries
127+
run: |
128+
git config --local user.name "GitHub Action"
129+
git config --local user.email "action@github.com"
130+
131+
# Add all library files
132+
git add loop_to_python_api/dlibs/
133+
134+
# Commit if there are changes
135+
if git diff --staged --quiet; then
136+
echo "No library changes to commit"
137+
else
138+
git commit -m "🤖 Update cross-platform libraries
139+
140+
Built libraries for platforms: ${{ github.event.inputs.platforms }}
141+
142+
Generated with [GitHub Actions](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
143+
144+
Co-Authored-By: GitHub Actions <noreply@github.com>"
145+
git push origin ${{ github.ref_name }}
146+
fi

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ jobs:
6464
git fetch origin
6565
git checkout -B $TARGET_BRANCH origin/$TARGET_BRANCH
6666
67-
# Add and commit the .dylib file
68-
git add ./loop_to_python_api/libLoopAlgorithmToPython.dylib
67+
# Add and commit the .dylib file to new dlibs structure
68+
git add ./loop_to_python_api/dlibs/macos/libLoopAlgorithmToPython.dylib
6969
git commit -m "Add generated libLoopAlgorithmToPython.dylib" || echo "No changes to commit"
7070
7171
# Push to the target branch

linux_setup.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)