Skip to content

Commit 7f58ad9

Browse files
CI: run tests for ch2 and ch3 with proper imports
1 parent 1183bdd commit 7f58ad9

1 file changed

Lines changed: 42 additions & 28 deletions

File tree

.github/workflows/python-tests.yml

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,64 @@
1-
# .github/workflows/python-tests.yml
21
name: Python (Chapters)
32

43
on:
54
push:
65
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"
712
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"
820

921
jobs:
1022
test:
1123
runs-on: ubuntu-latest
1224
strategy:
25+
fail-fast: false
1326
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 }}
1532

1633
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 }}
1841

19-
- uses: actions/setup-python@v5
42+
- name: Cache pip
43+
uses: actions/cache@v4
2044
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 }}-
2249
23-
- name: Install deps
50+
- name: Install dependencies
51+
shell: bash
2452
run: |
2553
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"
2957
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"
4260
fi
61+
python -m pip install pytest
4362
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

Comments
 (0)