Skip to content

Commit 66444ed

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

1 file changed

Lines changed: 28 additions & 42 deletions

File tree

.github/workflows/python-tests.yml

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

34
on:
45
push:
56
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"
127
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"
208

219
jobs:
2210
test:
2311
runs-on: ubuntu-latest
2412
strategy:
25-
fail-fast: false
2613
matrix:
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 }}
14+
chapter: [ch2_rl_formulation, ch3_bandits]
3215

3316
steps:
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 }}
17+
- uses: actions/checkout@v4
4118

42-
- name: Cache pip
43-
uses: actions/cache@v4
19+
- uses: actions/setup-python@v5
4420
with:
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 }}-
21+
python-version: "3.10"
4922

50-
- name: Install dependencies
51-
shell: bash
23+
- name: Install deps
5224
run: |
5325
python -m pip install --upgrade pip
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"
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"; \
5729
fi
58-
if [ -f "${{ matrix.chapter }}/requirements_ch3.txt" ]; then
59-
python -m pip install -r "${{ matrix.chapter }}/requirements_ch3.txt"
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
6042
fi
61-
python -m pip install pytest
6243
63-
- name: Run tests for ${{ matrix.chapter }}
64-
run: python -m pytest -q ${{ matrix.chapter }}/tests
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."

0 commit comments

Comments
 (0)