Build and Publish Bindings #3
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 Publish Bindings | |
| on: | |
| workflow_run: | |
| workflows: ["Release"] | |
| types: [completed] | |
| workflow_dispatch: | |
| inputs: | |
| publish: | |
| description: 'Publish to package registries' | |
| required: false | |
| default: 'false' | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build-native: | |
| name: Build Native Libraries | |
| # Only run if Release workflow succeeded (or manual trigger) | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| artifact: libundoc.so | |
| runtime: linux-x64 | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| artifact: undoc.dll | |
| runtime: win-x64 | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| artifact: libundoc.dylib | |
| runtime: osx-x64 | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| artifact: libundoc.dylib | |
| runtime: osx-arm64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Build native library | |
| run: cargo build --release --target ${{ matrix.target }} --features ffi | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: native-${{ matrix.runtime }} | |
| path: target/${{ matrix.target }}/release/${{ matrix.artifact }} | |
| retention-days: 7 | |
| build-python: | |
| name: Build Python Wheels | |
| needs: build-native | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| python-version: ['3.9', '3.10', '3.11', '3.12'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Download Linux native library | |
| if: matrix.os == 'ubuntu-latest' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-linux-x64 | |
| path: bindings/python/src/undoc/lib/linux-x64/ | |
| - name: Download Windows native library | |
| if: matrix.os == 'windows-latest' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-win-x64 | |
| path: bindings/python/src/undoc/lib/win-x64/ | |
| - name: Download macOS x64 native library | |
| if: matrix.os == 'macos-latest' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-osx-x64 | |
| path: bindings/python/src/undoc/lib/osx-x64/ | |
| - name: Download macOS ARM64 native library | |
| if: matrix.os == 'macos-latest' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-osx-arm64 | |
| path: bindings/python/src/undoc/lib/osx-arm64/ | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build wheel | |
| - name: Build wheel | |
| working-directory: bindings/python | |
| run: python -m build | |
| - name: Upload wheel | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-wheel-${{ matrix.os }}-py${{ matrix.python-version }} | |
| path: bindings/python/dist/*.whl | |
| retention-days: 7 | |
| build-nuget: | |
| name: Build NuGet Package | |
| needs: build-native | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - name: Create runtime directories | |
| run: | | |
| mkdir -p bindings/csharp/Undoc/runtimes/win-x64/native | |
| mkdir -p bindings/csharp/Undoc/runtimes/linux-x64/native | |
| mkdir -p bindings/csharp/Undoc/runtimes/osx-x64/native | |
| mkdir -p bindings/csharp/Undoc/runtimes/osx-arm64/native | |
| - name: Download Windows native library | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-win-x64 | |
| path: bindings/csharp/Undoc/runtimes/win-x64/native/ | |
| - name: Download Linux native library | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-linux-x64 | |
| path: bindings/csharp/Undoc/runtimes/linux-x64/native/ | |
| - name: Download macOS x64 native library | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-osx-x64 | |
| path: bindings/csharp/Undoc/runtimes/osx-x64/native/ | |
| - name: Download macOS ARM64 native library | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-osx-arm64 | |
| path: bindings/csharp/Undoc/runtimes/osx-arm64/native/ | |
| - name: Build NuGet package | |
| working-directory: bindings/csharp | |
| run: dotnet pack Undoc/Undoc.csproj -c Release -o ./artifacts | |
| - name: Upload NuGet package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: bindings/csharp/artifacts/*.nupkg | |
| retention-days: 7 | |
| publish-pypi: | |
| name: Publish to PyPI | |
| needs: build-python | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.inputs.publish == 'true' }} | |
| steps: | |
| - name: Download all Python wheels | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: python-wheel-* | |
| path: dist/ | |
| merge-multiple: true | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| packages-dir: dist/ | |
| skip-existing: true | |
| publish-nuget: | |
| name: Publish to NuGet | |
| needs: build-nuget | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.inputs.publish == 'true' }} | |
| steps: | |
| - name: Download NuGet package | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ./ | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - name: Publish to NuGet | |
| run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.NUGET_API_TOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| test-python: | |
| name: Test Python Bindings | |
| needs: build-python | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| python-version: ['3.11'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Download wheel | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-wheel-${{ matrix.os }}-py${{ matrix.python-version }} | |
| path: ./wheels/ | |
| - name: Install package | |
| shell: bash | |
| run: | | |
| pip install pytest | |
| pip install ./wheels/*.whl | |
| - name: Run tests | |
| working-directory: bindings/python | |
| shell: bash | |
| run: pytest tests/ -v --ignore=tests/test_integration.py | |
| test-nuget: | |
| name: Test NuGet Package | |
| needs: build-nuget | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| artifact: native-linux-x64 | |
| runtime: linux-x64 | |
| - os: windows-latest | |
| artifact: native-win-x64 | |
| runtime: win-x64 | |
| - os: macos-latest | |
| artifact: native-osx-x64 | |
| runtime: osx-x64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - name: Download NuGet package | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ./packages/ | |
| - name: Download native library | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact }} | |
| path: ./native-lib/ | |
| - name: Create local NuGet source | |
| run: dotnet nuget add source "${{ github.workspace }}/packages" -n local | |
| - name: Build test project | |
| working-directory: bindings/csharp | |
| run: dotnet build Undoc.Tests/Undoc.Tests.csproj -c Release | |
| - name: Copy native library to test output (Unix) | |
| if: matrix.os != 'windows-latest' | |
| shell: bash | |
| run: | | |
| find bindings/csharp/Undoc.Tests/bin/Release -type d -name "net*" | while read dir; do | |
| cp ./native-lib/* "$dir/" | |
| echo "Copied native library to $dir" | |
| done | |
| - name: Copy native library to test output (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| Get-ChildItem -Path "bindings/csharp/Undoc.Tests/bin/Release" -Directory -Recurse | Where-Object { $_.Name -like "net*" } | ForEach-Object { | |
| Copy-Item "./native-lib/*" -Destination $_.FullName -Force | |
| Write-Host "Copied native library to $($_.FullName)" | |
| } | |
| - name: Run tests | |
| working-directory: bindings/csharp | |
| run: dotnet test Undoc.Tests/Undoc.Tests.csproj -c Release --no-build |