ci: Use geant4 conda in CI on more platforms #830
Workflow file for this run
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: Build and Test | |
on: | |
schedule: | |
- cron: 0 */24 * * * | |
workflow_dispatch: | |
pull_request: | |
push: | |
branches: [main] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
GEANT4_VERSION: 11.2.2 | |
XERCES_VERSION: 3.2.5 | |
CPP_STANDARD: 17 | |
Geant4_DIR: ${{ github.workspace }}/geant4 | |
jobs: | |
install-with-geant4-from-conda: | |
name: Install dependencies with conda | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 60 | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
defaults: | |
run: | |
shell: bash -l {0} | |
steps: | |
- name: Setup conda | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
auto-update-conda: true | |
python-version: 3.12 | |
- name: Install Geant4 and cmake using conda | |
run: | | |
conda install -c conda-forge cmake geant4=${{ env.GEANT4_VERSION }} | |
- name: Install additional dependencies | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
conda install -c conda-forge ninja gxx_linux-64 | |
- name: Print versions | |
run: | | |
conda --version | |
cmake --version | |
geant4-config --version | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: pip install the package from source | |
run: | | |
python -m pip install . | |
python -c "import geant4_python_application; print(geant4_python_application.version)" | |
- name: Run tests | |
run: | | |
python -m pytest -vv --reruns 3 --reruns-delay 30 --only-rerun "(?i)http|timeout|connection|socket|resolve" | |
- name: Run example notebooks | |
if: matrix.os == 'macos-latest' # notebooks are already run on ubuntu-latest in another step | |
run: | | |
python -m pip install jupyter nbconvert matplotlib | |
for notebook in $(find examples -name '*.ipynb'); do | |
jupyter nbconvert --to notebook --execute --inplace $notebook | |
done | |
build-geant4: | |
name: Build Geant4 on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 120 | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- name: Setup CMake | |
uses: lukka/get-cmake@v3.30.3 | |
- name: Cache Xerces-C Installation | |
id: cache-xerces | |
uses: actions/cache@v4 | |
with: | |
path: ${{ github.workspace }}/xerces | |
key: xerces-v${{ env.XERCES_VERSION }}-cpp${{ env.CPP_STANDARD }} | |
- name: Build and Install Xerces-C | |
if: steps.cache-xerces.outputs.cache-hit != 'true' | |
run: | | |
git clone https://github.com/apache/xerces-c.git xerces-source | |
git -C xerces-source checkout tags/v${{ env.XERCES_VERSION }} | |
cmake -B xerces-build -S xerces-source -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/xerces -DCMAKE_CXX_STANDARD=${{ env.CPP_STANDARD }} -DBUILD_SHARED_LIBS=OFF ${{ matrix.os == 'windows-latest' && '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_CXX_FLAGS_RELEASE="/MT"' || '-G Ninja -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -Dnetwork-accessor=socket -Dtranscoder=iconv' }} | |
cmake --build xerces-build --parallel $(nproc) --config Release --target install | |
- name: Cache Geant4 Installation | |
id: cache-geant4 | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.Geant4_DIR }} | |
key: geant4-v${{ env.GEANT4_VERSION }}-cpp${{ env.CPP_STANDARD }} | |
- name: Build and Install Geant4 (without datasets) | |
if: steps.cache-geant4.outputs.cache-hit != 'true' | |
run: | | |
git clone https://github.com/Geant4/geant4.git ${{ github.workspace }}/geant4-source --depth 1 --branch v${{ env.GEANT4_VERSION }} | |
cmake -B geant4-build -S geant4-source -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${{ env.Geant4_DIR }} -DXERCESC_ROOT_DIR=${{ github.workspace }}/xerces -DCMAKE_CXX_STANDARD=${{ env.CPP_STANDARD }} -DGEANT4_USE_GDML=ON -DGEANT4_INSTALL_EXAMPLES=OFF -DGEANT4_INSTALL_DATA=OFF -DGEANT4_BUILD_TLS_MODEL=global-dynamic -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF ${{ matrix.os == 'windows-latest' && '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_CXX_FLAGS_RELEASE="/MT"' || '-G Ninja -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -DGEANT4_USE_SYSTEM_EXPAT=OFF' }} | |
cmake --build geant4-build --parallel $(nproc) --config Release --target install | |
install-geant4-datasets: | |
name: Download Geant4 datasets for ${{ matrix.os }} | |
needs: [build-geant4] | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 30 | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- name: Cache Geant4 Installation | |
id: cache-geant4 | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.Geant4_DIR }} | |
key: geant4-v${{ env.GEANT4_VERSION }}-cpp${{ env.CPP_STANDARD }} | |
fail-on-cache-miss: true | |
- name: Cache Geant4 Datasets | |
id: cache-geant4-data | |
uses: actions/cache@v4 | |
with: | |
path: ${{ github.workspace }}/geant4-data | |
key: geant4-${{ env.GEANT4_VERSION }}-data | |
enableCrossOsArchive: true | |
lookup-only: true | |
- name: Move Geant4 datasets (Ubuntu/MacOS) | |
if: | |
steps.cache-geant4-data.outputs.cache-hit != 'true' && matrix.os != | |
'windows-latest' | |
shell: bash | |
run: | | |
bash ${{ env.Geant4_DIR }}/bin/geant4-config --install-datasets | |
bash ${{ env.Geant4_DIR }}/bin/geant4-config --check-datasets | |
mv ${{ env.Geant4_DIR }}/share/Geant4/data ${{ github.workspace }}/geant4-data | |
- name: Move Geant4 datasets (Windows) | |
if: | |
steps.cache-geant4-data.outputs.cache-hit != 'true' && matrix.os == | |
'windows-latest' | |
shell: powershell | |
run: | | |
Get-ChildItem -Path ${{ env.Geant4_DIR }}\bin | |
cmd /c ${{ env.Geant4_DIR }}\bin\geant4-config.cmd --install-datasets | |
cmd /c ${{ env.Geant4_DIR }}\bin\geant4-config.cmd --check-datasets | |
Move-Item ${{ env.Geant4_DIR }}\share\Geant4\data ${{ github.workspace }}\geant4-data | |
build-test: | |
name: | |
Build and Test for ${{ matrix.os }} (Python ${{ matrix.python-version }}) | |
needs: [install-geant4-datasets] | |
timeout-minutes: 30 | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: | |
- "3.8" | |
- "3.9" | |
- "3.10" | |
- "3.11" | |
- "3.12" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Setup CMake | |
uses: lukka/get-cmake@v3.30.3 | |
- name: Setup Windows environment variables | |
if: matrix.os == 'windows-latest' | |
shell: bash | |
run: | | |
echo "CMAKE_ARGS=-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded" >> $GITHUB_ENV | |
- name: Cache Xerces-C Installation | |
id: cache-xerces | |
uses: actions/cache@v4 | |
with: | |
path: ${{ github.workspace }}/xerces | |
key: xerces-v${{ env.XERCES_VERSION }}-cpp${{ env.CPP_STANDARD }} | |
fail-on-cache-miss: true | |
- name: Cache Geant4 Installation | |
id: cache-geant4 | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.Geant4_DIR }} | |
key: geant4-v${{ env.GEANT4_VERSION }}-cpp${{ env.CPP_STANDARD }} | |
fail-on-cache-miss: true | |
- name: pip install the package | |
run: | | |
python -m pip install .[test] | |
git tag | |
python -c "import geant4_python_application; print(geant4_python_application.version)" | |
# test ability to download datasets in one job and use the cache in the others | |
- name: Cache Geant4 Datasets | |
if: matrix.python-version != '3.11' | |
id: cache-geant4-data | |
uses: actions/cache@v4 | |
with: | |
path: ${{ github.workspace }}/geant4-data | |
key: geant4-${{ env.GEANT4_VERSION }}-data | |
fail-on-cache-miss: true | |
enableCrossOsArchive: true | |
- name: Move Geant4 datasets (Ubuntu/MacOS) | |
if: matrix.python-version != '3.11' && matrix.os != 'windows-latest' | |
run: | | |
GEANT4_DATA_DIR=$(python -c "import geant4_python_application; print(geant4_python_application.data_directory())") | |
mkdir -p ${{ github.workspace }}/geant4-data "$GEANT4_DATA_DIR" | |
mv ${{ github.workspace }}/geant4-data/* "$GEANT4_DATA_DIR" | |
# TODO: unify this with the above | |
- name: Move Geant4 datasets (Windows) | |
if: matrix.python-version != '3.11' && matrix.os == 'windows-latest' | |
shell: powershell | |
run: | | |
$env:GEANT4_DATA_DIR = python -c "import geant4_python_application; print(geant4_python_application.data_directory())" | |
New-Item -ItemType Directory -Path "${{ github.workspace }}\geant4-data" -Force | |
New-Item -ItemType Directory -Path $env:GEANT4_DATA_DIR -Force | |
Move-Item "${{ github.workspace }}\geant4-data\*" $env:GEANT4_DATA_DIR -Force | |
- name: Install datasets | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_minutes: 30 | |
retry_wait_seconds: 60 | |
max_attempts: 5 | |
command: | | |
python -c "import geant4_python_application as g4; g4.install_datasets()" | |
# Check that the datasets are installed correctly | |
python -c "import geant4_python_application as g4; g4.files.datasets.check_datasets(throw=True)" | |
- name: Run tests | |
run: | | |
python -m pytest -vv --reruns 3 --reruns-delay 30 --only-rerun "(?i)http|timeout|connection|socket|resolve" | |
- name: Run example notebooks | |
if: matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest' | |
run: | | |
python -m pip install jupyter nbconvert matplotlib | |
for notebook in $(find examples -name '*.ipynb'); do | |
jupyter nbconvert --to notebook --execute --inplace $notebook | |
done |