|
| 1 | +name: HAOS E2E Tests (stdio) |
| 2 | + |
| 3 | +# Runs the complete E2E suite against real HAOS while the server-under-test is |
| 4 | +# the installed ha-mcp command connected through stdio JSON-RPC. This is a |
| 5 | +# separate parallel lane so transport coverage does not extend the existing |
| 6 | +# external HAOS lane's wall time. |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request: |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + pytest_args: |
| 13 | + description: 'Extra pytest args (e.g. "-k test_simple_connection") for targeted iteration' |
| 14 | + type: string |
| 15 | + required: false |
| 16 | + default: '' |
| 17 | + force_local_build: |
| 18 | + description: 'Build the qcow2 locally even on a cache hit' |
| 19 | + type: boolean |
| 20 | + required: false |
| 21 | + default: false |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + |
| 26 | +env: |
| 27 | + PYTHON_VERSION: "3.13" |
| 28 | + UV_CACHE_DIR: /tmp/.uv-cache |
| 29 | + LIBGUESTFS_BACKEND: direct |
| 30 | + |
| 31 | +jobs: |
| 32 | + changes: |
| 33 | + name: Detect relevant changes |
| 34 | + runs-on: ubuntu-latest |
| 35 | + timeout-minutes: 5 |
| 36 | + outputs: |
| 37 | + run: ${{ steps.filter.outputs.run }} |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 40 | + with: |
| 41 | + persist-credentials: false |
| 42 | + - name: Classify changed files |
| 43 | + id: filter |
| 44 | + env: |
| 45 | + BASE_REF: ${{ github.base_ref }} |
| 46 | + run: | |
| 47 | + # Fail closed: only a successfully resolved, non-empty, docs-only PR |
| 48 | + # may skip a required heavy job. |
| 49 | + run=true |
| 50 | + if [ "${{ github.event_name }}" = "pull_request" ] \ |
| 51 | + && git fetch --depth=1 origin "$BASE_REF" \ |
| 52 | + && base_sha=$(git rev-parse "origin/$BASE_REF") \ |
| 53 | + && changed=$(git diff --name-only --diff-filter=ACMRD "$base_sha" HEAD) \ |
| 54 | + && [ -n "$changed" ]; then |
| 55 | + echo "Changed files:"; printf '%s\n' "$changed" | sed 's/^/ /' |
| 56 | + run=false |
| 57 | + while IFS= read -r f; do |
| 58 | + [ -z "$f" ] && continue |
| 59 | + case "$f" in |
| 60 | + homeassistant-addon/*.md|homeassistant-addon-dev/*.md|homeassistant-addon-webhook-proxy/*.md|custom_components/ha_mcp_tools/*.md) |
| 61 | + continue ;; |
| 62 | + homeassistant-addon/*|homeassistant-addon-dev/*|homeassistant-addon-webhook-proxy/*|custom_components/ha_mcp_tools/*|tests/haos_image_build/*|tests/initial_test_state/*) |
| 63 | + run=true; break ;; |
| 64 | + *.md|*.mdx|docs/*|site/*) |
| 65 | + continue ;; |
| 66 | + *) |
| 67 | + run=true; break ;; |
| 68 | + esac |
| 69 | + done <<< "$changed" |
| 70 | + else |
| 71 | + echo "Non-PR event or unresolved diff — running suite (fail-closed)." |
| 72 | + fi |
| 73 | + echo "run=$run" |
| 74 | + echo "run=$run" >> "$GITHUB_OUTPUT" |
| 75 | +
|
| 76 | + haos-e2e-stdio: |
| 77 | + name: HAOS E2E Tests (stdio) |
| 78 | + needs: changes |
| 79 | + if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.run != 'false') }} |
| 80 | + runs-on: ubuntu-22.04 |
| 81 | + timeout-minutes: 45 |
| 82 | + |
| 83 | + steps: |
| 84 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 85 | + with: |
| 86 | + persist-credentials: false |
| 87 | + submodules: true |
| 88 | + fetch-depth: 0 |
| 89 | + |
| 90 | + - name: Compute image cache key |
| 91 | + id: key |
| 92 | + run: | |
| 93 | + hash=$(git ls-tree -r HEAD \ |
| 94 | + tests/haos_image_build \ |
| 95 | + tests/initial_test_state \ |
| 96 | + custom_components/ha_mcp_tools \ |
| 97 | + homeassistant-addon-webhook-proxy \ |
| 98 | + | sha256sum | cut -d' ' -f1 | head -c16) |
| 99 | + echo "cache-key=haos-image-$hash" >> "$GITHUB_OUTPUT" |
| 100 | +
|
| 101 | + - name: Restore image from cache |
| 102 | + id: restore-cache |
| 103 | + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 |
| 104 | + with: |
| 105 | + path: /tmp/haos-test-image.qcow2 |
| 106 | + key: ${{ steps.key.outputs.cache-key }} |
| 107 | + |
| 108 | + - name: Report image-acquisition path |
| 109 | + run: | |
| 110 | + echo "::notice title=HAOS image cache::cache-hit=${{ steps.restore-cache.outputs.cache-hit }} key=${{ steps.key.outputs.cache-key }}" |
| 111 | +
|
| 112 | + - name: Install QEMU + OVMF + libguestfs |
| 113 | + run: | |
| 114 | + sudo apt-get update |
| 115 | + sudo apt-get install -y --no-install-recommends \ |
| 116 | + qemu-system-x86 qemu-utils ovmf xz-utils curl libguestfs-tools sshpass |
| 117 | + sudo chmod +r /boot/vmlinuz-* |
| 118 | +
|
| 119 | + - name: Enable KVM group perms |
| 120 | + run: | |
| 121 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \ |
| 122 | + | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 123 | + sudo udevadm control --reload-rules |
| 124 | + sudo udevadm trigger --name-match=kvm |
| 125 | +
|
| 126 | + - name: Free disk space for the local build |
| 127 | + if: steps.restore-cache.outputs.cache-hit != 'true' || github.event.inputs.force_local_build == 'true' |
| 128 | + run: | |
| 129 | + df -h / |
| 130 | + sudo rm -rf /usr/share/dotnet /usr/share/swift /opt/ghc \ |
| 131 | + /usr/local/lib/android /usr/local/.ghcup |
| 132 | + sudo apt-get clean |
| 133 | + docker system prune -af --volumes || true |
| 134 | + df -h / |
| 135 | +
|
| 136 | + - name: Install build-script Python deps |
| 137 | + if: steps.restore-cache.outputs.cache-hit != 'true' || github.event.inputs.force_local_build == 'true' |
| 138 | + run: pip install -r tests/haos_image_build/requirements.txt |
| 139 | + |
| 140 | + - name: Build image locally |
| 141 | + if: steps.restore-cache.outputs.cache-hit != 'true' || github.event.inputs.force_local_build == 'true' |
| 142 | + run: | |
| 143 | + python3 tests/haos_image_build/build_image.py --verbose \ |
| 144 | + --output /tmp/haos-test-image.qcow2 |
| 145 | +
|
| 146 | + # The external HAOS lane is the sole writer for this shared key. A |
| 147 | + # simultaneous cache miss can build here, but this parallel lane must not |
| 148 | + # race it with a second cache save. |
| 149 | + |
| 150 | + - name: Install uv |
| 151 | + uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 |
| 152 | + with: |
| 153 | + version: "latest" |
| 154 | + |
| 155 | + - name: Set up Python |
| 156 | + run: uv python install ${{ env.PYTHON_VERSION }} |
| 157 | + |
| 158 | + - name: Install test dependencies |
| 159 | + run: uv sync --all-extras --dev |
| 160 | + |
| 161 | + - name: Confirm image present |
| 162 | + run: ls -lh /tmp/haos-test-image.qcow2 |
| 163 | + |
| 164 | + - name: Run full E2E suite through stdio against HAOS |
| 165 | + run: | |
| 166 | + cd tests |
| 167 | + uv run pytest src/e2e/ -n2 --dist loadscope -v --tb=short --maxfail=0 ${{ github.event.inputs.pytest_args }} |
| 168 | + env: |
| 169 | + HAMCP_ENV_FILE: "tests/.env.test" |
| 170 | + HAOS_TEST_IMAGE_PATH: /tmp/haos-test-image.qcow2 |
| 171 | + HAOS_TEST_MODE: stdio |
| 172 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 173 | + |
| 174 | + - name: Extract HA diagnostics from booted qcow2 |
| 175 | + if: always() |
| 176 | + run: | |
| 177 | + sudo chmod +r /boot/vmlinuz-* || true |
| 178 | + mkdir -p /tmp/haos-diagnostics |
| 179 | + cp /tmp/haos-build/haos-serial.log /tmp/haos-diagnostics/bake-serial.log 2>/dev/null || true |
| 180 | + QCOW2=/tmp/haos-test-image.qcow2 |
| 181 | + [ -f "$QCOW2" ] || QCOW2=/tmp/haos-build/haos-test-image.qcow2 |
| 182 | + guestfish --ro -a "$QCOW2" run \ |
| 183 | + : mount /dev/sda8 / \ |
| 184 | + : ll /supervisor/homeassistant \ |
| 185 | + > /tmp/haos-diagnostics/config-dir-listing.txt 2>&1 \ |
| 186 | + || echo "directory listing failed" |
| 187 | + guestfish --ro -a "$QCOW2" run \ |
| 188 | + : mount /dev/sda8 / \ |
| 189 | + : tar-out /supervisor/homeassistant/.storage /tmp/haos-diagnostics/storage.tar \ |
| 190 | + || echo ".storage tar-out failed" |
| 191 | + guestfish --ro -a "$QCOW2" run \ |
| 192 | + : mount /dev/sda8 / \ |
| 193 | + : glob copy-out '/supervisor/homeassistant/*.log*' /tmp/haos-diagnostics/ \ |
| 194 | + || echo "log glob copy failed" |
| 195 | + ls -la /tmp/haos-diagnostics/ || true |
| 196 | + cat /tmp/haos-diagnostics/config-dir-listing.txt || true |
| 197 | + python3 scripts/redact_diagnostics_secrets.py /tmp/haos-diagnostics |
| 198 | +
|
| 199 | + - name: Upload HAOS diagnostics |
| 200 | + if: always() |
| 201 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 |
| 202 | + with: |
| 203 | + name: haos-stdio-diagnostics |
| 204 | + path: | |
| 205 | + /tmp/haos-diagnostics/ |
| 206 | + /tmp/haos-e2e-serial.log |
| 207 | + if-no-files-found: warn |
| 208 | + retention-days: 7 |
0 commit comments