|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - DEV |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + pull-requests: write # required to post PR comments |
| 16 | + |
| 17 | +jobs: |
| 18 | + # ------------------------------------------------------------------ |
| 19 | + # Unit tests (fast, no Klipper dependency) |
| 20 | + # ------------------------------------------------------------------ |
| 21 | + unit-test: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 # full history required for gh-pages deployment |
| 28 | + |
| 29 | + - name: Set up Python |
| 30 | + uses: actions/setup-python@v5 |
| 31 | + with: |
| 32 | + python-version: "3.12" |
| 33 | + cache: "pip" |
| 34 | + cache-dependency-path: requirements.txt |
| 35 | + |
| 36 | + - name: Create virtual environment |
| 37 | + run: python -m venv .venv |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: .venv/bin/pip install -r requirements.txt |
| 41 | + |
| 42 | + - name: Run unit tests with coverage |
| 43 | + run: | |
| 44 | + .venv/bin/python -m pytest tests/ \ |
| 45 | + --cov=extras \ |
| 46 | + --cov-report=term-missing \ |
| 47 | + --cov-report=html:coverage-report \ |
| 48 | + --cov-report=xml:coverage.xml \ |
| 49 | + --junitxml=test-results.xml |
| 50 | +
|
| 51 | + - name: Write coverage summary to job log |
| 52 | + if: always() |
| 53 | + run: | |
| 54 | + echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY |
| 55 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 56 | + .venv/bin/python -m coverage report >> $GITHUB_STEP_SUMMARY |
| 57 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 58 | +
|
| 59 | + - name: Upload HTML coverage report as artifact |
| 60 | + if: always() |
| 61 | + uses: actions/upload-artifact@v4 |
| 62 | + with: |
| 63 | + name: coverage-report.zip |
| 64 | + path: coverage-report/ |
| 65 | + if-no-files-found: error |
| 66 | + retention-days: 30 |
| 67 | + |
| 68 | + # ------------------------------------------------------------------ |
| 69 | + # Klippy integration tests (runs AFC under a real Klipper/Kalico process) |
| 70 | + # ------------------------------------------------------------------ |
| 71 | + klippy-test: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + strategy: |
| 74 | + fail-fast: false |
| 75 | + matrix: |
| 76 | + firmware: |
| 77 | + - name: klipper |
| 78 | + repo: https://github.com/Klipper3d/klipper.git |
| 79 | + - name: kalico |
| 80 | + repo: https://github.com/KalicoCrew/kalico.git |
| 81 | + |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Set up Python |
| 86 | + uses: actions/setup-python@v5 |
| 87 | + with: |
| 88 | + python-version: "3.12" |
| 89 | + cache: "pip" |
| 90 | + cache-dependency-path: requirements.txt |
| 91 | + |
| 92 | + - name: Create virtual environment |
| 93 | + run: python -m venv .venv |
| 94 | + |
| 95 | + - name: Install Python test dependencies |
| 96 | + run: .venv/bin/pip install -r requirements.txt |
| 97 | + |
| 98 | + # Clone into klipper/ regardless of variant so KLIPPER_PATH needs no change. |
| 99 | + - name: Clone ${{ matrix.firmware.name }} |
| 100 | + run: git clone --depth 1 ${{ matrix.firmware.repo }} klipper |
| 101 | + |
| 102 | + - name: Install klippy Python dependencies |
| 103 | + run: .venv/bin/pip install -r klipper/scripts/klippy-requirements.txt |
| 104 | + |
| 105 | + # chelper is a C extension compiled at runtime. Kalico does not ship |
| 106 | + # build_chelper.py, so the fallback chain handles both variants. |
| 107 | + - name: Build chelper |
| 108 | + run: | |
| 109 | + cd klipper |
| 110 | + python klippy/chelper/__init__.py 2>/dev/null || \ |
| 111 | + make PYTHON=$(pwd)/../.venv/bin/python scripts/build_chelper.py || \ |
| 112 | + true # chelper may auto-build on first import; continue |
| 113 | +
|
| 114 | + # Install the ARM cross-compiler toolchain needed to build STM32H723 firmware. |
| 115 | + - name: Install ARM cross-compiler |
| 116 | + run: sudo apt-get install -y gcc-arm-none-eabi libnewlib-arm-none-eabi |
| 117 | + |
| 118 | + # Build the STM32H723 MCU dict. |
| 119 | + # The dict file is generated during compilation (before linking), so we |
| 120 | + # allow link errors (|| true) and verify the dict was produced. |
| 121 | + - name: Build STM32H723 firmware dict |
| 122 | + run: | |
| 123 | + cp tests/klippy/stm32h723.config klipper/.config |
| 124 | + make -C klipper olddefconfig |
| 125 | + make -C klipper || true # link may fail with newer GCC LTO; dict is generated earlier |
| 126 | + test -f klipper/out/klipper.dict || (echo "ERROR: klipper.dict not generated" && exit 1) |
| 127 | + mkdir -p tests/dict |
| 128 | + cp klipper/out/klipper.dict tests/dict/stm32h723.dict |
| 129 | +
|
| 130 | + - name: Run klippy integration tests |
| 131 | + env: |
| 132 | + KLIPPER_PATH: ${{ github.workspace }}/klipper |
| 133 | + DICTDIR: ${{ github.workspace }}/tests/dict |
| 134 | + run: | |
| 135 | + .venv/bin/python -m pytest tests/klippy/ -v \ |
| 136 | + --junitxml=klippy-test-results-${{ matrix.firmware.name }}.xml |
| 137 | +
|
| 138 | + - name: Upload klippy test results |
| 139 | + if: always() |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + with: |
| 142 | + name: klippy-test-results-${{ matrix.firmware.name }}.zip |
| 143 | + path: klippy-test-results-${{ matrix.firmware.name }}.xml |
| 144 | + if-no-files-found: warn |
| 145 | + retention-days: 30 |
0 commit comments