|
| 1 | +name: CI/CD Integrated |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - "**" |
| 8 | + pull_request: |
| 9 | + schedule: |
| 10 | + - cron: "0 0 * * *" |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + quality: |
| 18 | + name: Code Quality |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Install uv |
| 25 | + uses: astral-sh/setup-uv@v5 |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: uv sync --all-groups |
| 29 | + |
| 30 | + - name: Run pre-commit checks |
| 31 | + run: uv run pre-commit run --all-files --show-diff-on-failure |
| 32 | + |
| 33 | + mypy: |
| 34 | + name: Type Check (mypy) |
| 35 | + needs: [quality] |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Install uv |
| 42 | + uses: astral-sh/setup-uv@v5 |
| 43 | + with: |
| 44 | + python-version: "3.12" |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + run: uv sync --all-groups |
| 48 | + |
| 49 | + - name: Run mypy type checking |
| 50 | + run: | |
| 51 | + echo "Running mypy in strict mode..." |
| 52 | + uv run mypy custom_components/solax_modbus tests --strict |
| 53 | +
|
| 54 | + hacs: |
| 55 | + name: HACS Validation |
| 56 | + needs: [quality] |
| 57 | + runs-on: ubuntu-latest |
| 58 | + steps: |
| 59 | + - name: Checkout code |
| 60 | + uses: actions/checkout@v4 |
| 61 | + - name: HACS Action |
| 62 | + uses: hacs/action@main |
| 63 | + with: |
| 64 | + category: integration |
| 65 | + |
| 66 | + hassfest: |
| 67 | + name: Hassfest Validation |
| 68 | + needs: [quality] |
| 69 | + runs-on: ubuntu-latest |
| 70 | + steps: |
| 71 | + - name: Checkout code |
| 72 | + uses: actions/checkout@v4 |
| 73 | + - name: Hassfest Action |
| 74 | + uses: home-assistant/actions/hassfest@master |
| 75 | + |
| 76 | + test-quick: |
| 77 | + name: Test Quick |
| 78 | + needs: [mypy] |
| 79 | + if: github.event_name == 'push' && github.ref != 'refs/heads/main' |
| 80 | + runs-on: ubuntu-latest |
| 81 | + strategy: |
| 82 | + matrix: |
| 83 | + python-version: ["3.12"] |
| 84 | + steps: |
| 85 | + - name: Checkout code |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Install uv |
| 89 | + uses: astral-sh/setup-uv@v5 |
| 90 | + with: |
| 91 | + python-version: ${{ matrix.python-version }} |
| 92 | + |
| 93 | + - name: Install dependencies |
| 94 | + run: uv sync --all-groups |
| 95 | + |
| 96 | + - name: Run Quick Tests |
| 97 | + run: uv run pytest -m "not slow" |
| 98 | + |
| 99 | + test-comprehensive: |
| 100 | + name: Test Comprehensive |
| 101 | + needs: [mypy] |
| 102 | + if: github.event_name == 'pull_request' || github.event_name == 'schedule' || (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' |
| 103 | + runs-on: ubuntu-latest |
| 104 | + strategy: |
| 105 | + matrix: |
| 106 | + python-version: ["3.12", "3.13"] |
| 107 | + steps: |
| 108 | + - name: Checkout code |
| 109 | + uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Install uv |
| 112 | + uses: astral-sh/setup-uv@v5 |
| 113 | + with: |
| 114 | + python-version: ${{ matrix.python-version }} |
| 115 | + |
| 116 | + - name: Install dependencies |
| 117 | + run: uv sync --all-groups |
| 118 | + |
| 119 | + - name: Run Full Tests |
| 120 | + run: uv run pytest |
| 121 | + |
| 122 | + all-checks-passed: |
| 123 | + name: ✅ All Checks Passed |
| 124 | + if: always() |
| 125 | + needs: [hacs, hassfest, test-quick, test-comprehensive] |
| 126 | + runs-on: ubuntu-latest |
| 127 | + steps: |
| 128 | + - name: Check all results |
| 129 | + run: | |
| 130 | + HACS="${{ needs.hacs.result }}" |
| 131 | + HASSFEST="${{ needs.hassfest.result }}" |
| 132 | + QUICK="${{ needs.test-quick.result }}" |
| 133 | + COMPREHENSIVE="${{ needs.test-comprehensive.result }}" |
| 134 | + |
| 135 | + echo "HACS: $HACS" |
| 136 | + echo "Hassfest: $HASSFEST" |
| 137 | + echo "Quick Tests: $QUICK" |
| 138 | + echo "Comprehensive Tests: $COMPREHENSIVE" |
| 139 | + |
| 140 | + # 1. Static Analysis must pass |
| 141 | + if [[ "$HACS" != "success" ]]; then |
| 142 | + echo "❌ HACS validation failed" |
| 143 | + exit 1 |
| 144 | + fi |
| 145 | + if [[ "$HASSFEST" != "success" ]]; then |
| 146 | + echo "❌ Hassfest validation failed" |
| 147 | + exit 1 |
| 148 | + fi |
| 149 | + |
| 150 | + # 2. Tests: One path must succeed |
| 151 | + if [[ "$COMPREHENSIVE" == "success" ]]; then |
| 152 | + echo "✅ Comprehensive tests passed" |
| 153 | + exit 0 |
| 154 | + elif [[ "$QUICK" == "success" && "$COMPREHENSIVE" == "skipped" ]]; then |
| 155 | + echo "✅ Quick tests passed" |
| 156 | + exit 0 |
| 157 | + elif [[ "$QUICK" == "skipped" && "$COMPREHENSIVE" == "skipped" ]]; then |
| 158 | + echo "⚠️ No tests ran?" |
| 159 | + exit 1 |
| 160 | + else |
| 161 | + echo "❌ Tests failed or cancelled" |
| 162 | + exit 1 |
| 163 | + fi |
0 commit comments