Publish Release #126
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Publish Release | |
| on: | |
| workflow_dispatch: | |
| release: | |
| types: [published] | |
| schedule: | |
| - cron: "0 2 * * *" | |
| permissions: | |
| contents: read | |
| jobs: | |
| init: | |
| name: Initialize build | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.tag.outputs.tag }} | |
| branch_build: ${{ steps.tag.outputs.branch_build }} | |
| deploy_env: ${{ steps.tag.outputs.deploy_env }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Get tag | |
| id: tag | |
| # yamllint disable rule:line-length | |
| run: | | |
| if [[ "${{ github.event_name }}" = "release" ]]; then | |
| TAG="${{ github.event.release.tag_name}}" | |
| BRANCH_BUILD="false" | |
| if [[ "${{ github.event.release.prerelease }}" = "true" ]]; then | |
| ENVIRONMENT="beta" | |
| else | |
| ENVIRONMENT="production" | |
| fi | |
| else | |
| TAG=$(cat esphome/const.py | sed -n -E "s/^__version__\s+=\s+\"(.+)\"$/\1/p") | |
| today="$(date --utc '+%Y%m%d')" | |
| TAG="${TAG}${today}" | |
| BRANCH=${GITHUB_REF#refs/heads/} | |
| if [[ "$BRANCH" != "dev" ]]; then | |
| TAG="${TAG}-${BRANCH}" | |
| BRANCH_BUILD="true" | |
| ENVIRONMENT="" | |
| else | |
| BRANCH_BUILD="false" | |
| ENVIRONMENT="dev" | |
| fi | |
| fi | |
| echo "tag=${TAG}" >> $GITHUB_OUTPUT | |
| echo "branch_build=${BRANCH_BUILD}" >> $GITHUB_OUTPUT | |
| echo "deploy_env=${ENVIRONMENT}" >> $GITHUB_OUTPUT | |
| # yamllint enable rule:line-length | |
| deploy-pypi: | |
| name: Build and publish to PyPi | |
| if: github.repository == 'esphome/esphome' && github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: "3.x" | |
| - name: Build | |
| run: |- | |
| pip3 install build | |
| python3 -m build | |
| - name: Publish | |
| uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 | |
| with: | |
| skip-existing: true | |
| deploy-docker: | |
| name: Build ESPHome ${{ matrix.platform.arch }} | |
| if: github.repository == 'esphome/esphome' | |
| permissions: | |
| contents: read | |
| packages: write | |
| runs-on: ${{ matrix.platform.os }} | |
| needs: [init] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - arch: amd64 | |
| os: "ubuntu-24.04" | |
| - arch: arm64 | |
| os: "ubuntu-24.04-arm" | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: "3.11" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 | |
| - name: Log in to docker hub | |
| uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Log in to the GitHub container registry | |
| uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build docker | |
| uses: ./.github/actions/build-image | |
| with: | |
| target: final | |
| build_type: docker | |
| suffix: "" | |
| version: ${{ needs.init.outputs.tag }} | |
| - name: Build ha-addon | |
| uses: ./.github/actions/build-image | |
| with: | |
| target: final | |
| build_type: ha-addon | |
| suffix: "hassio" | |
| version: ${{ needs.init.outputs.tag }} | |
| # - name: Build lint | |
| # uses: ./.github/actions/build-image | |
| # with: | |
| # target: lint | |
| # build_type: lint | |
| # suffix: lint | |
| # version: ${{ needs.init.outputs.tag }} | |
| - name: Upload digests | |
| uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 | |
| with: | |
| name: digests-${{ matrix.platform.arch }} | |
| path: /tmp/digests | |
| retention-days: 1 | |
| deploy-manifest: | |
| name: Publish ESPHome ${{ matrix.image.build_type }} to ${{ matrix.registry }} | |
| runs-on: ubuntu-latest | |
| needs: | |
| - init | |
| - deploy-docker | |
| if: github.repository == 'esphome/esphome' | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: | |
| - build_type: "docker" | |
| suffix: "" | |
| - build_type: "ha-addon" | |
| suffix: "hassio" | |
| # - build_type: "lint" | |
| # suffix: "lint" | |
| registry: | |
| - ghcr | |
| - dockerhub | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Download digests | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| pattern: digests-* | |
| path: /tmp/digests | |
| merge-multiple: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 | |
| - name: Log in to docker hub | |
| if: matrix.registry == 'dockerhub' | |
| uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Log in to the GitHub container registry | |
| if: matrix.registry == 'ghcr' | |
| uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate short tags | |
| id: tags | |
| run: | | |
| output=$(docker/generate_tags.py \ | |
| --tag "${{ needs.init.outputs.tag }}" \ | |
| --suffix "${{ matrix.image.suffix }}" \ | |
| --registry "${{ matrix.registry }}") | |
| echo $output | |
| for l in $output; do | |
| echo $l >> $GITHUB_OUTPUT | |
| done | |
| - name: Create manifest list and push | |
| working-directory: /tmp/digests/${{ matrix.image.build_type }}/${{ matrix.registry }} | |
| run: | | |
| docker buildx imagetools create $(jq -Rcnr 'inputs | . / "," | map("-t " + .) | join(" ")' <<< "${{ steps.tags.outputs.tags}}") \ | |
| $(printf '${{ steps.tags.outputs.image }}@sha256:%s ' *) | |
| deploy-ha-addon-repo: | |
| if: github.repository == 'esphome/esphome' && needs.init.outputs.branch_build == 'false' | |
| runs-on: ubuntu-latest | |
| needs: | |
| - init | |
| - deploy-manifest | |
| steps: | |
| - name: Generate a token | |
| id: generate-token | |
| uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0 | |
| with: | |
| app-id: ${{ secrets.ESPHOME_GITHUB_APP_ID }} | |
| private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} | |
| owner: esphome | |
| repositories: home-assistant-addon | |
| - name: Trigger Workflow | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| github-token: ${{ steps.generate-token.outputs.token }} | |
| script: | | |
| let description = "ESPHome"; | |
| if (context.eventName == "release") { | |
| description = ${{ toJSON(github.event.release.body) }}; | |
| } | |
| github.rest.actions.createWorkflowDispatch({ | |
| owner: "esphome", | |
| repo: "home-assistant-addon", | |
| workflow_id: "bump-version.yml", | |
| ref: "main", | |
| inputs: { | |
| version: "${{ needs.init.outputs.tag }}", | |
| content: description | |
| } | |
| }) | |
| deploy-esphome-schema: | |
| if: github.repository == 'esphome/esphome' && needs.init.outputs.branch_build == 'false' | |
| runs-on: ubuntu-latest | |
| needs: [init] | |
| environment: ${{ needs.init.outputs.deploy_env }} | |
| steps: | |
| - name: Generate a token | |
| id: generate-token | |
| uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0 | |
| with: | |
| app-id: ${{ secrets.ESPHOME_GITHUB_APP_ID }} | |
| private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} | |
| owner: esphome | |
| repositories: esphome-schema | |
| - name: Trigger Workflow | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| github-token: ${{ steps.generate-token.outputs.token }} | |
| script: | | |
| github.rest.actions.createWorkflowDispatch({ | |
| owner: "esphome", | |
| repo: "esphome-schema", | |
| workflow_id: "generate-schemas.yml", | |
| ref: "main", | |
| inputs: { | |
| version: "${{ needs.init.outputs.tag }}", | |
| } | |
| }) | |
| version-notifier: | |
| if: github.repository == 'esphome/esphome' && needs.init.outputs.branch_build == 'false' | |
| runs-on: ubuntu-latest | |
| needs: | |
| - init | |
| - deploy-manifest | |
| steps: | |
| - name: Generate a token | |
| id: generate-token | |
| uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0 | |
| with: | |
| app-id: ${{ secrets.ESPHOME_GITHUB_APP_ID }} | |
| private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} | |
| owner: esphome | |
| repositories: version-notifier | |
| - name: Trigger Workflow | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| github-token: ${{ steps.generate-token.outputs.token }} | |
| script: | | |
| github.rest.actions.createWorkflowDispatch({ | |
| owner: "esphome", | |
| repo: "version-notifier", | |
| workflow_id: "notify.yml", | |
| ref: "main", | |
| inputs: { | |
| version: "${{ needs.init.outputs.tag }}", | |
| } | |
| }) |