2021-04-26 20:19:40 +00:00
name : Build images
# yamllint disable-line rule:truthy
on :
2021-04-27 09:17:40 +00:00
workflow_dispatch :
2021-04-26 20:19:40 +00:00
release :
types : [ "published" ]
schedule :
- cron : "0 2 * * *"
env :
BUILD_TYPE : core
2023-01-22 19:40:33 +00:00
DEFAULT_PYTHON : "3.10"
2021-04-26 20:19:40 +00:00
jobs :
init :
name : Initialize build
2022-01-20 11:54:54 +00:00
if : github.repository_owner == 'home-assistant'
2021-04-26 20:19:40 +00:00
runs-on : ubuntu-latest
outputs :
architectures : ${{ steps.info.outputs.architectures }}
version : ${{ steps.version.outputs.version }}
channel : ${{ steps.version.outputs.channel }}
publish : ${{ steps.version.outputs.publish }}
steps :
- name : Checkout the repository
2023-06-12 08:42:40 +00:00
uses : actions/checkout@v3.5.3
2021-04-26 20:19:40 +00:00
with :
fetch-depth : 0
- name : Set up Python ${{ env.DEFAULT_PYTHON }}
2023-05-25 07:48:52 +00:00
uses : actions/setup-python@v4.6.1
2021-04-26 20:19:40 +00:00
with :
python-version : ${{ env.DEFAULT_PYTHON }}
- name : Get information
id : info
uses : home-assistant/actions/helpers/info@master
- name : Get version
id : version
uses : home-assistant/actions/helpers/version@master
with :
type : ${{ env.BUILD_TYPE }}
- name : Verify version
uses : home-assistant/actions/helpers/verify-version@master
with :
ignore-dev : true
build_python :
name : Build PyPi package
2023-05-30 17:43:59 +00:00
environment : ${{ needs.init.outputs.channel }}
2023-05-30 12:39:19 +00:00
needs : [ "init" , "build_base" ]
2021-04-26 20:19:40 +00:00
runs-on : ubuntu-latest
2022-01-20 11:54:54 +00:00
if : github.repository_owner == 'home-assistant' && needs.init.outputs.publish == 'true'
2021-04-26 20:19:40 +00:00
steps :
- name : Checkout the repository
2023-06-12 08:42:40 +00:00
uses : actions/checkout@v3.5.3
2021-04-26 20:19:40 +00:00
- name : Set up Python ${{ env.DEFAULT_PYTHON }}
2023-05-25 07:48:52 +00:00
uses : actions/setup-python@v4.6.1
2021-04-26 20:19:40 +00:00
with :
python-version : ${{ env.DEFAULT_PYTHON }}
2023-02-06 16:21:57 +00:00
- name : Download Translations
run : python3 -m script.translations download
env :
LOKALISE_TOKEN : ${{ secrets.LOKALISE_TOKEN }}
2021-04-26 20:19:40 +00:00
- name : Build package
shell : bash
run : |
2022-01-28 22:09:05 +00:00
# Remove dist, build, and homeassistant.egg-info
# when build locally for testing!
pip install twine build
python -m build
2021-04-26 20:19:40 +00:00
- name : Upload package
shell : bash
run : |
export TWINE_USERNAME="__token__"
export TWINE_PASSWORD="${{ secrets.TWINE_TOKEN }}"
twine upload dist/* --skip-existing
build_base :
name : Build ${{ matrix.arch }} base core image
2022-01-20 11:54:54 +00:00
if : github.repository_owner == 'home-assistant'
2021-04-26 20:19:40 +00:00
needs : init
runs-on : ubuntu-latest
2023-06-26 12:32:02 +00:00
permissions :
contents : read
packages : write
id-token : write
2021-04-26 20:19:40 +00:00
strategy :
matrix :
arch : ${{ fromJson(needs.init.outputs.architectures) }}
steps :
- name : Checkout the repository
2023-06-12 08:42:40 +00:00
uses : actions/checkout@v3.5.3
2021-04-26 20:19:40 +00:00
2022-07-02 16:04:35 +00:00
- name : Download nightly wheels of frontend
if : needs.init.outputs.channel == 'dev'
uses : dawidd6/action-download-artifact@v2
with :
github_token : ${{secrets.GITHUB_TOKEN}}
repo : home-assistant/frontend
branch : dev
2022-07-03 20:06:50 +00:00
workflow : nightly.yaml
2022-07-02 16:04:35 +00:00
workflow_conclusion : success
name : wheels
2023-01-12 21:31:14 +00:00
- name : Download nightly wheels of intents
if : needs.init.outputs.channel == 'dev'
uses : dawidd6/action-download-artifact@v2
with :
github_token : ${{secrets.GITHUB_TOKEN}}
2023-05-30 21:10:08 +00:00
repo : home-assistant/intents-package
2023-01-12 21:31:14 +00:00
branch : main
workflow : nightly.yaml
workflow_conclusion : success
name : package
2021-04-26 20:19:40 +00:00
- name : Set up Python ${{ env.DEFAULT_PYTHON }}
2021-04-27 08:36:13 +00:00
if : needs.init.outputs.channel == 'dev'
2023-05-25 07:48:52 +00:00
uses : actions/setup-python@v4.6.1
2021-04-26 20:19:40 +00:00
with :
python-version : ${{ env.DEFAULT_PYTHON }}
- name : Adjust nightly version
2021-04-27 08:36:13 +00:00
if : needs.init.outputs.channel == 'dev'
2021-04-26 20:19:40 +00:00
shell : bash
run : |
2022-07-03 20:16:29 +00:00
python3 -m pip install packaging tomli
2023-04-27 20:39:29 +00:00
python3 -m pip install .
2022-02-22 10:27:38 +00:00
version="$(python3 script/version_bump.py nightly)"
2021-04-26 20:19:40 +00:00
2022-07-02 16:04:35 +00:00
if [[ "$(ls home_assistant_frontend*.whl)" =~ ^home_assistant_frontend-(.*)-py3-none-any.whl$ ]]; then
echo "Found frontend wheel, setting version to: ${BASH_REMATCH[1]}"
frontend_version="${BASH_REMATCH[1]}" yq \
--inplace e -o json \
'.requirements = ["home-assistant-frontend=="+env(frontend_version)]' \
homeassistant/components/frontend/manifest.json
sed -i "s|home-assistant-frontend==.*|home-assistant-frontend==${BASH_REMATCH[1]}|" \
homeassistant/package_constraints.txt
python -m script.gen_requirements_all
fi
2023-01-12 21:31:14 +00:00
if [[ "$(ls home_assistant_intents*.whl)" =~ ^home_assistant_intents-(.*)-py3-none-any.whl$ ]]; then
echo "Found intents wheel, setting version to: ${BASH_REMATCH[1]}"
yq \
--inplace e -o json \
'del(.requirements[] | select(contains("home-assistant-intents")))' \
homeassistant/components/conversation/manifest.json
intents_version="${BASH_REMATCH[1]}" yq \
--inplace e -o json \
'.requirements += ["home-assistant-intents=="+env(intents_version)]' \
homeassistant/components/conversation/manifest.json
2023-01-15 12:21:16 +00:00
sed -i "s|home-assistant-intents==.*|home-assistant-intents==${BASH_REMATCH[1]}|" \
homeassistant/package_constraints.txt
2023-01-12 21:31:14 +00:00
python -m script.gen_requirements_all
fi
2023-04-28 07:53:04 +00:00
- name : Adjustments for armhf
if : matrix.arch == 'armhf'
run : |
# Pandas has issues building on armhf, it is expected they
# will drop the platform in the near future (they consider it
# "flimsy" on 386). The following packages depend on pandas,
# so we comment them out.
2023-06-01 01:12:53 +00:00
sed -i "s|env-canada|# env-canada|g" requirements_all.txt
2023-04-28 07:53:04 +00:00
sed -i "s|noaa-coops|# noaa-coops|g" requirements_all.txt
sed -i "s|pyezviz|# pyezviz|g" requirements_all.txt
sed -i "s|pykrakenapi|# pykrakenapi|g" requirements_all.txt
2023-02-03 19:00:01 +00:00
- name : Download Translations
run : python3 -m script.translations download
env :
LOKALISE_TOKEN : ${{ secrets.LOKALISE_TOKEN }}
2021-08-03 10:56:31 +00:00
- name : Write meta info file
shell : bash
run : |
2021-08-04 09:03:41 +00:00
echo "${{ github.sha }};${{ github.ref }};${{ github.event_name }};${{ github.actor }}" > rootfs/OFFICIAL_IMAGE
2021-08-03 10:56:31 +00:00
2021-04-26 20:19:40 +00:00
- name : Login to GitHub Container Registry
2023-06-08 08:58:13 +00:00
uses : docker/login-action@v2.2.0
2021-04-26 20:19:40 +00:00
with :
registry : ghcr.io
username : ${{ github.repository_owner }}
password : ${{ secrets.GITHUB_TOKEN }}
- name : Build base image
2023-06-12 10:14:32 +00:00
uses : home-assistant/builder@2023.06.0
2021-04-26 20:19:40 +00:00
with :
args : |
$BUILD_ARGS \
--${{ matrix.arch }} \
2023-06-26 12:32:02 +00:00
--cosign \
2021-04-26 20:19:40 +00:00
--target /data \
--generic ${{ needs.init.outputs.version }}
2021-11-24 08:48:34 +00:00
env :
CAS_API_KEY : ${{ secrets.CAS_TOKEN }}
2021-04-26 20:19:40 +00:00
2023-02-06 16:21:57 +00:00
- name : Archive translations
shell : bash
run : find ./homeassistant/components/*/translations -name "*.json" | tar zcvf translations.tar.gz -T -
- name : Upload translations
uses : actions/upload-artifact@v3
with :
name : translations
path : translations.tar.gz
if-no-files-found : error
2021-04-26 20:19:40 +00:00
build_machine :
2021-04-27 13:04:47 +00:00
name : Build ${{ matrix.machine }} machine core image
2022-01-20 11:54:54 +00:00
if : github.repository_owner == 'home-assistant'
2021-04-26 20:19:40 +00:00
needs : [ "init" , "build_base" ]
runs-on : ubuntu-latest
2023-06-26 12:32:02 +00:00
permissions :
contents : read
packages : write
id-token : write
2021-04-26 20:19:40 +00:00
strategy :
matrix :
machine :
- generic-x86-64
- intel-nuc
2021-07-28 12:19:21 +00:00
- khadas-vim3
2021-04-27 09:17:40 +00:00
- odroid-c2
2021-04-26 20:19:40 +00:00
- odroid-c4
2023-03-09 13:18:19 +00:00
- odroid-m1
2021-04-26 20:19:40 +00:00
- odroid-n2
- odroid-xu
- qemuarm
- qemuarm-64
- qemux86
- qemux86-64
- raspberrypi
- raspberrypi2
- raspberrypi3
- raspberrypi3-64
- raspberrypi4
- raspberrypi4-64
- tinker
2022-06-23 11:58:24 +00:00
- yellow
2021-04-26 20:19:40 +00:00
steps :
- name : Checkout the repository
2023-06-12 08:42:40 +00:00
uses : actions/checkout@v3.5.3
2021-04-26 20:19:40 +00:00
2021-12-13 16:14:37 +00:00
- name : Set build additional args
run : |
# Create general tags
if [[ "${{ needs.init.outputs.version }}" =~ d ]]; then
echo "BUILD_ARGS=--additional-tag dev" >> $GITHUB_ENV
elif [[ "${{ needs.init.outputs.version }}" =~ b ]]; then
echo "BUILD_ARGS=--additional-tag beta" >> $GITHUB_ENV
else
echo "BUILD_ARGS=--additional-tag stable" >> $GITHUB_ENV
fi
2021-04-26 20:19:40 +00:00
- name : Login to GitHub Container Registry
2023-06-08 08:58:13 +00:00
uses : docker/login-action@v2.2.0
2021-04-26 20:19:40 +00:00
with :
registry : ghcr.io
username : ${{ github.repository_owner }}
password : ${{ secrets.GITHUB_TOKEN }}
- name : Build base image
2023-06-12 10:14:32 +00:00
uses : home-assistant/builder@2023.06.0
2021-04-26 20:19:40 +00:00
with :
args : |
$BUILD_ARGS \
--target /data/machine \
2023-06-26 12:32:02 +00:00
--cosign \
2021-04-27 11:45:58 +00:00
--machine "${{ needs.init.outputs.version }}=${{ matrix.machine }}"
2021-11-24 08:48:34 +00:00
env :
CAS_API_KEY : ${{ secrets.CAS_TOKEN }}
2021-04-26 20:19:40 +00:00
publish_ha :
name : Publish version files
2023-05-30 17:43:59 +00:00
environment : ${{ needs.init.outputs.channel }}
2022-01-20 11:54:54 +00:00
if : github.repository_owner == 'home-assistant'
2021-04-26 20:19:40 +00:00
needs : [ "init" , "build_machine" ]
runs-on : ubuntu-latest
steps :
- name : Checkout the repository
2023-06-12 08:42:40 +00:00
uses : actions/checkout@v3.5.3
2021-04-26 20:19:40 +00:00
- name : Initialize git
uses : home-assistant/actions/helpers/git-init@master
with :
name : ${{ secrets.GIT_NAME }}
email : ${{ secrets.GIT_EMAIL }}
token : ${{ secrets.GIT_TOKEN }}
- name : Update version file
uses : home-assistant/actions/helpers/version-push@master
with :
key : "homeassistant[]"
key-description : "Home Assistant Core"
version : ${{ needs.init.outputs.version }}
channel : ${{ needs.init.outputs.channel }}
- name : Update version file (stable -> beta)
2021-04-27 08:36:13 +00:00
if : needs.init.outputs.channel == 'stable'
2021-04-26 20:19:40 +00:00
uses : home-assistant/actions/helpers/version-push@master
with :
key : "homeassistant[]"
key-description : "Home Assistant Core"
version : ${{ needs.init.outputs.version }}
channel : beta
publish_container :
2022-03-02 12:55:05 +00:00
name : Publish meta container for ${{ matrix.registry }}
2023-05-30 17:43:59 +00:00
environment : ${{ needs.init.outputs.channel }}
2022-01-20 11:54:54 +00:00
if : github.repository_owner == 'home-assistant'
2021-04-26 20:19:40 +00:00
needs : [ "init" , "build_base" ]
runs-on : ubuntu-latest
2023-06-27 07:29:45 +00:00
permissions :
contents : read
packages : write
id-token : write
2021-04-26 20:19:40 +00:00
steps :
- name : Checkout the repository
2023-06-12 08:42:40 +00:00
uses : actions/checkout@v3.5.3
2021-04-26 20:19:40 +00:00
2023-06-26 12:32:02 +00:00
- name : Install Cosign
2023-06-27 08:21:36 +00:00
uses : sigstore/cosign-installer@v3.1.0
2023-06-26 12:32:02 +00:00
with :
cosign-release : "v2.0.2"
2021-04-26 20:19:40 +00:00
- name : Login to DockerHub
2023-06-08 08:58:13 +00:00
uses : docker/login-action@v2.2.0
2021-04-26 20:19:40 +00:00
with :
username : ${{ secrets.DOCKERHUB_USERNAME }}
password : ${{ secrets.DOCKERHUB_TOKEN }}
- name : Login to GitHub Container Registry
2023-06-08 08:58:13 +00:00
uses : docker/login-action@v2.2.0
2021-04-26 20:19:40 +00:00
with :
registry : ghcr.io
username : ${{ github.repository_owner }}
password : ${{ secrets.GITHUB_TOKEN }}
- name : Build Meta Image
shell : bash
run : |
export DOCKER_CLI_EXPERIMENTAL=enabled
function create_manifest() {
2022-03-02 12:55:05 +00:00
local tag_l=${1}
local tag_r=${2}
2023-06-26 12:32:02 +00:00
for registry in "ghcr.io/home-assistant" "docker.io/homeassistant"
do
docker manifest create "${registry}/home-assistant:${tag_l}" \
"${registry}/amd64-homeassistant:${tag_r}" \
"${registry}/i386-homeassistant:${tag_r}" \
"${registry}/armhf-homeassistant:${tag_r}" \
"${registry}/armv7-homeassistant:${tag_r}" \
"${registry}/aarch64-homeassistant:${tag_r}"
2022-03-02 12:55:05 +00:00
2023-06-26 12:32:02 +00:00
docker manifest annotate "${registry}/home-assistant:${tag_l}" \
"${registry}/amd64-homeassistant:${tag_r}" \
--os linux --arch amd64
2021-04-26 20:19:40 +00:00
2023-06-26 12:32:02 +00:00
docker manifest annotate "${registry}/home-assistant:${tag_l}" \
"${registry}/i386-homeassistant:${tag_r}" \
--os linux --arch 386
2021-04-26 20:19:40 +00:00
2023-06-26 12:32:02 +00:00
docker manifest annotate "${registry}/home-assistant:${tag_l}" \
"${registry}/armhf-homeassistant:${tag_r}" \
--os linux --arch arm --variant=v6
2021-04-26 20:19:40 +00:00
2023-06-26 12:32:02 +00:00
docker manifest annotate "${registry}/home-assistant:${tag_l}" \
"${registry}/armv7-homeassistant:${tag_r}" \
--os linux --arch arm --variant=v7
2021-04-26 20:19:40 +00:00
2023-06-26 12:32:02 +00:00
docker manifest annotate "${registry}/home-assistant:${tag_l}" \
"${registry}/aarch64-homeassistant:${tag_r}" \
--os linux --arch arm64 --variant=v8
2021-04-26 20:19:40 +00:00
2023-06-26 12:32:02 +00:00
docker manifest push --purge "${registry}/home-assistant:${tag_l}"
cosign sign --yes "${registry}/home-assistant:${tag_l}"
done
2021-04-26 20:19:40 +00:00
}
function validate_image() {
2021-04-27 10:41:31 +00:00
local image=${1}
2023-06-26 12:32:02 +00:00
if ! cosign verify --certificate-oidc-issuer https://token.actions.githubusercontent.com --certificate-identity-regexp https://github.com/home-assistant/core/.* "${image}"; then
2021-04-26 20:19:40 +00:00
echo "Invalid signature!"
exit 1
fi
}
2023-06-26 12:32:02 +00:00
function push_dockerhub() {
local image=${1}
local tag=${2}
docker tag "ghcr.io/home-assistant/${image}:${tag}" "docker.io/homeassistant/${image}:${tag}"
docker push "docker.io/homeassistant/${image}:${tag}"
cosign sign --yes "docker.io/homeassistant/${image}:${tag}"
}
# Pull images from github container registry and verify signature
docker pull "ghcr.io/home-assistant/amd64-homeassistant:${{ needs.init.outputs.version }}"
docker pull "ghcr.io/home-assistant/i386-homeassistant:${{ needs.init.outputs.version }}"
docker pull "ghcr.io/home-assistant/armhf-homeassistant:${{ needs.init.outputs.version }}"
docker pull "ghcr.io/home-assistant/armv7-homeassistant:${{ needs.init.outputs.version }}"
docker pull "ghcr.io/home-assistant/aarch64-homeassistant:${{ needs.init.outputs.version }}"
validate_image "ghcr.io/home-assistant/amd64-homeassistant:${{ needs.init.outputs.version }}"
validate_image "ghcr.io/home-assistant/i386-homeassistant:${{ needs.init.outputs.version }}"
validate_image "ghcr.io/home-assistant/armhf-homeassistant:${{ needs.init.outputs.version }}"
validate_image "ghcr.io/home-assistant/armv7-homeassistant:${{ needs.init.outputs.version }}"
validate_image "ghcr.io/home-assistant/aarch64-homeassistant:${{ needs.init.outputs.version }}"
# Upload images to dockerhub
push_dockerhub "amd64-homeassistant" "${{ needs.init.outputs.version }}"
push_dockerhub "i386-homeassistant" "${{ needs.init.outputs.version }}"
push_dockerhub "armhf-homeassistant" "${{ needs.init.outputs.version }}"
push_dockerhub "armv7-homeassistant" "${{ needs.init.outputs.version }}"
push_dockerhub "aarch64-homeassistant" "${{ needs.init.outputs.version }}"
2022-03-02 12:55:05 +00:00
# Create version tag
create_manifest "${{ needs.init.outputs.version }}" "${{ needs.init.outputs.version }}"
# Create general tags
if [[ "${{ needs.init.outputs.version }}" =~ d ]]; then
2022-03-02 23:38:26 +00:00
create_manifest "dev" "${{ needs.init.outputs.version }}"
2022-03-02 12:55:05 +00:00
elif [[ "${{ needs.init.outputs.version }}" =~ b ]]; then
create_manifest "beta" "${{ needs.init.outputs.version }}"
create_manifest "rc" "${{ needs.init.outputs.version }}"
else
create_manifest "stable" "${{ needs.init.outputs.version }}"
create_manifest "latest" "${{ needs.init.outputs.version }}"
create_manifest "beta" "${{ needs.init.outputs.version }}"
create_manifest "rc" "${{ needs.init.outputs.version }}"
# Create series version tag (e.g. 2021.6)
v="${{ needs.init.outputs.version }}"
create_manifest "${v%.*}" "${{ needs.init.outputs.version }}"
fi