Skip to content

CI: build macos & windows #496

CI: build macos & windows

CI: build macos & windows #496

Workflow file for this run

name: CI
on:
push:
branches: [main]
tags: ['v**']
paths-ignore:
- '**/*.md'
pull_request: {branches: [main]}
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: 'false'
defaults: {run: {shell: 'bash -el {0}'}} # https://github.com/marketplace/actions/setup-miniconda#important
env:
YARDL_VERSION: 0.6.7
jobs:
build:
strategy:
matrix:
cppVersion: [17]
os: [ubuntu, windows, macos]
fail-fast: false
environment: pypi
permissions: {contents: write, id-token: write}
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v7
with: {fetch-depth: 0, submodules: recursive}
- name: strip environment.yml
run: |
cat environment.yml | grep -Ev "#.*local" > temp-ci-environment.yml
- uses: conda-incubator/setup-miniconda@v4
with:
activate-environment: yardl
environment-file: temp-ci-environment.yml
- id: yardl
name: Install yardl
run: |
rm temp-ci-environment.yml # cleanup temporary file from previous step
if test ${{ matrix.os }} = windows; then
DL_SUFFIX=_windows_x86_64.zip
elif test ${{ matrix.os }} = macos; then
DL_SUFFIX=_darwin_arm64.tar.gz
else
DL_SUFFIX=_linux_x86_64.tar.gz
fi
echo "suffix=$DL_SUFFIX" >> $GITHUB_ENV
gh release download -R microsoft/yardl -p "*$DL_SUFFIX" v$YARDL_VERSION
mkdir yardl
if test ${{ matrix.os }} = windows; then
unzip "yardl_${YARDL_VERSION}${DL_SUFFIX}" -d yardl
else
tar -xzf "yardl_${YARDL_VERSION}${DL_SUFFIX}" -C yardl
fi
rm "yardl_${YARDL_VERSION}${DL_SUFFIX}"
echo "$PWD/yardl" >> "$GITHUB_PATH"
env:
GH_TOKEN: ${{ github.token }}
# Enable tmate debugging of manually-triggered workflows if the input option was provided
- name: Setup tmate session if triggered
#if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 30
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled != 'false' }}
- name: Build model
run: just generate
- name: Run Python
run: just run-python
- name: Build cpp
run: |
export HDF5_ROOT="$CONDA_PREFIX"
export CMAKE_PREFIX_PATH="$CONDA_PREFIX/Library:$CONDA_PREFIX"
just cmake_install_prefix="$PWD/cpp/install" build-cpp
echo CMAKE_PREFIX_PATH="$PWD/cpp/install:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV
- name: Run cpp
run: just run-cpp
- name: Build cpp example
run: |
just cmake_source_dir=ccp/example cmake_build_dir=cpp/example/build build-cpp
- id: prep
name: Prepare deployment
run: |
cp LICENSE.txt python/LICENSE
cp LICENSE.txt cpp/install/LICENSE
[[ "${GITHUB_REF}" == refs/tags/* ]] && tag="${GITHUB_REF#refs/tags/}" || tag=$(python -c 'import importlib.metadata as m; print(m.version("petsird"))')
tgz="petsird_${tag}${{ steps.yardl.outputs.suffix }}"
if test ${{ matrix.os }} = windows; then
cd cpp/install
zip -r "../../$tgz" .
else
tar -czf "$tgz" -C cpp/install .
fi
echo tgz="$tgz" >> $GITHUB_OUTPUT
- id: dist
uses: casperdcl/deploy-pypi@v3
with:
build: python -o dist
upload: ${{ matrix.os == 'ubuntu' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
- if: matrix.os == 'ubuntu'
uses: actions/upload-artifact@v7
with:
name: python-petsird
path: dist/**
- uses: actions/upload-artifact@v7
with:
name: cpp-petsird-${{ matrix.os }}
path: cpp/install/**
gh-release-draft:
needs: build
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v7
with:
path: dist
pattern: '*-petsird*'
merge-multiple: true
- run: ls dist # debugging
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
name: gh release create --draft
run: |
tag="${GITHUB_REF#refs/tags/}"
gh release create --draft --title "$tag" --generate-notes "$tag" dist/*.*
env:
GH_TOKEN: ${{ github.token }}