Fix Windows zip failures and update MATLAB toolbox packaging #29
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: Build and Release Pyraview | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: # Allows manual triggering | |
| jobs: | |
| build_and_test: | |
| name: Build & Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup CMake | |
| uses: lukka/get-cmake@latest | |
| - name: Configure CMake | |
| shell: bash | |
| run: | | |
| mkdir build | |
| if [ "${{ runner.os }}" == "Windows" ]; then | |
| cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release | |
| else | |
| cmake -S . -B build -DCMAKE_BUILD_TYPE=Release | |
| fi | |
| - name: Build All | |
| run: cmake --build build --parallel | |
| - name: Run C Tests | |
| shell: bash | |
| run: | | |
| cd build | |
| ctest --output-on-failure | |
| # Zip binaries for release (naming by OS/Architecture) | |
| - name: Package Binaries | |
| if: startsWith(github.ref, 'refs/tags/') | |
| shell: bash | |
| run: | | |
| mkdir -p dist | |
| if [ "${{ runner.os }}" == "Windows" ]; then | |
| # Use 7-Zip (pre-installed on Windows runners) | |
| # 'a' is add, '-j' junk paths (like zip -j) | |
| 7z a -tzip dist/pyraview-win-x64.zip ./build/bin/*.dll ./build/bin/*.exe | |
| else | |
| zip -j dist/pyraview-${{ runner.os }}-${{ runner.arch }}.zip build/bin/* | |
| fi | |
| - name: Upload Artifacts | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binaries-${{ matrix.os }} | |
| path: dist/* | |
| build-matlab: | |
| name: Build & Test Matlab (${{ matrix.os }}) | |
| needs: build_and_test | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| # Matlab actions support limited OS versions, check availability | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: matlab-actions/setup-matlab@v2 | |
| with: | |
| release: 'R2024b' | |
| - name: Compile MEX | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| # Enable OpenMP if supported by the platform (simple check or flag) | |
| # For Ubuntu (GCC): -fopenmp | |
| # For Windows (MSVC): -openmp (or implied via /openmp) | |
| # For macOS (Clang): -Xpreprocessor -fopenmp -lomp (but requires libomp) | |
| # To keep it simple and avoid linker errors on stock runners without libomp, we skip explicit OMP flags for now or use safe defaults. | |
| # But pyraview.c has #include <omp.h>. If we don't link OMP, it might fail if _OPENMP is defined by default but library isn't linked. | |
| # Let's try compiling WITHOUT flags first, relying on the source's #ifdef _OPENMP guards. | |
| command: mex -v src/matlab/pyraview_mex.c src/c/pyraview.c -Iinclude -output src/matlab/pyraview | |
| - name: Run Matlab Tests | |
| uses: matlab-actions/run-tests@v2 | |
| with: | |
| select-by-folder: src/matlab | |
| - name: Upload MEX Artifact | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mex-${{ matrix.os }} | |
| path: src/matlab/pyraview.* # Matches pyraview.mexw64, .mexa64, etc. | |
| if-no-files-found: error | |
| package-matlab: | |
| name: Package Matlab Toolbox | |
| needs: build-matlab | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: matlab-actions/setup-matlab@v2 | |
| with: | |
| release: 'R2024b' | |
| # Download all platform-specific MEX files we just built | |
| - name: Download all MEX artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: src/matlab | |
| pattern: mex-* | |
| merge-multiple: true | |
| # Run the packaging command | |
| - name: Package Toolbox | |
| uses: matlab-actions/run-command@v2 | |
| env: | |
| RELEASE_TAG: ${{ github.ref_name }} | |
| with: | |
| command: | | |
| % 1. Create a dummy .prj content with a GUID so the constructor doesn't crash | |
| guid = char(java.util.UUID.randomUUID()); | |
| prjContent = sprintf(['<?xml version="1.0" encoding="UTF-8"?>' ... | |
| '<deployment-project plugin="plugin.toolbox" v3.0>' ... | |
| '<configuration file="pyraview.prj" name="pyraview" target="target.toolbox" target-name="Package Toolbox">' ... | |
| '<param.guid>%s</param.guid>' ... | |
| '</configuration></deployment-project>'], guid); | |
| % 2. Write it to a temporary file | |
| fid = fopen('temp_packaging.prj', 'w'); | |
| fprintf(fid, '%s', prjContent); | |
| fclose(fid); | |
| % Create the options object from the temporary PRJ | |
| opts = matlab.addons.toolbox.ToolboxOptions('temp_packaging.prj'); | |
| opts.ToolboxName = 'Pyraview'; | |
| % Grab version from environment variable | |
| v = getenv('RELEASE_TAG'); | |
| if startsWith(v, 'v') | |
| v = v(2:end); | |
| end | |
| opts.ToolboxVersion = v; | |
| opts.AuthorName = 'Van Hooser lab'; | |
| opts.ToolboxImage = ''; | |
| opts.Description = 'High-performance multi-resolution decimation engine.'; | |
| opts.OutputFile = 'Pyraview.mltbx'; | |
| % Important: Include the folder with the MEX files | |
| opts.ToolboxFiles = {fullfile(pwd, 'src', 'matlab')}; | |
| % Package it | |
| matlab.addons.toolbox.packageToolbox(opts); | |
| # Upload the .mltbx as an artifact so the release job can pick it up | |
| - name: Upload Toolbox Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: matlab-toolbox | |
| path: Pyraview.mltbx | |
| release: | |
| name: Create GitHub Release | |
| needs: [build_and_test, package-matlab] | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Required to create releases | |
| steps: | |
| - name: Download All Artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: release-assets | |
| merge-multiple: true | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: release-assets/* | |
| name: Release ${{ github.ref_name }} | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |