diff --git a/.github/actions/restore-python/action.yml b/.github/actions/restore-python/action.yml new file mode 100644 index 00000000..1195504e --- /dev/null +++ b/.github/actions/restore-python/action.yml @@ -0,0 +1,47 @@ +name: Restore Python +inputs: + python-version: + description: Python version to restore + required: true + type: string + cache-key: + description: Cache key to use + required: true + type: string +outputs: + python-version: + description: Python version restored + value: ${{ steps.python.outputs.python-version }} +runs: + using: "composite" + steps: + - name: Set up Python ${{ inputs.python-version }} + id: python + uses: actions/setup-python@v5.1.0 + with: + python-version: ${{ inputs.python-version }} + - name: Restore Python virtual environment + id: cache-venv + uses: actions/cache/restore@v4.0.2 + with: + path: venv + # yamllint disable-line rule:line-length + key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ inputs.cache-key }} + + - name: Create Python virtual environment + if: steps.cache-venv.outputs.cache-hit != 'true' && runner.os != 'Windows' + shell: bash + run: | + python -m venv venv + source venv/bin/activate + python --version + pip install -r requirements.txt + + - name: Create Python virtual environment + if: steps.cache-venv.outputs.cache-hit != 'true' && runner.os == 'Windows' + shell: bash + run: | + python -m venv venv + ./venv/Scripts/activate + python --version + pip install -r requirements.txt \ No newline at end of file diff --git a/.github/workflows/build_latest.yaml b/.github/workflows/build_latest.yaml new file mode 100644 index 00000000..8cf4888d --- /dev/null +++ b/.github/workflows/build_latest.yaml @@ -0,0 +1,100 @@ +name: ESPHome-latest + +on: + - push + - pull_request + - workflow_dispatch + +env: + DEFAULT_PYTHON: "3.9" + + +jobs: + common: + name: Create common environment + runs-on: ubuntu-latest + outputs: + cache-key: ${{ steps.cache-key.outputs.key }} + steps: + - name: Check out code from GitHub + uses: actions/checkout@v4.1.6 + - name: Generate cache-key + id: cache-key + run: echo key="${{ hashFiles('requirements.txt') }}" >> $GITHUB_OUTPUT + - name: Set up Python ${{ env.DEFAULT_PYTHON }} + id: python + uses: actions/setup-python@v5.1.0 + with: + python-version: ${{ env.DEFAULT_PYTHON }} + - name: Restore Python virtual environment + id: cache-venv + uses: actions/cache@v4.0.2 + with: + path: venv + # yamllint disable-line rule:line-length + key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ steps.cache-key.outputs.key }} + - name: Create Python virtual environment + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + python -m venv venv + . venv/bin/activate + python --version + pip install -r requirements.txt + + build-list: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Check out code from GitHub + uses: actions/checkout@v4.1.6 + - name: Find all YAML satellite files + id: set-matrix + run: echo "matrix=$(ls config/satellite*.yaml | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT + + + build: + name: Build YAML config ${{ matrix.file }} + runs-on: ubuntu-latest + needs: + - common + - build-list + strategy: + fail-fast: false + max-parallel: 2 + matrix: + file: ${{ fromJson(needs.build-list.outputs.matrix) }} + steps: + - name: Check out code from GitHub + uses: actions/checkout@v4.1.6 + - name: Restore Python + uses: ./.github/actions/restore-python + with: + python-version: ${{ env.DEFAULT_PYTHON }} + cache-key: ${{ needs.common.outputs.cache-key }} + + - name: Run esphome compile ${{ matrix.file }} + run: | + . venv/bin/activate + esphome compile ${{ matrix.file }} + esphome config ${{ matrix.file }} >> ${{ matrix.file }}.cmpl.yaml + + - name: Parse name + id: get_node_name + uses: mikefarah/yq@master + with: + cmd: yq '.esphome.name' ${{ matrix.file }}.cmpl.yaml + + - name: 'Upload Artifact' + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.get_node_name.outputs.result }}.firmware.factory.bin + path: config/.esphome/build/${{ steps.get_node_name.outputs.result }}/.pioenvs/${{ steps.get_node_name.outputs.result }}/firmware.factory.bin + retention-days: 30 + + - name: 'Upload Artifact' + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.get_node_name.outputs.result }}.firmware.bin + path: config/.esphome/build/${{ steps.get_node_name.outputs.result }}/.pioenvs/${{ steps.get_node_name.outputs.result }}/firmware.bin + retention-days: 30 \ No newline at end of file