Trying to fix the pytest ubuntu problem #73
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 Linux from stopping just because macOS failed (and vice versa) | |
| matrix: | |
| os: [macos-latest, ubuntu-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: Install dependencies | |
| 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 | |
| run: | | |
| chmod +x build.sh | |
| ./build.sh | |
| - 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/ | |
| 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 | |
| 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/ | |
| # 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/ \; | |
| git add loop_to_python_api/dlibs/ | |
| git commit -m "chore: update binaries for macOS and Linux [skip ci]" || echo "No changes to commit" | |
| git push origin ${{ needs.build-and-test.outputs.target_branch }} |