CI: run tests for ch2 and ch3 with proper imports #21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Python (Chapters) | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| paths: | |
| - "ch2_rl_formulation/**" | |
| - "ch3_multi_armed_bandits/**" | |
| - "ch4_dynamic_programming/**" | |
| - "ch5_monte_carlo/**" | |
| - ".github/workflows/python-tests.yml" | |
| pull_request: | |
| branches: [ "main" ] | |
| paths: | |
| - "ch2_rl_formulation/**" | |
| - "ch3_multi_armed_bandits/**" | |
| - "ch4_dynamic_programming/**" | |
| - "ch5_monte_carlo/**" | |
| - ".github/workflows/python-tests.yml" | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12"] | |
| chapter: [ch2_rl_formulation, ch3_multi_armed_bandits, ch4_dynamic_programming, ch5_monte_carlo] | |
| env: | |
| PYTHONPATH: ${{ github.workspace }} | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache pip | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-py${{ matrix.python-version }}- | |
| - name: Install dependencies | |
| shell: bash | |
| run: | | |
| python -m pip install --upgrade pip | |
| if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi | |
| if [ -f "${{ matrix.chapter }}/requirements.txt" ]; then | |
| python -m pip install -r "${{ matrix.chapter }}/requirements.txt" | |
| fi | |
| if [ -f "${{ matrix.chapter }}/requirements_ch3.txt" ]; then | |
| python -m pip install -r "${{ matrix.chapter }}/requirements_ch3.txt" | |
| fi | |
| python -m pip install pytest | |
| - name: Run tests for ${{ matrix.chapter }} | |
| run: python -m pytest -q ${{ matrix.chapter }}/tests |