Skip to content

Commit a54bb07

Browse files
CI: use root requirements.txt and reusable chapter workflow
1 parent 2317fdf commit a54bb07

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed
Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,37 @@
1-
name: _chapter-tests
1+
name: chapter tests (reusable)
22

33
on:
44
workflow_call:
55
inputs:
66
chapter:
7+
description: "Folder name of the chapter (e.g., ch2_rl_formulation)"
78
required: true
89
type: string
910

1011
jobs:
1112
test:
13+
name: ${{ inputs.chapter }} (py${{ matrix.python }})
1214
runs-on: ubuntu-latest
1315
strategy:
16+
fail-fast: false
1417
matrix:
15-
python-version: ["3.10", "3.11", "3.12"]
16-
env:
17-
MPLBACKEND: Agg
18-
PYTHONDONTWRITEBYTECODE: 1
19-
PYTHONPATH: ${{ github.workspace }}
18+
python: ["3.10", "3.11", "3.12"]
19+
2020
steps:
2121
- name: Check out repository
2222
uses: actions/checkout@v4
2323

24-
- name: Set up Python ${{ matrix.python-version }}
24+
- name: Set up Python ${{ matrix.python }}
2525
uses: actions/setup-python@v5
2626
with:
27-
python-version: ${{ matrix.python-version }}
27+
python-version: ${{ matrix.python }}
28+
cache: "pip"
2829

29-
- name: Cache pip
30-
uses: actions/cache@v4
31-
with:
32-
path: ~/.cache/pip
33-
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}
34-
restore-keys: |
35-
${{ runner.os }}-pip-${{ matrix.python-version }}-
30+
- name: Upgrade pip
31+
run: python -m pip install -U pip
3632

37-
- name: Install dependencies (requirements.txt if present)
38-
run: |
39-
python -m pip install --upgrade pip
40-
if [ -f requirements.txt ]; then
41-
pip install -r requirements.txt
42-
fi
43-
# Fallback to guarantee core deps exist for tests
44-
pip install --upgrade --upgrade-strategy eager numpy matplotlib pytest
33+
- name: Install dependencies (root requirements.txt)
34+
run: pip install -r requirements.txt
4535

4636
- name: Show environment
4737
run: |
@@ -51,4 +41,4 @@ jobs:
5141
- name: Run tests
5242
run: |
5343
echo "Running pytest in ${{ inputs.chapter }}/tests"
54-
python -m pytest -q ${{ inputs.chapter }}/tests
44+
pytest -q ${{ inputs.chapter }}/tests

.github/workflows/ch2.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name: ch2 tests
2+
23
on:
34
push:
45
branches: [ "main" ]
56
paths:
67
- "ch2_rl_formulation/**"
78
- ".github/workflows/ch2.yml"
89
- ".github/workflows/_chapter-tests.yml"
10+
- "requirements.txt"
911
pull_request:
1012
branches: [ "main" ]
1113
paths:
1214
- "ch2_rl_formulation/**"
1315
- ".github/workflows/ch2.yml"
1416
- ".github/workflows/_chapter-tests.yml"
17+
- "requirements.txt"
1518

1619
jobs:
1720
call:

.github/workflows/ch4.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name: ch4 tests
2+
23
on:
34
push:
45
branches: [ "main" ]
56
paths:
67
- "ch4_dynamic_programming/**"
78
- ".github/workflows/ch4.yml"
89
- ".github/workflows/_chapter-tests.yml"
10+
- "requirements.txt"
911
pull_request:
1012
branches: [ "main" ]
1113
paths:
1214
- "ch4_dynamic_programming/**"
1315
- ".github/workflows/ch4.yml"
1416
- ".github/workflows/_chapter-tests.yml"
17+
- "requirements.txt"
1518

1619
jobs:
1720
call:

.github/workflows/ch5.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name: ch5 tests
2+
23
on:
34
push:
45
branches: [ "main" ]
56
paths:
67
- "ch5_monte_carlo/**"
78
- ".github/workflows/ch5.yml"
89
- ".github/workflows/_chapter-tests.yml"
10+
- "requirements.txt"
911
pull_request:
1012
branches: [ "main" ]
1113
paths:
1214
- "ch5_monte_carlo/**"
1315
- ".github/workflows/ch5.yml"
1416
- ".github/workflows/_chapter-tests.yml"
17+
- "requirements.txt"
1518

1619
jobs:
1720
call:

.github/workflows/python-tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Python (Chapters)
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- "ch2_rl_formulation/**"
8+
- "ch4_dynamic_programming/**"
9+
- "ch5_monte_carlo/**"
10+
- ".github/workflows/python-tests.yml"
11+
- ".github/workflows/_chapter-tests.yml"
12+
- "requirements.txt"
13+
pull_request:
14+
branches: [ "main" ]
15+
paths:
16+
- "ch2_rl_formulation/**"
17+
- "ch4_dynamic_programming/**"
18+
- "ch5_monte_carlo/**"
19+
- ".github/workflows/python-tests.yml"
20+
- ".github/workflows/_chapter-tests.yml"
21+
- "requirements.txt"
22+
23+
jobs:
24+
ch2:
25+
uses: ./.github/workflows/_chapter-tests.yml
26+
with:
27+
chapter: ch2_rl_formulation
28+
29+
ch4:
30+
uses: ./.github/workflows/_chapter-tests.yml
31+
with:
32+
chapter: ch4_dynamic_programming
33+
34+
ch5:
35+
uses: ./.github/workflows/_chapter-tests.yml
36+
with:
37+
chapter: ch5_monte_carlo

0 commit comments

Comments
 (0)