Skip to content

Commit 4c9f413

Browse files
committed
Enable GitHub Actions
Signed-off-by: Keith Battocchi <[email protected]>
1 parent d1baba1 commit 4c9f413

File tree

6 files changed

+429
-400
lines changed

6 files changed

+429
-400
lines changed

.github/workflows/ci.yml

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
name: Run all checks for pull requests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
inputs:
9+
ref:
10+
description: 'The git ref to build the package for'
11+
required: false
12+
default: ''
13+
type: string
14+
15+
# Precompute the ref if the workflow was triggered by a workflow dispatch rather than copying this logic repeatedly
16+
env:
17+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || null }}
18+
19+
jobs:
20+
eval:
21+
name: Evaluate changes
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v3
25+
name: Checkout repository
26+
with:
27+
ref: ${{ env.ref }}
28+
fetch-depth: 2
29+
30+
# We want to enforce the following rules for PRs:
31+
# * if all modifications are to README.md
32+
# no testing is needed
33+
# * if there are modifications to docs/* or to any code
34+
# then docs need to be built to verify consistency
35+
# * if there are modifications to notebooks/* or to any code
36+
# then notebooks need to be run to verify consistency
37+
# * for any code changes (or changes to metadata files)
38+
# linting and testing should be run
39+
# For a PR build, HEAD will be the merge commit, and we want to diff against the base branch,
40+
# which will be the first parent: HEAD^
41+
# (For non-PR changes, we will always perform all CI tasks)
42+
# Note that GitHub Actions provides path filters, but they operate at the workflow level, not the job level
43+
- run: |
44+
if ($env:GITHUB_EVENT_NAME -eq 'pull_request') {
45+
$editedFiles = git diff HEAD^ --name-only
46+
$editedFiles # echo edited files to enable easier debugging
47+
$codeChanges = $false
48+
$docChanges = $false
49+
$nbChanges = $false
50+
$changeType = "none"
51+
foreach ($file in $editedFiles) {
52+
switch -Wildcard ($file) {
53+
"README.md" { Continue }
54+
".gitignore" { Continue }
55+
"econml/_version.py" { Continue }
56+
"prototypes/*" { Continue }
57+
"images/*" { Continue }
58+
"doc/*" { $docChanges = $true; Continue }
59+
"notebooks/*" { $nbChanges = $true; Continue }
60+
default { $codeChanges = $true; Continue }
61+
}
62+
}
63+
}
64+
echo "buildDocs=$(($env:GITHUB_EVENT_NAME -ne 'pull_request') -or ($docChanges -or $codeChanges))" >> $env:GITHUB_OUTPUT
65+
echo "buildNbs=$(($env:GITHUB_EVENT_NAME -ne 'pull_request') -or ($nbChanges -or $codeChanges))" >> $env:GITHUB_OUTPUT
66+
echo "testCode=$(($env:GITHUB_EVENT_NAME -ne 'pull_request') -or $codeChanges)" >> $env:GITHUB_OUTPUT
67+
shell: pwsh
68+
name: Determine type of code change
69+
id: eval
70+
outputs:
71+
buildDocs: ${{ steps.eval.outputs.buildDocs }}
72+
buildNbs: ${{ steps.eval.outputs.buildNbs }}
73+
testCode: ${{ steps.eval.outputs.testCode }}
74+
75+
lint:
76+
name: Lint code
77+
needs: [eval]
78+
if: ${{ needs.eval.outputs.testCode == 'True' }}
79+
runs-on: ubuntu-latest
80+
steps:
81+
- uses: actions/checkout@v3
82+
name: Checkout repository
83+
with:
84+
ref: ${{ env.ref }}
85+
- uses: actions/setup-python@v4
86+
name: Setup Python
87+
with:
88+
python-version: 3.9
89+
- run: python -m pip install --upgrade pip && pip install --upgrade setuptools
90+
name: Ensure latest pip and setuptools
91+
- run: 'pip install pycodestyle && pycodestyle econml'
92+
93+
notebooks:
94+
name: Run notebooks
95+
needs: [eval]
96+
if: ${{ needs.eval.outputs.buildNbs == 'True' }}
97+
runs-on: ubuntu-latest
98+
strategy:
99+
matrix:
100+
kind: [except customer scenarios, customer scenarios]
101+
include:
102+
- kind: "except customer scenarios"
103+
extras: "[tf,plt]"
104+
pattern: "(?!CustomerScenarios)"
105+
install_graphviz: true
106+
version: 3.8 # no supported version of tensorflow for 3.9
107+
- kind: "customer scenarios"
108+
extras: "[plt,dowhy]"
109+
pattern: "CustomerScenarios"
110+
version: 3.9
111+
install_graphviz: false
112+
fail-fast: false
113+
steps:
114+
- uses: actions/checkout@v3
115+
name: Checkout repository
116+
with:
117+
ref: ${{ env.ref }}
118+
- uses: actions/setup-python@v4
119+
name: Setup Python
120+
with:
121+
python-version: ${{ matrix.version }}
122+
- run: python -m pip install --upgrade pip && pip install --upgrade setuptools
123+
name: Ensure latest pip and setuptools
124+
- run: sudo apt-get -yq install graphviz
125+
name: Install graphviz
126+
if: ${{ matrix.install_graphviz }}
127+
- run: pip install -e .${{ matrix.extras }}
128+
name: Install econml
129+
- run: pip install pytest pytest-runner jupyter jupyter-client nbconvert nbformat seaborn xgboost tqdm
130+
name: Install test and notebook requirements
131+
- run: pip list
132+
name: List installed packages
133+
- run: python setup.py pytest
134+
name: Run notebook tests
135+
env:
136+
PYTEST_ADDOPTS: '-m "notebook"'
137+
NOTEBOOK_DIR_PATTERN: ${{ matrix.pattern }}
138+
139+
tests:
140+
name: "Run tests"
141+
needs: [eval]
142+
if: ${{ needs.eval.outputs.testCode == 'True' }}
143+
strategy:
144+
matrix:
145+
os: [ubuntu-latest, windows-latest, macos-latest]
146+
python-version: [3.6, 3.7, 3.8, 3.9]
147+
kind: [serial, other, dml, main, treatment]
148+
exclude:
149+
# Serial tests fail randomly on mac sometimes, so we don't run them there
150+
- os: macos-latest
151+
kind: serial
152+
# Python 3.6 isn't supported on ubuntu-latest
153+
- os: ubuntu-latest
154+
python-version: 3.6
155+
156+
# Assign the correct package and testing options for each kind of test
157+
include:
158+
- kind: serial
159+
opts: '-m "serial" -n 1'
160+
extras: "[tf,plt]"
161+
- kind: other
162+
opts: '-m "cate_api" -n auto'
163+
extras: "[tf,plt]"
164+
- kind: dml
165+
opts: '-m "dml"'
166+
extras: "[tf,plt]"
167+
- kind: main
168+
opts: '-m "not (notebook or automl or dml or serial or cate_api or treatment_featurization)" -n 2'
169+
extras: "[tf,plt,dowhy]"
170+
- kind: treatment
171+
opts: '-m "treatment_featurization" -n auto'
172+
extras: "[tf,plt]"
173+
fail-fast: false
174+
runs-on: ${{ matrix.os }}
175+
steps:
176+
- uses: actions/checkout@v3
177+
name: Checkout repository
178+
with:
179+
ref: ${{ env.ref }}
180+
- uses: actions/setup-python@v4
181+
name: Setup Python
182+
with:
183+
python-version: ${{ matrix.python-version }}
184+
- run: python -m pip install --upgrade pip && pip install --upgrade setuptools
185+
name: Ensure latest pip and setuptools
186+
- run: pip install -e .${{ matrix.extras }}
187+
name: Install econml
188+
- run: pip install pytest pytest-runner coverage
189+
name: Install pytest
190+
- run: python setup.py pytest
191+
name: Run tests
192+
env:
193+
PYTEST_ADDOPTS: ${{ matrix.opts }}
194+
COVERAGE_PROCESS_START: 'setup.cfg'
195+
# todo: publish test results, coverage info
196+
197+
build:
198+
name: Build package
199+
needs: [eval]
200+
if: ${{ needs.eval.outputs.testCode == 'True' }}
201+
uses: ./.github/workflows/publish-package.yml
202+
with:
203+
publish: false
204+
repository: testpypi
205+
# don't have access to env context here for some reason
206+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || null }}
207+
208+
docs:
209+
name: Build documentation
210+
needs: [eval]
211+
if: ${{ needs.eval.outputs.buildDocs == 'True' }}
212+
uses: ./.github/workflows/publish-documentation.yml
213+
with:
214+
publish: false
215+
environment: test
216+
# don't have access to env context here for some reason
217+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || null }}
218+
219+
verify:
220+
name: Verify CI checks
221+
needs: [lint, notebooks, tests, build, docs]
222+
if: always()
223+
runs-on: ubuntu-latest
224+
steps:
225+
- run: exit 1
226+
name: At least one check failed or was cancelled
227+
if: ${{ !(success()) }}
228+
- run: exit 0
229+
name: All checks passed
230+
if: ${{ success() }}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build and publish the documentation
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
publish:
6+
description: 'Whether to publish the documentation (as opposed to just building it)'
7+
required: false
8+
default: true
9+
type: boolean
10+
environment:
11+
description: 'Whether to publish to production or test environment'
12+
required: false
13+
default: prod
14+
type: choice
15+
options: [prod, test]
16+
ref:
17+
description: 'The git ref to build the documentation for'
18+
required: false
19+
default: ''
20+
type: string
21+
# annoyingly, there does not seem to be a way to share these input definitions between triggers
22+
workflow_call:
23+
inputs:
24+
publish:
25+
description: 'Whether to publish the documentation (as opposed to just building it)'
26+
required: false
27+
default: true
28+
type: boolean
29+
# choice type only supported for workflow_dispatch, not workflow_call
30+
environment:
31+
description: 'Whether to publish to production or test environment'
32+
required: false
33+
default: prod
34+
type: string
35+
ref:
36+
description: 'The git ref to build the documentation for'
37+
required: false
38+
default: ''
39+
type: string
40+
41+
42+
jobs:
43+
create_docs:
44+
name: Create and publish documentation
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v3
48+
name: Checkout repository
49+
with:
50+
ref: ${{ inputs.ref }}
51+
- uses: actions/setup-python@v4
52+
name: Setup Python
53+
with:
54+
python-version: 3.8 # because of our supported TensorFlow versions, must build on 3.6-3.8
55+
- run: python -m pip install --upgrade pip && pip install --upgrade setuptools
56+
name: Ensure latest pip and setuptools
57+
- run: pip install -U cython && pip install -e .[all]
58+
name: Install econml[all]
59+
- run: sudo apt-get -yq install graphviz
60+
name: Install graphviz
61+
- run: pip install "sphinx~=4.4.0" "sphinx_rtd_theme~=1.0.0" && python setup.py build_sphinx -W
62+
name: Build documentation
63+
- uses: actions/upload-artifact@v3
64+
name: Upload docs as artifact
65+
with:
66+
name: docs
67+
path: build/sphinx/html/
68+
- run: |-
69+
pushd build/sphinx/html
70+
zip -r docs.zip *
71+
popd
72+
name: Zip docs for publishing
73+
if : ${{ inputs.publish }}
74+
- uses: azure/webapps-deploy@v2
75+
name: Deploy documentation to Azure web app
76+
with:
77+
app-name: ${{ inputs.environment == 'prod' && 'econml' || 'econml-dev' }}
78+
package: build/sphinx/html/docs.zip
79+
publish-profile: ${{ inputs.environment == 'prod' && secrets.PROD_WEBAPP_PUBLISH_PROFILE || secrets.STAGING_WEBAPP_PUBLISH_PROFILE }}
80+
if: ${{ inputs.publish }}

0 commit comments

Comments
 (0)