-
Notifications
You must be signed in to change notification settings - Fork 234
246 lines (234 loc) · 8.9 KB
/
core.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
name: Tests
on:
push:
branches:
- main
- '*_rel'
schedule:
# run daily at 5:00 am UTC (12 am ET/9 pm PT)
- cron: '0 5 * * *'
repository_dispatch:
# to run this, send a POST API call at repos/IDAES/idaes-pse/dispatches with the specified event_type
# e.g. `gh repos/IDAES/idaes-pse/dispatches -F event_type=ci_run_tests`
types: [ci_run_tests]
workflow_dispatch:
inputs:
git-ref:
description: Git hash (optional)
required: false
pull_request:
types:
- opened
# ready_for_review occurs when a draft PR is turned to non-draft
- ready_for_review
# synchronize occurs whenever commits are pushed to the PR branch
- synchronize
concurrency:
# NOTE: the value of `group` should be chosen carefully,
# otherwise we might end up over- or under-canceling workflow runs
# e.g. if we want to have Codecov results for each commit on `main`,
# we should use something `github.sha` instead of `github.ref_name`
# to avoid over-canceling runs from `main`
# in which case we'd need to access the PR number from somewhere else rather than `github.ref_name`
# to avoid under-canceling runs from PRs
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
env:
# default Python version to use for checks that do not require multiple versions
DEFAULT_PYTHON_VERSION: '3.10'
IDAES_CONDA_ENV_NAME_DEV: idaes-pse-dev
PYTEST_ADDOPTS: "--color=yes"
defaults:
run:
# -l: login shell, needed when using Conda run:
shell: bash -l {0}
jobs:
code-formatting:
name: Check code formatting (Black)
# OS and/or Python version don't make a difference, so we choose ubuntu and 3.10 for performance
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Install Black
# unlike the other jobs, we don't need to install IDAES 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: |
# we store the version
black_requirement="$(grep 'black==' requirements-dev.txt)"
pip --no-cache-dir install --progress-bar off "$black_requirement"
- name: Run Black to verify that the committed code is formatted
run: |
black --check .
spell-check:
name: Check Spelling
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Run Spell Checker
uses: crate-ci/[email protected]
with:
config: ./.github/workflows/typos.toml
pytest:
# description: Run pytest with dev dependencies
name: pytest (py${{ matrix.python-version }}/${{ matrix.os }})
runs-on: ${{ matrix.runner-image }}
needs: [code-formatting, spell-check]
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
os:
- linux
- win64
include:
- os: linux
runner-image: ubuntu-20.04
- os: win64
runner-image: windows-2022
- python-version: '3.11'
# only generate coverage report for a single python version in the matrix
# to avoid overloading Codecov
cov-report: true
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/display-debug-info
- name: Set up Conda environment
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.IDAES_CONDA_ENV_NAME_DEV }}
python-version: ${{ matrix.python-version }}
- name: Set up idaes
uses: ./.github/actions/setup-idaes
with:
install-target: -r requirements-dev.txt
- name: Add pytest CLI options for coverage
if: matrix.cov-report
run: |
echo PYTEST_ADDOPTS="$PYTEST_ADDOPTS --cov --cov-report=xml" >> "$GITHUB_ENV"
- name: Run pytest (not integration)
run: |
pytest --pyargs idaes -m "not integration"
- name: Upload coverage report as GHA workflow artifact
if: matrix.cov-report
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.os }}
path: coverage.xml
if-no-files-found: error
upload-coverage:
name: Upload coverage report (Codecov)
needs: [pytest]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
report-variant: ["linux", "win64"]
steps:
# the checkout step is needed to have access to codecov.yml
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: coverage-report-${{ matrix.report-variant }}
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
verbose: true
# NOTE: secrets are not available for pull_request workflows
# However, as of 2024-02-10, Codecov is still allowing tokenless upload from PRs
# but does require token for other workflows e.g. merge to `main`
# see https://github.com/codecov/codecov-action/issues/1274#issuecomment-1934437359
token: ${{ secrets.CODECOV_TOKEN }}
# pinning version after v0.7.0 broke tokenless upload
# see codecov/codecov-action#1487
version: v0.7.1
build-docs:
name: Build Sphinx docs
runs-on: ubuntu-latest
needs: [code-formatting, spell-check]
steps:
- uses: actions/checkout@v4
- name: Set up Conda environment
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.IDAES_CONDA_ENV_NAME_DEV }}
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Set up idaes
uses: ./.github/actions/setup-idaes
with:
install-target: -r requirements-dev.txt
- name: Build Sphinx docs
run: |
which python
cd docs/
python build.py --timeout 600
- name: Publish built docs
uses: actions/upload-artifact@v4
with:
name: idaes-pse-docs-html
path: docs/build/html/
retention-days: 7
pylint:
name: Pylint
runs-on: ubuntu-latest
needs: [code-formatting, spell-check]
env:
pylint_target_dir: idaes/
pylint_output_path: pylint.json
pylint_todo_sentinel: PYLINT-TODO
steps:
- uses: actions/checkout@v4
# NOTE: using Conda instead of actions/setup-python in this job is not strictly necessary
# as it doesn't need to run on Windows or use the setup-idaes local action,
# but we do it for consistency with the other jobs
- name: Set up Conda environment
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.IDAES_CONDA_ENV_NAME_DEV }}
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Set up idaes
uses: ./.github/actions/setup-idaes
with:
install-target: -r requirements-dev.txt
- name: Run pylint
run: |
echo "::group::Display pylint version"
pip show pylint astroid
echo "::endgroup::"
pylint --rcfile=./.pylint/pylintrc --disable=R --output-format=idaes_reporters.DisplayProgress,colorized,idaes_reporters.GHACheckAnnotations:pylint.txt "$pylint_target_dir"
- name: Generate GHA Check Annotations from Pylint report
if: success() || failure()
run: |
cat pylint.txt || echo "GHA-compatible Pylint report not found"
- name: Show PYLINT-TODO comments left in the codebase
if: always()
run: |
# use a bash array to save options containing quotes to a variable, then use the double-quoted array expansion "${arr[@]}"
grep_opts=( --recursive --include '*.py' --color=always --after-context=2 --line-number --initial-tab )
grep "$pylint_todo_sentinel" "${grep_opts[@]}" "$pylint_target_dir" || echo "No \"$pylint_todo_sentinel\" comments found in $pylint_target_dir"
compat:
name: Compatibility tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up Conda environment
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.IDAES_CONDA_ENV_NAME_DEV }}
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Set up idaes
uses: ./.github/actions/setup-idaes
with:
install-target: -r requirements-dev.txt
- name: Create empty pytest.ini file
run: |
echo "" > pytest.ini
- name: Install and run compatibility tests
run: |
pip install "git+https://github.com/IDAES/[email protected]"
pytest --pyargs idaes_compatibility