|
| 1 | +name: CI |
| 2 | + |
| 3 | +# yamllint disable-line rule:truthy |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + esphome_version: |
| 8 | + description: "ESPHome PyPi Package version to use" |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + push: |
| 12 | + branches: [main, dev] |
| 13 | + |
| 14 | + pull_request: |
| 15 | + merge_group: |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +concurrency: |
| 21 | + # yamllint disable-line rule:line-length |
| 22 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + ci: |
| 27 | + name: ${{ matrix.name }} |
| 28 | + runs-on: ubuntu-latest |
| 29 | + strategy: |
| 30 | + fail-fast: false |
| 31 | + max-parallel: 5 |
| 32 | + matrix: |
| 33 | + include: |
| 34 | + - id: test |
| 35 | + file: tests/full.yaml |
| 36 | + name: Test tests/full.yaml |
| 37 | + pio_cache_key: full |
| 38 | + - id: test |
| 39 | + file: tests/base.yaml |
| 40 | + name: Test tests/base.yaml |
| 41 | + pio_cache_key: base |
| 42 | + - id: clang-format |
| 43 | + name: Run clang-format |
| 44 | + - id: yamllint |
| 45 | + name: Run yamllint |
| 46 | + - id: black-format |
| 47 | + name: Run black-format |
| 48 | + - id: isort |
| 49 | + name: Run isort |
| 50 | + |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v3 |
| 53 | + - name: Set up Python |
| 54 | + uses: actions/setup-python@v4 |
| 55 | + id: python |
| 56 | + with: |
| 57 | + python-version: "3.9" |
| 58 | + |
| 59 | + - name: Cache virtualenv |
| 60 | + uses: actions/cache@v3 |
| 61 | + with: |
| 62 | + path: .venv |
| 63 | + # yamllint disable-line rule:line-length |
| 64 | + key: venv-${{ steps.python.outputs.python-version }} |
| 65 | + restore-keys: | |
| 66 | + venv-${{ steps.python.outputs.python-version }} |
| 67 | + - name: Set up virtualenv |
| 68 | + # yamllint disable rule:line-length |
| 69 | + run: | |
| 70 | + python -m venv .venv |
| 71 | + source .venv/bin/activate |
| 72 | + pip install -U pip |
| 73 | + pip install -r requirements.txt |
| 74 | + if [ ${{ github.event.inputs.esphome_version != '' }} == true ]; then pip install ESPHome==${{ github.event.inputs.esphome_version }}; else pip install -U ESPHome; fi |
| 75 | + echo "$GITHUB_WORKSPACE/.venv/bin" >> $GITHUB_PATH |
| 76 | + echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv" >> $GITHUB_ENV |
| 77 | + # yamllint enable rule:line-length |
| 78 | + |
| 79 | + # Use per check platformio cache because checks use different parts |
| 80 | + - name: Cache platformio |
| 81 | + uses: actions/cache@v3 |
| 82 | + with: |
| 83 | + path: ~/.platformio |
| 84 | + # yamllint disable-line rule:line-length |
| 85 | + key: platformio-${{ matrix.pio_cache_key }}-${{ hashFiles('platformio.ini') }} |
| 86 | + if: matrix.id == 'test' |
| 87 | + |
| 88 | + - run: esphome compile ${{ matrix.file }} |
| 89 | + if: matrix.id == 'test' |
| 90 | + env: |
| 91 | + # Also cache libdeps, store them in a ~/.platformio subfolder |
| 92 | + PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps |
| 93 | + |
| 94 | + - name: Run clang-format |
| 95 | + |
| 96 | + with: |
| 97 | + clang-format-version: "13" |
| 98 | + check-path: "components" |
| 99 | + if: matrix.id == 'clang-format' |
| 100 | + |
| 101 | + - name: Run yamllint |
| 102 | + if: matrix.id == 'yamllint' |
| 103 | + |
| 104 | + |
| 105 | + - name: Run black-format |
| 106 | + if: matrix.id == 'black-format' |
| 107 | + uses: psf/black@stable |
| 108 | + with: |
| 109 | + options: "--check --verbose" |
| 110 | + version: "~= 24.1" |
| 111 | + |
| 112 | + - name: Run isort |
| 113 | + if: matrix.id == 'isort' |
| 114 | + uses: isort/isort-action@master |
| 115 | + with: |
| 116 | + requirementsFiles: "requirements.txt" |
| 117 | + |
| 118 | + ci-status: |
| 119 | + name: CI Status |
| 120 | + runs-on: ubuntu-latest |
| 121 | + needs: [ci] |
| 122 | + if: always() |
| 123 | + steps: |
| 124 | + - name: Successful deploy |
| 125 | + if: ${{ !(contains(needs.*.result, 'failure')) }} |
| 126 | + run: exit 0 |
| 127 | + - name: Failing deploy |
| 128 | + if: ${{ contains(needs.*.result, 'failure') }} |
| 129 | + run: exit 1 |
0 commit comments