|
| 1 | +# .github/workflows/python-tests.yml |
1 | 2 | name: Python (Chapters) |
2 | 3 |
|
3 | 4 | on: |
4 | 5 | push: |
5 | 6 | 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" |
12 | 7 | 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" |
20 | 8 |
|
21 | 9 | jobs: |
22 | 10 | test: |
23 | 11 | runs-on: ubuntu-latest |
24 | 12 | strategy: |
25 | | - fail-fast: false |
26 | 13 | 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] |
32 | 15 |
|
33 | 16 | 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 |
41 | 18 |
|
42 | | - - name: Cache pip |
43 | | - uses: actions/cache@v4 |
| 19 | + - uses: actions/setup-python@v5 |
44 | 20 | 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" |
49 | 22 |
|
50 | | - - name: Install dependencies |
51 | | - shell: bash |
| 23 | + - name: Install deps |
52 | 24 | run: | |
53 | 25 | 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"; \ |
57 | 29 | 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 |
60 | 42 | fi |
61 | | - python -m pip install pytest |
62 | 43 |
|
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