|
1 | | -# .github/workflows/python-tests.yml |
2 | 1 | name: Python (Chapters) |
3 | 2 |
|
4 | 3 | on: |
5 | 4 | push: |
6 | 5 | branches: [ "main" ] |
| 6 | + paths: |
| 7 | + - "ch2_rl_formulation/**" |
| 8 | + - "ch3_multi_armed_bandits/**" |
| 9 | + - "ch4_dynamic_programming/**" |
| 10 | + - "ch5_monte_carlo/**" |
| 11 | + - ".github/workflows/python-tests.yml" |
7 | 12 | pull_request: |
| 13 | + branches: [ "main" ] |
| 14 | + paths: |
| 15 | + - "ch2_rl_formulation/**" |
| 16 | + - "ch3_multi_armed_bandits/**" |
| 17 | + - "ch4_dynamic_programming/**" |
| 18 | + - "ch5_monte_carlo/**" |
| 19 | + - ".github/workflows/python-tests.yml" |
8 | 20 |
|
9 | 21 | jobs: |
10 | 22 | test: |
11 | 23 | runs-on: ubuntu-latest |
12 | 24 | strategy: |
| 25 | + fail-fast: false |
13 | 26 | matrix: |
14 | | - chapter: [ch2_rl_formulation, ch3_bandits] |
| 27 | + python-version: ["3.10", "3.11", "3.12"] |
| 28 | + chapter: [ch2_rl_formulation, ch3_multi_armed_bandits, ch4_dynamic_programming, ch5_monte_carlo] |
| 29 | + |
| 30 | + env: |
| 31 | + PYTHONPATH: ${{ github.workspace }} |
15 | 32 |
|
16 | 33 | steps: |
17 | | - - uses: actions/checkout@v4 |
| 34 | + - name: Check out repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Set up Python |
| 38 | + uses: actions/setup-python@v5 |
| 39 | + with: |
| 40 | + python-version: ${{ matrix.python-version }} |
18 | 41 |
|
19 | | - - uses: actions/setup-python@v5 |
| 42 | + - name: Cache pip |
| 43 | + uses: actions/cache@v4 |
20 | 44 | with: |
21 | | - python-version: "3.10" |
| 45 | + path: ~/.cache/pip |
| 46 | + key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt') }} |
| 47 | + restore-keys: | |
| 48 | + ${{ runner.os }}-py${{ matrix.python-version }}- |
22 | 49 |
|
23 | | - - name: Install deps |
| 50 | + - name: Install dependencies |
| 51 | + shell: bash |
24 | 52 | run: | |
25 | 53 | python -m pip install --upgrade pip |
26 | | - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
27 | | - if [ -f "${{ matrix.chapter }}/requirements.txt" ]; then \ |
28 | | - pip install -r "${{ matrix.chapter }}/requirements.txt"; \ |
| 54 | + if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi |
| 55 | + if [ -f "${{ matrix.chapter }}/requirements.txt" ]; then |
| 56 | + python -m pip install -r "${{ matrix.chapter }}/requirements.txt" |
29 | 57 | fi |
30 | | - pip install pytest |
31 | | -
|
32 | | - - name: Make repo importable |
33 | | - run: echo "PYTHONPATH=${GITHUB_WORKSPACE}" >> $GITHUB_ENV |
34 | | - |
35 | | - - name: Check if ${{ matrix.chapter }} has tests |
36 | | - id: has_tests |
37 | | - run: | |
38 | | - if compgen -G "${{ matrix.chapter }}/tests/**/*.py" > /dev/null; then |
39 | | - echo "exists=true" >> $GITHUB_OUTPUT |
40 | | - else |
41 | | - echo "exists=false" >> $GITHUB_OUTPUT |
| 58 | + if [ -f "${{ matrix.chapter }}/requirements_ch3.txt" ]; then |
| 59 | + python -m pip install -r "${{ matrix.chapter }}/requirements_ch3.txt" |
42 | 60 | fi |
| 61 | + python -m pip install pytest |
43 | 62 |
|
44 | | - - name: Run ${{ matrix.chapter }} tests |
45 | | - if: steps.has_tests.outputs.exists == 'true' |
46 | | - run: pytest -q ${{ matrix.chapter }}/tests |
47 | | - |
48 | | - - name: Note skipped chapter |
49 | | - if: steps.has_tests.outputs.exists != 'true' |
50 | | - run: echo "No tests found for ${{ matrix.chapter }} — skipping." |
| 63 | + - name: Run tests for ${{ matrix.chapter }} |
| 64 | + run: python -m pytest -q ${{ matrix.chapter }}/tests |
0 commit comments