From b2feff657a5ad514dea59d3ddd335361d30d9987 Mon Sep 17 00:00:00 2001 From: jcschaff Date: Sun, 2 Jun 2024 13:03:54 -0400 Subject: [PATCH] WIP: python build CI/CD actions --- .github/workflows/conda.yml | 44 ++++++++++++++ .github/workflows/enscripten.yaml | 60 +++++++++++++++++++ .github/workflows/pip.yml | 31 ++++++++++ .github/workflows/wheels.yml | 99 +++++++++++++++++++++++++++++++ 4 files changed, 234 insertions(+) create mode 100644 .github/workflows/conda.yml create mode 100644 .github/workflows/enscripten.yaml create mode 100644 .github/workflows/pip.yml create mode 100644 .github/workflows/wheels.yml diff --git a/.github/workflows/conda.yml b/.github/workflows/conda.yml new file mode 100644 index 00000000..fc267d8e --- /dev/null +++ b/.github/workflows/conda.yml @@ -0,0 +1,44 @@ +name: Conda + +on: + workflow_dispatch: + push: + branches: + - master + pull_request: + +jobs: + build: + strategy: + fail-fast: false + matrix: + platform: [ubuntu-latest, macos-13, macos-14, windows-latest] + python-version: ["3.8", "3.11"] + + runs-on: ${{ matrix.platform }} + + # The setup-miniconda action needs this to activate miniconda + defaults: + run: + shell: "bash -l {0}" + + steps: + - uses: actions/checkout@v4 + + - name: Get conda + uses: conda-incubator/setup-miniconda@v3.0.4 + with: + python-version: ${{ matrix.python-version }} + channels: conda-forge + + - name: Prepare + run: conda install conda-build conda-verify pytest + + - name: Build + run: conda build conda.recipe + + - name: Install + run: conda install -c ${CONDA_PREFIX}/conda-bld/ pyvcell_fvsolver + + - name: Test + run: pytest tests diff --git a/.github/workflows/enscripten.yaml b/.github/workflows/enscripten.yaml new file mode 100644 index 00000000..7a5de098 --- /dev/null +++ b/.github/workflows/enscripten.yaml @@ -0,0 +1,60 @@ +name: WASM + +on: + workflow_dispatch: + pull_request: + branches: + - master + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + build-wasm-emscripten: + name: Pyodide + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install pyodide-build + run: pip install pyodide-build==0.23.4 + + - name: Compute emsdk version + id: compute-emsdk-version + run: | + pyodide xbuildenv install --download + EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version) + echo "emsdk-version=$EMSCRIPTEN_VERSION" >> $GITHUB_OUTPUT + + - uses: mymindstorm/setup-emsdk@v14 + with: + version: ${{ steps.compute-emsdk-version.outputs.emsdk-version }} + actions-cache-folder: emsdk-cache + + # A future version of pyodide may switch to -fwasm-exceptions + - name: Build + run: CFLAGS=-fexceptions LDFLAGS=-fexceptions pyodide build + + - uses: actions/upload-artifact@v4 + with: + path: dist/*.whl + + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Set up Pyodide virtual environment + run: | + pyodide venv .venv-pyodide + .venv-pyodide/bin/pip install $(echo -n dist/*.whl)[test] + + - name: Test + run: .venv-pyodide/bin/pytest diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml new file mode 100644 index 00000000..a1f2173a --- /dev/null +++ b/.github/workflows/pip.yml @@ -0,0 +1,31 @@ +name: "Pip" + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + +jobs: + build: + name: Build with Pip + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + platform: [windows-latest, macos-13, ubuntu-latest] + python-version: ["3.7", "3.12", "pypy-3.9"] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Build and install + run: pip install --verbose ./pyvcell-fvsolver + + - name: Test + run: pytest diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml new file mode 100644 index 00000000..3fcfe235 --- /dev/null +++ b/.github/workflows/wheels.yml @@ -0,0 +1,99 @@ +name: Wheels + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + release: + types: + - published + +env: + FORCE_COLOR: 3 + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + build_sdist: + name: Build SDist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Build SDist + working-directory: pyvcell-fvsolver + run: pipx run build --sdist + + - name: Check metadata + working-directory: pyvcell-fvsolver + run: pipx run twine check dist/* + + - name: artifact upload + uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz + working-directory: pyvcell-fvsolver + + + build_wheels: + name: Wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-13, macos-14, windows-latest] + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: build wheel + uses: pypa/cibuildwheel@v2.17 + with: + working-directory: pyvcell-fvsolver + env: + CIBW_ARCHS_MACOS: universal2 + CIBW_ARCHS_WINDOWS: auto ARM64 + + - name: Verify clean directory + working-directory: pyvcell-fvsolver + run: git diff --exit-code + shell: bash + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }} + working-directory: pyvcell-fvsolver + path: wheelhouse/*.whl + + + upload_all: + name: Upload if release + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + environment: pypi + permissions: + id-token: write + + steps: + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - uses: actions/download-artifact@v4 + with: + working-directory: pyvcell-fvsolver + pattern: cibw-* + merge-multiple: true + path: dist + + - uses: pypa/gh-action-pypi-publish@release/v1