-
Notifications
You must be signed in to change notification settings - Fork 5
163 lines (155 loc) · 5.18 KB
/
checks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Checks
on:
push:
branches: [main]
tags: ['*']
pull_request:
branches: [main]
env:
PYTEST_ADDOPTS: --color=yes
PIP_PROGRESS_BAR: "off"
defaults:
run:
# -l: login shell, needed when using Conda:
shell: bash -l {0}
jobs:
code-formatting:
name: Check code is formatted (Black)
# OS and/or Python version don't make a difference, so we choose ubuntu and 3.12 as defaults
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Black
# unlike the other jobs, we don't need to install WaterTAP and/or all the dev dependencies,
# but we still want to specify the Black version to use in requirements-dev.txt for local development
# so we extract the relevant line and pass it to a simple `pip install`
run: |
black_requirement="$(grep '^black==' requirements-dev.txt)"
pip install "$black_requirement"
- name: Run Black to verify that the committed code is formatted
run: |
black --check .
pytest:
name: pytest (${{ matrix.os }}/${{ matrix.python-version }}/${{ matrix.install-mode }})
runs-on: ${{ matrix.os-version }}
needs: [code-formatting]
strategy:
fail-fast: false
matrix:
install-mode:
- dev
- standard
python-version:
- "3.9"
- "3.10"
- "3.11"
os:
- linux
- win64
include:
- os: linux
os-version: ubuntu-22.04
- os: win64
os-version: windows-2022
- install-mode: dev
python-version: "3.11" # choice of Python version is arbitrary among those in matrix
coverage: "true"
- install-mode: dev
python-version: "3.10"
mpi: "true"
steps:
- if: matrix.install-mode == 'dev'
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
miniforge-version: latest
python-version: ${{ matrix.python-version }}
activate-environment: ${{ matrix.install-mode == 'dev' && 'parameter-sweep-dev' || 'parameter-sweep' }}
- if: matrix.install-mode == 'dev'
name: Install (dev)
env:
SETUPTOOLS_SCM_DEBUG: "1"
run: |
pip install build
python -c "import build.util; print(build.util.project_wheel_metadata('.')['Version'])"
pip install -r requirements-dev.txt
- if: matrix.install-mode == 'standard'
name: Install (standard)
run: |
pip install "git+${{ format('{0}/{1}@{2}', github.server_url, github.repository, github.ref) }}"
- name: Set up IDAES solvers
run: |
idaes get-extensions --verbose
- if: matrix.coverage
name: Enable coverage for pytest
run: echo PYTEST_ADDOPTS="$PYTEST_ADDOPTS --cov --cov-report=xml" >> $GITHUB_ENV
- name: Run pytest
run: |
pip install pytest # ensure pytest is installed (should do nothing if already present from requirements-dev.txt)
pytest --pyargs parameter_sweep
- name: Upload coverage report as job artifact
if: matrix.coverage
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.os }}
path: coverage.xml
if-no-files-found: error
- if: matrix.mpi
name: Collect coverage for MPI-using code
run: |
conda install --quiet --yes mpi4py
mpiexec -n 2 \
coverage run --parallel-mode \
-m mpi4py -m pytest \
src/parameter_sweep/tests/test*parameter_sweep.py \
src/parameter_sweep/loop_tool/tests/test*loop_tool.py \
--no-cov
# merge into single report
coverage combine
# convert to XML
coverage xml
- name: Upload coverage report as job artifact
if: matrix.mpi
uses: actions/upload-artifact@v4
with:
name: coverage-report-mpi-${{ matrix.os }}
path: coverage.xml
if-no-files-found: error
upload-coverage:
name: Upload coverage report (Codecov)
needs: [pytest]
runs-on: ubuntu-latest
steps:
# the checkout step is needed to have access to codecov.yml
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: coverage-report-*
- name: Upload coverage report to Codecov (token)
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
# downgrading after v0.7.0 broke tokenless upload
# see codecov/codecov-action#1487
version: v0.6.0
build-docs:
name: Build docs (Sphinx)
needs: [code-formatting]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install -r requirements-dev.txt
- run: make -C docs html