.github/workflows/build_package.yaml: update windows build and fix ma… #19
This file contains 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: Run Tests and Build Wheels | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
python-version: ["3.9", "3.10", "3.11", "3.12"] | |
os: [macos-latest, ubuntu-latest] # , windows-latest | |
fail-fast: false | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache pip packages | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Cache cargo crates | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
key: ${{ runner.os }}-cargo-${{ matrix.python-version }}-${{ hashFiles('**/Cargo.lock') }} | |
- uses: actions/cache@v2 | |
if: matrix.os == 'windows-latest' | |
with: | |
path: ./vcpkg | |
key: vcpkg-openblas | |
- uses: Swatinem/rust-cache@v2 | |
continue-on-error: true | |
- name: Install maturin on Linux (with patchelf) | |
if: matrix.os == 'ubuntu-latest' | |
run: pip install maturin[patchelf] | |
- name: Install maturin on non-linux (without patchelf) | |
if: matrix.os != 'ubuntu-latest' | |
run: pip install maturin | |
- name: Install OpenBLAS on Linux | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libopenblas-dev | |
- name: Install OpenBLAS on macOS | |
if: matrix.os == 'macos-latest' | |
run: brew install openblas gcc gfortran | |
- name: Set up vcpkg | |
if: matrix.os == 'windows-latest' | |
run: | | |
git clone https://github.com/Microsoft/vcpkg.git --depth 1 | |
cd vcpkg | |
.\bootstrap-vcpkg.bat | |
shell: cmd | |
- name: Install OpenBLAS by vcpkg | |
if: matrix.os == 'windows-latest' | |
run: | | |
./vcpkg/vcpkg.exe install openblas:x64-windows-static | |
- name: Set VCPKG_ROOT environment variable on Windows | |
if: matrix.os == 'windows-latest' | |
run: | | |
setx VCPKG_ROOT "%cd%\vcpkg" | |
setx PATH "%PATH%;%cd%\vcpkg\installed\x64-windows\bin" | |
shell: cmd | |
# - name: Setup GNU Fortran | |
# if: matrix.os != 'ubuntu-latest' | |
# uses: fortran-lang/setup-fortran@v1 | |
# with: | |
# compiler: gcc | |
# version: 13 | |
- name: Set Fortran Compiler and Linker Flags on macOS | |
if: matrix.os == 'macos-latest' | |
run: | | |
export FC=$(brew --prefix)/bin/gfortran | |
export LDFLAGS="-L$(brew --prefix)/lib -lgfortran" | |
export LD_LIBRARY_PATH=$(brew --prefix)/lib | |
echo "export FC=$(brew --prefix)/bin/gfortran" >> $GITHUB_ENV | |
echo "export LDFLAGS=-L$(brew --prefix)/lib" >> $GITHUB_ENV | |
echo "export LD_LIBRARY_PATH=$(brew --prefix)/lib" >> $GITHUB_ENV | |
- name: Run cargo tests | |
run: cargo test | |
env: | |
OPENBLAS_DIR: ${{ matrix.os == 'windows-latest' && '%VCPKG_ROOT%/installed/x64-windows' || '/usr/local/opt/openblas' }} | |
- name: Run cargo clippy | |
run: cargo clippy --all -- -D warnings | |
env: | |
OPENBLAS_DIR: ${{ matrix.os == 'windows-latest' && '%VCPKG_ROOT%/installed/x64-windows' || '/usr/local/opt/openblas' }} | |
- name: Build wheels with maturin on macOS | |
if: matrix.os == 'macos-latest' | |
run: | | |
maturin build --release --out dist | |
env: | |
OPENBLAS_DIR: /usr/local/opt/openblas | |
- name: Build wheels with maturin on Linux | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
maturin build --release --out dist | |
env: | |
OPENBLAS_DIR: /usr/lib/x86_64-linux-gnu | |
- name: Build wheels with maturin on Windows | |
if: matrix.os == 'windows-latest' | |
run: | | |
maturin build --release --out dist | |
env: | |
OPENBLAS_DIR: "%VCPKG_ROOT%/installed/x64-windows" | |
- name: Install the built package | |
run: | | |
pip install --find-links dist . | |
- name: Install pytest | |
run: | | |
pip install pytest | |
- name: Run tests | |
run: | | |
pytest | |
env: | |
PYTHONPATH: . | |
- name: Upload wheel artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: wheels-${{ matrix.os }}-${{ matrix.python-version }} | |
path: dist | |
release: | |
name: Release and Publish | |
runs-on: ubuntu-latest | |
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} | |
needs: build | |
permissions: | |
id-token: write | |
contents: write | |
attestations: write | |
steps: | |
- uses: actions/download-artifact@v4 | |
- name: Setup Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: cargo-release Cache | |
id: cargo_release_cache | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cargo/bin/cargo-release | |
key: ${{ runner.os }}-cargo-release | |
- name: Install cargo-release | |
run: cargo install cargo-release | |
if: steps.cargo_release_cache.outputs.cache-hit != 'true' | |
- name: cargo login | |
run: cargo login ${{ secrets.CRATES_IO_API_TOKEN }} | |
- name: Publish crate to crates.io | |
run: | | |
cargo release publish \ | |
--workspace \ | |
--all-features \ | |
--allow-branch HEAD \ | |
--no-confirm \ | |
--execute | |
- name: Publish to PyPI | |
if: "startsWith(github.ref, 'refs/tags/')" | |
uses: PyO3/maturin-action@v1 | |
env: | |
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
with: | |
command: upload | |
args: --non-interactive --skip-existing wheels-*/* |