11name : CI Workflow
22
3- # Trigger on PR events and direct pushes to main (but not PR merges)
43on :
54 push :
6- branches :
7- - main
8- - feature/windows-linux-compability
5+ branches : [main, feature/windows-linux-compability]
96 pull_request :
10- branches :
11- - main
12- types :
13- - opened
14- - synchronize
15- - reopened
7+ branches : [main]
8+ types : [opened, synchronize, reopened]
169
17- # Define the jobs to run in the workflow
1810jobs :
19- build :
11+ build-and-test :
2012 strategy :
2113 matrix :
22- include :
23- - os : macos-latest
24- platform : macos
25- artifact : libLoopAlgorithmToPython.dylib
26- - os : ubuntu-latest
27- platform : linux
28- artifact : libLoopAlgorithmToPython.so
14+ os : [macos-latest, ubuntu-latest]
2915 runs-on : ${{ matrix.os }}
16+ outputs :
17+ target_branch : ${{ steps.vars.outputs.target_branch }}
3018
3119 steps :
3220 - name : Checkout code
3321 uses : actions/checkout@v4
3422
3523 - name : Set up Python
36- uses : actions/setup-python@v4
24+ uses : actions/setup-python@v5
3725 with :
3826 python-version : ' 3.9'
3927
4028 - name : Set up Swift
4129 uses : swiftactions/setup-swift@v2
4230 with :
43- swift-version : " 6.0"
31+ swift-version : ' 6.0'
4432
45- - name : Install additional Linux dependencies
46- if : matrix.platform == 'linux'
47- run : |
48- sudo apt-get update
49- sudo apt-get install -y libsqlite3-dev zlib1g-dev libncurses5-dev libicu-dev
50-
51- - name : Install Python dependencies
33+ - name : Install dependencies
5234 run : |
5335 python -m pip install --upgrade pip
5436 if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
37+ pip install pytest
5538
56- - name : Build Swift library
39+ - name : Run build script
5740 run : |
5841 chmod +x build.sh
5942 ./build.sh
60-
61- # Debug: Check what files were actually generated
62- echo "Files in .build/release/:"
63- ls -la .build/release/ || echo "No .build/release directory"
64-
65- echo "Files in loop_to_python_api/dlibs/:"
66- ls -la loop_to_python_api/dlibs/ || echo "No dlibs directory"
67-
68- echo "${{ matrix.platform }} library file:"
69- ls -la loop_to_python_api/dlibs/${{ matrix.platform }}/ || echo "No ${{ matrix.platform }} dlibs"
70-
71- - name : Set library path for testing
72- run : |
73- if [[ "${{ matrix.platform }}" == "linux" ]]; then
74- export LD_LIBRARY_PATH="${PWD}/loop_to_python_api/dlibs/linux:$LD_LIBRARY_PATH"
75- echo "LD_LIBRARY_PATH=${PWD}/loop_to_python_api/dlibs/linux:$LD_LIBRARY_PATH" >> $GITHUB_ENV
76- fi
7743
7844 - name : Run tests
79- run : |
80- pytest -v -s
45+ run : pytest -v -s
8146
82- - name : Upload library artifact
47+ # Save the library files so the next job can commit them
48+ - name : Upload Library Artifact
8349 uses : actions/upload-artifact@v4
8450 with :
85- name : library-${{ matrix.platform }}
86- path : loop_to_python_api/dlibs/${{ matrix.platform }}/${{ matrix.artifact }}
87- retention-days : 1
51+ name : library-${{ matrix.os }}
52+ path : |
53+ loop_to_python_api/dlibs/macos/*.dylib
54+ loop_to_python_api/dlibs/linux/*.so
55+
56+ - name : Set Target Branch
57+ id : vars
58+ run : |
59+ if [ "${{ github.event_name }}" = "pull_request" ]; then
60+ echo "target_branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT
61+ else
62+ echo "target_branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT
63+ fi
8864
89- commit-libraries :
90- needs : build
65+ commit-generated-files :
66+ needs : build-and-test
9167 runs-on : ubuntu-latest
92- if : github.event_name == 'pull_request' || !contains(github.event.head_commit.message, 'Merge pull request')
93-
68+ # Only push on direct pushes or specific PR actions to avoid loops
69+ if : github.event_name == 'push' || github.event_name == 'pull_request'
9470 steps :
95- - name : Checkout code
71+ - name : Checkout target branch
9672 uses : actions/checkout@v4
9773 with :
98- token : ${{ secrets.GITHUB_TOKEN }}
99-
100- - name : Download macOS library
101- uses : actions/download-artifact@v4
102- with :
103- name : library-macos
104- path : loop_to_python_api/dlibs/macos/
74+ ref : ${{ needs.build-and-test.outputs.target_branch }}
75+ fetch-depth : 0
10576
106- - name : Download Linux library
77+ - name : Download all artifacts
10778 uses : actions/download-artifact@v4
10879 with :
109- name : library-linux
110- path : loop_to_python_api/dlibs/linux/
80+ path : temp_libs
11181
112- - name : Commit and push libraries
82+ - name : Organize and Commit
11383 run : |
114- git config --local user.name "GitHub Action "
115- git config --local user.email "action@ github.com"
84+ git config --local user.name "github-actions[bot] "
85+ git config --local user.email "github-actions[bot]@users.noreply. github.com"
11686
117- # Determine target branch
118- if [ "${{ github.event_name }}" = "pull_request" ]; then
119- TARGET_BRANCH="${{ github.event.pull_request.head.ref }}"
120- else
121- TARGET_BRANCH="${{ github.ref_name }}"
122- fi
87+ # Move files from artifact folders back to the correct repo structure
88+ mkdir -p loop_to_python_api/dlibs/macos/
89+ mkdir -p loop_to_python_api/dlibs/linux/
12390
124- # Fetch latest changes and checkout target branch
125- git fetch origin
126- git checkout -B $TARGET_BRANCH origin/$TARGET_BRANCH
91+ # Copy downloaded files (adjusting for nested folder structure created by download-artifact)
92+ find temp_libs/library-macos-latest -name "*.dylib" -exec cp {} loop_to_python_api/dlibs/macos/ \;
93+ find temp_libs/library-ubuntu-latest -name "*.so" -exec cp {} loop_to_python_api/dlibs/linux/ \;
12794
128- # Add both library files
129- git add loop_to_python_api/dlibs/macos/libLoopAlgorithmToPython.dylib || echo "No macOS library to add"
130- git add loop_to_python_api/dlibs/linux/libLoopAlgorithmToPython.so || echo "No Linux library to add"
131-
132- # Commit if there are changes
133- if git diff --staged --quiet; then
134- echo "No library changes to commit"
135- else
136- git commit -m "Update compiled libraries for macOS and Linux
137-
138- 🤖 Generated with [Claude Code](https://claude.ai/code)
139-
140- Co-Authored-By : Claude <noreply@anthropic.com>"
141- git push origin $TARGET_BRANCH
142- fi
143-
95+ git add loop_to_python_api/dlibs/
96+ git commit -m "chore: update cross-platform binaries [skip ci]" || echo "No changes to commit"
97+ git push origin ${{ needs.build-and-test.outputs.target_branch }}
0 commit comments