Fix windows build #98
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI Workflow | |
| on: | |
| push: | |
| branches: [main, feature/windows-linux-compability] | |
| pull_request: | |
| branches: [main] | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| build-and-test: | |
| strategy: | |
| fail-fast: false # Prevents one OS from stopping others from building | |
| matrix: | |
| os: [macos-latest, ubuntu-latest, windows-latest] | |
| runs-on: ${{ matrix.os }} | |
| outputs: | |
| target_branch: ${{ steps.vars.outputs.target_branch }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.9' | |
| - name: Set up Swift (macOS) | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer | |
| swift --version | |
| - name: Set up Swift (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| uses: swift-actions/setup-swift@v2 # Corrected repository name | |
| with: | |
| swift-version: "6.0" | |
| - name: Set up Swift (Windows) | |
| if: matrix.os == 'windows-latest' | |
| uses: SwiftyLab/setup-swift@latest | |
| with: | |
| swift-version: "6.0" | |
| - name: Install dependencies | |
| shell: bash | |
| run: | | |
| python -m pip install --upgrade pip | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| pip install pytest | |
| - name: Run build script (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| chmod +x build.sh | |
| ./build.sh | |
| - name: Build on Windows | |
| if: matrix.os == 'windows-latest' | |
| shell: cmd | |
| run: | | |
| :: 1. Load Visual Studio Environment | |
| call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" | |
| :: 2. Dynamically find the Swift SDK Root | |
| :: This looks for where swift.exe is and goes up to the SDK folder | |
| for /f "delims=" %%i in ('where swift.exe') do set "SWIFT_BIN_PATH=%%~dpi" | |
| :: Logic: If Swift is in ...\Toolchains\6.0.0\usr\bin\, | |
| :: the SDK is usually in ...\Platforms\6.0.0\Windows.platform\Developer\SDKs\Windows.sdk | |
| :: SwiftyLab usually organizes them under a common 'Swift' root. | |
| set "SDKROOT=%SWIFT_BIN_PATH%..\..\..\..\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | |
| :: 3. Verify the path exists (Debugging) | |
| echo Resolved SDKROOT to: %SDKROOT% | |
| if not exist "%SDKROOT%" ( | |
| echo WARNING: SDKROOT path not found. Falling back to manual check. | |
| dir C:\Users\runneradmin\AppData\Local\Programs\Swift\Platforms /s /b | |
| ) | |
| echo Starting Fresh Swift Build (Swift 6.0)... | |
| swift build -c release -v | |
| if %ERRORLEVEL% NEQ 0 ( | |
| echo "Swift build failed with exit code %ERRORLEVEL%" | |
| exit /b %ERRORLEVEL% | |
| ) | |
| echo Build finished. Searching for DLL... | |
| dir /s /b .build\*.dll | |
| - name: Verify library was built | |
| shell: bash | |
| run: | | |
| echo "Checking if library was built successfully..." | |
| if [[ "${{ matrix.os }}" == "macos-latest" ]]; then | |
| EXPECTED_LIB="loop_to_python_api/dlibs/macos/libLoopAlgorithmToPython.dylib" | |
| elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then | |
| EXPECTED_LIB="loop_to_python_api/dlibs/linux/libLoopAlgorithmToPython.so" | |
| elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| EXPECTED_LIB="loop_to_python_api/dlibs/windows/libLoopAlgorithmToPython.dll" | |
| fi | |
| echo "Expected library: $EXPECTED_LIB" | |
| if [ -f "$EXPECTED_LIB" ]; then | |
| echo "✓ Library found: $EXPECTED_LIB" | |
| ls -la "$EXPECTED_LIB" | |
| else | |
| echo "✗ Library NOT found: $EXPECTED_LIB" | |
| echo "Contents of dlibs directory:" | |
| find loop_to_python_api/dlibs/ -type f -name "*" 2>/dev/null || echo "No files found in dlibs/" | |
| echo "Contents of .build/release/:" | |
| find .build/release/ -name "*" -type f 2>/dev/null || echo "No files found in .build/release/" | |
| exit 1 | |
| fi | |
| - name: Run tests | |
| shell: bash | |
| run: | | |
| # Help Linux find the shared library | |
| export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/loop_to_python_api/dlibs/linux/ | |
| # Help macOS find the shared library | |
| export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(pwd)/loop_to_python_api/dlibs/macos/ | |
| # Help Windows find the shared library | |
| export PATH=$PATH:$(pwd)/loop_to_python_api/dlibs/windows/ | |
| pytest -v -s | |
| - name: Upload Library Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: library-${{ matrix.os }} | |
| path: | | |
| loop_to_python_api/dlibs/macos/*.dylib | |
| loop_to_python_api/dlibs/linux/*.so | |
| loop_to_python_api/dlibs/windows/*.dll | |
| if-no-files-found: error | |
| - name: Set Target Branch | |
| id: vars | |
| shell: bash | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "target_branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "target_branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| fi | |
| commit-generated-files: | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| if: success() && (github.event_name == 'push' || github.event_name == 'pull_request') | |
| steps: | |
| - name: Checkout target branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.build-and-test.outputs.target_branch }} | |
| fetch-depth: 0 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: temp_libs | |
| - name: Organize and Commit | |
| run: | | |
| git config --local user.name "github-actions[bot]" | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| mkdir -p loop_to_python_api/dlibs/macos/ | |
| mkdir -p loop_to_python_api/dlibs/linux/ | |
| mkdir -p loop_to_python_api/dlibs/windows/ | |
| # Move files and clean up temp folders | |
| find temp_libs/ -name "*.dylib" -exec mv {} loop_to_python_api/dlibs/macos/ \; | |
| find temp_libs/ -name "*.so" -exec mv {} loop_to_python_api/dlibs/linux/ \; | |
| find temp_libs/ -name "*.dll" -exec mv {} loop_to_python_api/dlibs/windows/ \; | |
| git add loop_to_python_api/dlibs/ | |
| git commit -m "chore: update binaries for macOS, Linux, and Windows [skip ci]" || echo "No changes to commit" | |
| git push origin ${{ needs.build-and-test.outputs.target_branch }} |