Repository navigation
feat: allow opt-in for new backends #281
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 | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ '**' ] | |
| env: | |
| TAGS: "-tags=ci" | |
| COVERAGE: "-coverpkg=github.com/go-python/gopy/..." | |
| # Init() in main_test will make sure all backends are available if | |
| # GOPY_TRAVIS_CI is set | |
| GOPY_TRAVIS_CI: 1 | |
| GOTRACEBACK: crash | |
| GO111MODULE: auto | |
| jobs: | |
| build: | |
| name: Build (${{ matrix.platform }}, Go ${{ matrix.go-version }}, Python ${{ matrix.python-version }}) | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # TODO: Consider official support matrix (OS and Go versions) and adjust this matrix accordingly | |
| go-version: [1.25.x, 1.24.x, 1.23.x, 1.22.x] | |
| platform: [ubuntu-latest, windows-latest, macos-15] | |
| python-version: ['3.11', '3.12'] | |
| runs-on: ${{ matrix.platform }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| cache: true | |
| - name: Install Linux packages | |
| if: matrix.platform == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install curl libffi-dev python3-cffi python3-pip | |
| # install pybindgen | |
| python3 -m pip install --user -U pybindgen | |
| # install goimports | |
| go install golang.org/x/tools/cmd/goimports@latest | |
| - name: Install macOS packages | |
| if: startsWith(matrix.platform, 'macos-') | |
| run: | | |
| python3 -m pip install -U pybindgen | |
| go install golang.org/x/tools/cmd/goimports@latest | |
| - name: Install Windows packages | |
| if: matrix.platform == 'windows-latest' | |
| run: | | |
| # install pybindgen and psutil (for memory tracking in tests) | |
| python -m pip install -U pybindgen psutil | |
| # install goimports | |
| go install golang.org/x/tools/cmd/goimports@latest | |
| - name: Build-Linux | |
| if: matrix.platform == 'ubuntu-latest' | |
| run: | | |
| make | |
| - name: Test Linux | |
| if: matrix.platform == 'ubuntu-latest' | |
| run: | | |
| make test | |
| - name: Build-macOS | |
| if: startsWith(matrix.platform, 'macos-') | |
| run: | | |
| make | |
| - name: Test macOS | |
| if: startsWith(matrix.platform, 'macos-') | |
| run: | | |
| make test | |
| - name: Build-Windows | |
| if: matrix.platform == 'windows-latest' | |
| run: | | |
| go build -v ./... | |
| - name: Test Windows | |
| if: matrix.platform == 'windows-latest' | |
| run: | | |
| go test -v ./... | |
| - name: Upload-Coverage | |
| if: matrix.platform == 'ubuntu-latest' | |
| uses: codecov/codecov-action@v4 | |
| # Builds and tests the opt-in cffi backend (GOPY_BACKEND=cffi). Runs beside | |
| # the main matrix, on one Go version, and stops at the first failure. | |
| cffi: | |
| name: cffi backend (${{ matrix.platform }}, Python ${{ matrix.python-version }}) | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| platform: [ubuntu-latest, windows-latest, macos-15] | |
| python-version: ['3.11', '3.12'] | |
| runs-on: ${{ matrix.platform }} | |
| env: | |
| GOPY_BACKEND: cffi | |
| # print the python stack if the process crashes, e.g. at exit | |
| PYTHONFAULTHANDLER: 1 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: pip | |
| cache-dependency-path: .github/requirements-cffi.txt | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.25.x | |
| cache: true | |
| - name: Install packages | |
| run: | | |
| python -m pip install -r .github/requirements-cffi.txt | |
| go install golang.org/x/tools/cmd/goimports@v0.29.0 | |
| - name: Build | |
| run: go build -v ./... | |
| - name: Test | |
| run: go test -v ./... | |
| # Builds and tests the opt-in pybind11 backend (GOPY_BACKEND=pybind11). | |
| # Runs beside the main matrix, on one Go version, and stops at the first | |
| # failure. Shares its cgo shim with cffi (see noAPIShim in bind/cffi.go); | |
| # what's new here is compiling a C++ file against that shim with a real | |
| # C++ compiler, so unlike the cffi job this needs no extra system packages | |
| # (a C++ compiler is already required for CGO_ENABLED=1 on every platform). | |
| pybind11: | |
| name: pybind11 backend (${{ matrix.platform }}, Python ${{ matrix.python-version }}) | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| platform: [ubuntu-latest, windows-latest, macos-15] | |
| python-version: ['3.11', '3.12'] | |
| runs-on: ${{ matrix.platform }} | |
| env: | |
| GOPY_BACKEND: pybind11 | |
| # CXX defaults to "c++" in buildPyBind11 (cmd_build.go), which isn't a | |
| # recognized command on windows-latest's MinGW toolchain (the same one | |
| # CGO_ENABLED=1 already needs there, so no extra install is needed). | |
| CXX: g++ | |
| PYTHONFAULTHANDLER: 1 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: pip | |
| cache-dependency-path: .github/requirements-pybind11.txt | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.25.x | |
| cache: true | |
| - name: Install packages | |
| run: | | |
| python -m pip install -r .github/requirements-pybind11.txt | |
| go install golang.org/x/tools/cmd/goimports@v0.29.0 | |
| - name: Build | |
| run: go build -v ./... | |
| # The skipped test is pybind11's own auto-generated TypeError wording, | |
| # which differs from pybindgen's for one case in TestHi (Person's | |
| # setters given the wrong argument type) -- a message-text difference, | |
| # not a functional one. | |
| # | |
| # -timeout raises go test's own default (10m): each test here compiles | |
| # twice (cgo, then a separate C++ step), against cffi's one, and once | |
| # measured at ~18.5s/test average on windows-latest, 32 tests alone used | |
| # 590s of the default budget. | |
| - name: Test | |
| run: go test -v -timeout=30m -skip '^TestHi$' ./... |