CI-unittests #3622
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: CI-unittests | |
# Execute unit tests | |
# (includes CTAO-DPPS-SonarQube) | |
env: | |
SIMTOOLS_DB_SERVER: ${{ secrets.DB_SERVER }} | |
SIMTOOLS_DB_API_USER: ${{ secrets.DB_API_USER }} | |
SIMTOOLS_DB_API_PW: ${{ secrets.DB_API_PW }} | |
SIMTOOLS_DB_API_PORT: ${{ secrets.DB_API_PORT }} | |
SIMTOOLS_DB_SIMULATION_MODEL: "CTAO-Simulation-Model-LATEST" | |
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: [opened, synchronize] | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
unittests: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- os: macos-latest | |
python-version: "3.11" | |
install-method: mamba | |
- os: ubuntu-latest | |
python-version: "3.11" | |
install-method: mamba | |
extra-args: ["codecov", "random-order"] | |
- os: ubuntu-latest | |
python-version: "3.11" | |
install-method: pip | |
- os: ubuntu-latest | |
python-version: "3.12" | |
install-method: mamba | |
defaults: | |
run: | |
shell: bash -leo pipefail {0} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Prepare mamba installation | |
if: matrix.install-method == 'mamba' | |
env: | |
PYTHON_VERSION: ${{ matrix.python-version }} | |
run: | | |
# setup correct python version | |
sed -i -e "s/- python=.*/- python=$PYTHON_VERSION/g" environment.yml | |
- name: Install mamba dependencies | |
if: matrix.install-method == 'mamba' | |
uses: mamba-org/setup-micromamba@v2 | |
with: | |
environment-file: environment.yml | |
create-args: python=${{ matrix.python-version }} | |
init-shell: bash | |
- name: Python setup | |
if: matrix.install-method == 'pip' | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
check-latest: true | |
- if: ${{ matrix.install-method == 'pip' && runner.os == 'macOS' }} | |
name: Fix Python PATH on macOS | |
# from https://github.com/cta-observatory/ctapipe/blob/cfacbe1eeb2d9a4634980e5f1ef39b944bca6a7a/.github/workflows/ci.yml#L100 | |
run: | | |
tee -a "$HOME/.bash_profile" <<< "export PATH=$pythonLocation/bin:$PATH" | |
- name: Python dependencies (pip) | |
if: matrix.install-method == 'pip' | |
run: | | |
pip install '.[tests,dev,doc]' | |
- name: Python dependencies (mamba) | |
if: matrix.install-method == 'mamba' | |
run: | | |
pip install -e '.[tests,dev,doc]' | |
- name: Unit tests | |
shell: bash -l {0} | |
run: | | |
pytest --durations=10 --color=yes -n auto --dist loadscope \ | |
--cov=simtools --cov-report=xml | |
# CTAO-DPPS-SonarQube | |
- uses: SonarSource/[email protected] | |
if: contains(matrix.extra-args, 'codecov') | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
- name: Random order | |
if: github.event_name == 'schedule' && contains(matrix.extra-args, 'random-order') | |
shell: bash -l {0} | |
run: | | |
pytest --color=yes -n auto --dist loadscope --count 5 --random-order | |
- name: Upload coverage report to codecov | |
uses: codecov/codecov-action@v5 | |
if: contains(matrix.extra-args, 'codecov') | |
with: | |
token: ${{ secrets.CODECOV_SIMTOOLS_TOKEN }} |