esphome/.github/workflows/release.yml

150 lines
4.6 KiB
YAML
Raw Normal View History

2022-09-06 05:48:01 +02:00
---
2020-07-14 14:34:44 +02:00
name: Publish Release
2022-09-06 05:48:01 +02:00
# yamllint disable-line rule:truthy
2020-07-14 14:34:44 +02:00
on:
workflow_dispatch:
2020-07-14 14:34:44 +02:00
release:
types: [published]
schedule:
- cron: "0 2 * * *"
2020-07-14 14:34:44 +02:00
permissions:
contents: read
2020-07-14 14:34:44 +02:00
jobs:
init:
name: Initialize build
2020-07-14 14:34:44 +02:00
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
2020-07-14 14:34:44 +02:00
steps:
- uses: actions/checkout@v3
- name: Get tag
id: tag
2022-09-06 05:48:01 +02:00
# yamllint disable rule:line-length
2020-07-14 14:34:44 +02:00
run: |
if [[ "$GITHUB_EVENT_NAME" = "release" ]]; then
TAG="${GITHUB_REF#refs/tags/}"
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}"
fi
fi
echo "tag=${TAG}" >> $GITHUB_OUTPUT
2022-09-06 05:48:01 +02:00
# yamllint enable rule:line-length
2020-07-14 14:34:44 +02:00
deploy-pypi:
name: Build and publish to PyPi
if: github.repository == 'esphome/esphome' && github.event_name == 'release'
2020-07-14 14:34:44 +02:00
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
2020-07-14 14:34:44 +02:00
- name: Set up Python
uses: actions/setup-python@v4
2020-07-14 14:34:44 +02:00
with:
2022-09-06 05:48:01 +02:00
python-version: "3.x"
2020-07-14 14:34:44 +02:00
- name: Set up python environment
run: |
script/setup
pip install setuptools wheel twine
- name: Build
run: python setup.py sdist bdist_wheel
- name: Upload
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*
deploy-docker:
name: Build and publish ESPHome ${{ matrix.image.title}}
if: github.repository == 'esphome/esphome'
permissions:
contents: read
packages: write
2020-07-14 14:34:44 +02:00
runs-on: ubuntu-latest
needs: [init]
2020-07-14 14:34:44 +02:00
strategy:
matrix:
image:
- title: "ha-addon"
suffix: "hassio"
target: "hassio"
baseimg: "hassio"
- title: "docker"
suffix: ""
target: "docker"
baseimg: "docker"
- title: "lint"
suffix: "lint"
target: "lint"
baseimg: "docker"
2020-07-14 14:34:44 +02:00
steps:
2022-09-06 05:48:01 +02:00
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
2022-09-06 05:48:01 +02:00
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
2020-07-15 01:37:30 +02:00
2022-09-06 05:48:01 +02:00
- name: Log in to docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to the GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate short tags
id: tags
2022-09-06 05:48:01 +02:00
run: |
docker/generate_tags.py \
2022-09-06 05:48:01 +02:00
--tag "${{ needs.init.outputs.tag }}" \
--suffix "${{ matrix.image.suffix }}"
2020-07-14 14:34:44 +02:00
- name: Build and push
uses: docker/build-push-action@v3
2022-09-06 05:48:01 +02:00
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
target: ${{ matrix.image.target }}
push: true
# yamllint disable rule:line-length
2023-01-20 02:06:47 +01:00
cache-from: type=registry,ref=ghcr.io/${{ steps.tags.outputs.image }}:cache-${{ steps.tags.outputs.channel }}
cache-to: type=registry,ref=ghcr.io/${{ steps.tags.outputs.image }}:cache-${{ steps.tags.outputs.channel }},mode=max
# yamllint enable rule:line-length
tags: ${{ steps.tags.outputs.tags }}
build-args: |
BASEIMGTYPE=${{ matrix.image.baseimg }}
BUILD_VERSION=${{ needs.init.outputs.tag }}
deploy-ha-addon-repo:
if: github.repository == 'esphome/esphome' && github.event_name == 'release'
runs-on: ubuntu-latest
needs: [deploy-docker]
steps:
- env:
2022-02-15 21:11:46 +01:00
TOKEN: ${{ secrets.DEPLOY_HA_ADDON_REPO_TOKEN }}
2022-09-06 05:48:01 +02:00
# yamllint disable rule:line-length
run: |
curl \
-u ":$TOKEN" \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/esphome/home-assistant-addon/actions/workflows/bump-version.yml/dispatches \
-d '{"ref":"main","inputs":{"version":"${{ github.event.release.tag_name }}","content":${{ toJSON(github.event.release.body) }}}}'
2022-09-06 05:48:01 +02:00
# yamllint enable rule:line-length