|
| 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() }} |
0 commit comments