JH Build images #125
This file contains 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: JH Build images | |
# yamllint disable-line rule:truthy | |
on: | |
workflow_dispatch: | |
release: | |
types: ["published"] | |
schedule: | |
- cron: "0 6 * * *" | |
env: | |
BUILD_TYPE: core | |
DEFAULT_PYTHON: "3.10" | |
jobs: | |
init: | |
name: Initialize build | |
if: github.repository_owner == 'jethub-homeassistant' | |
runs-on: ${{ vars.RUNNER }} | |
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 | |
uses: actions/[email protected] | |
with: | |
fetch-depth: 0 | |
- name: update build.yaml | |
run: cp -f build-jethub.yaml build.yaml | |
- name: Set up Python ${{ env.DEFAULT_PYTHON }} | |
uses: actions/[email protected] | |
with: | |
python-version: ${{ env.DEFAULT_PYTHON }} | |
- name: Get information | |
id: info | |
uses: jethub-homeassistant/actions/helpers/info@master-jethub | |
- name: Get version | |
id: version | |
uses: jethub-homeassistant/actions/helpers/version@master-jethub | |
with: | |
type: ${{ env.BUILD_TYPE }} | |
- name: Verify version | |
uses: jethub-homeassistant/actions/helpers/verify-version@master-jethub | |
with: | |
ignore-dev: true | |
- name: Generate meta info | |
shell: bash | |
run: | | |
echo "${{ github.sha }};${{ github.ref }};${{ github.event_name }};${{ github.actor }}" > OFFICIAL_IMAGE | |
- name: Signing meta info file | |
uses: jethub-homeassistant/actions/helpers/codenotary@master-jethub | |
with: | |
source: file://${{ github.workspace }}/OFFICIAL_IMAGE | |
asset: OFFICIAL_IMAGE-${{ steps.version.outputs.version }} | |
token: ${{ secrets.CAS_TOKEN }} | |
build_python: | |
name: Build PyPi package | |
needs: ["init", "build_base"] | |
runs-on: ${{ vars.RUNNER }} | |
if: 0 # github.repository_owner == 'jethub-homeassistant' && needs.init.outputs.publish == 'true' | |
steps: | |
- name: Checkout the repository | |
uses: actions/[email protected] | |
- name: update build.yaml | |
run: cp -f build-jethub.yaml build.yaml | |
- name: Set up Python ${{ env.DEFAULT_PYTHON }} | |
uses: actions/[email protected] | |
with: | |
python-version: ${{ env.DEFAULT_PYTHON }} | |
- name: Download Translations | |
uses: transifex/cli-action@v2 | |
with: | |
token: ${{ secrets.TX_TOKEN }} | |
args: pull -s -t -a | |
- name: Write Translations | |
run: python3 -m script.jhtranslations download | |
- name: Build package | |
shell: bash | |
run: | | |
# Remove dist, build, and homeassistant.egg-info | |
# when build locally for testing! | |
pip install twine build | |
python -m build | |
- 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 | |
if: github.repository_owner == 'jethub-homeassistant' | |
needs: init | |
runs-on: ${{ vars.RUNNER }} | |
strategy: | |
matrix: | |
arch: ${{ fromJson(needs.init.outputs.architectures) }} | |
steps: | |
- name: Checkout the repository | |
uses: actions/[email protected] | |
- name: update build.yaml | |
run: cp -f build-jethub.yaml build.yaml | |
- 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 | |
workflow: nightly.yaml | |
workflow_conclusion: success | |
name: wheels | |
- name: Download nightly wheels of intents | |
if: needs.init.outputs.channel == 'dev' | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
github_token: ${{secrets.GITHUB_TOKEN}} | |
repo: home-assistant/intents-package | |
branch: main | |
workflow: nightly.yaml | |
workflow_conclusion: success | |
name: package | |
- name: Set up Python ${{ env.DEFAULT_PYTHON }} | |
if: needs.init.outputs.channel == 'dev' | |
uses: actions/[email protected] | |
with: | |
python-version: ${{ env.DEFAULT_PYTHON }} | |
- name: Adjust nightly version | |
if: needs.init.outputs.channel == 'dev' | |
shell: bash | |
run: | | |
python3 -m pip install packaging tomli | |
python3 -m pip install . | |
version="$(python3 script/version_bump.py nightly)" | |
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 | |
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 | |
sed -i "s|home-assistant-intents==.*|home-assistant-intents==${BASH_REMATCH[1]}|" \ | |
homeassistant/package_constraints.txt | |
python -m script.gen_requirements_all | |
fi | |
- 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. | |
sed -i "s|env-canada|# env-canada|g" requirements_all.txt | |
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 | |
- name: Download Translations | |
uses: transifex/cli-action@v2 | |
with: | |
token: ${{ secrets.TX_TOKEN }} | |
args: pull -s -t -a | |
- name: Write Translations | |
run: python3 -m script.jhtranslations download | |
- name: Write meta info file | |
shell: bash | |
run: | | |
echo "${{ github.sha }};${{ github.ref }};${{ github.event_name }};${{ github.actor }}" > rootfs/OFFICIAL_IMAGE | |
- name: Login to DockerHub | |
uses: docker/[email protected] | |
with: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build base image | |
uses: jethub-homeassistant/[email protected] | |
with: | |
args: | | |
$BUILD_ARGS \ | |
--${{ matrix.arch }} \ | |
--target /data \ | |
--generic ${{ needs.init.outputs.version }} | |
env: | |
CAS_API_KEY: ${{ secrets.CAS_TOKEN }} | |
- 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 | |
build_machine: | |
name: Build ${{ matrix.machine }} machine core image | |
if: github.repository_owner == 'jethub-homeassistant' | |
needs: ["init", "build_base"] | |
runs-on: ${{ vars.RUNNER }} | |
strategy: | |
matrix: | |
machine: | |
- generic-x86-64 | |
- intel-nuc | |
- jethub-h1 | |
- jethub-h2 | |
- jethub-d1 | |
- jethub-d1p | |
- odroid-c4 | |
- qemuarm | |
- qemuarm-64 | |
steps: | |
- name: Checkout the repository | |
uses: actions/[email protected] | |
- name: update build.yaml | |
run: cp -f build-jethub.yaml build.yaml | |
- 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 | |
- name: Login to DockerHub | |
uses: docker/[email protected] | |
with: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build base image | |
uses: jethub-homeassistant/[email protected] | |
with: | |
args: | | |
$BUILD_ARGS \ | |
--target /data/machine \ | |
--machine "${{ needs.init.outputs.version }}=${{ matrix.machine }}" | |
env: | |
CAS_API_KEY: ${{ secrets.CAS_TOKEN }} | |
publish_ha: | |
name: Publish version files | |
if: github.repository_owner == 'jethub-homeassistant' | |
needs: ["init", "build_machine"] | |
runs-on: ${{ vars.RUNNER }} | |
steps: | |
- name: Checkout the repository | |
uses: actions/[email protected] | |
- name: update build.yaml | |
run: cp -f build-jethub.yaml build.yaml | |
- name: Initialize git | |
uses: jethub-homeassistant/actions/helpers/git-init@master-jethub | |
with: | |
name: ${{ secrets.GIT_NAME }} | |
email: ${{ secrets.GIT_EMAIL }} | |
token: ${{ secrets.GIT_TOKEN }} | |
- name: Update version file | |
uses: jethub-homeassistant/actions/helpers/version-push@master-jethub | |
with: | |
key: "homeassistant[]" | |
key-description: "Home Assistant Core" | |
version: ${{ needs.init.outputs.version }} | |
channel: ${{ needs.init.outputs.channel }} | |
- name: Update version file (stable -> beta) | |
if: needs.init.outputs.channel == 'stable' | |
uses: jethub-homeassistant/actions/helpers/version-push@master-jethub | |
with: | |
key: "homeassistant[]" | |
key-description: "Home Assistant Core" | |
version: ${{ needs.init.outputs.version }} | |
channel: beta | |
publish_container: | |
name: Publish meta container for ${{ matrix.registry }} | |
if: github.repository_owner == 'jethub-homeassistant' | |
needs: ["init", "build_base"] | |
runs-on: ${{ vars.RUNNER }} | |
strategy: | |
fail-fast: false | |
matrix: | |
registry: | |
- "ghcr.io/jethub-homeassistant" | |
- "jethubjhaos" | |
steps: | |
- name: Checkout the repository | |
uses: actions/[email protected] | |
- name: update build.yaml | |
run: cp -f build-jethub.yaml build.yaml | |
- name: Login to DockerHub | |
if: matrix.registry == 'jethubjhaos' | |
uses: docker/[email protected] | |
with: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
if: matrix.registry == 'ghcr.io/jethub-homeassistant' | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Install CAS tools | |
uses: jethub-homeassistant/actions/helpers/cas@master-jethub | |
- name: Build Meta Image | |
shell: bash | |
run: | | |
export DOCKER_CLI_EXPERIMENTAL=enabled | |
function create_manifest() { | |
local tag_l=${1} | |
local tag_r=${2} | |
docker manifest create "${{ matrix.registry }}/jethub-homeassistant:${tag_l}" \ | |
"${{ matrix.registry }}/amd64-homeassistant:${tag_r}" \ | |
"${{ matrix.registry }}/i386-homeassistant:${tag_r}" \ | |
"${{ matrix.registry }}/armhf-homeassistant:${tag_r}" \ | |
"${{ matrix.registry }}/armv7-homeassistant:${tag_r}" \ | |
"${{ matrix.registry }}/aarch64-homeassistant:${tag_r}" | |
docker manifest annotate "${{ matrix.registry }}/jethub-homeassistant:${tag_l}" \ | |
"${{ matrix.registry }}/amd64-homeassistant:${tag_r}" \ | |
--os linux --arch amd64 | |
docker manifest annotate "${{ matrix.registry }}/jethub-homeassistant:${tag_l}" \ | |
"${{ matrix.registry }}/i386-homeassistant:${tag_r}" \ | |
--os linux --arch 386 | |
docker manifest annotate "${{ matrix.registry }}/jethub-homeassistant:${tag_l}" \ | |
"${{ matrix.registry }}/armhf-homeassistant:${tag_r}" \ | |
--os linux --arch arm --variant=v6 | |
docker manifest annotate "${{ matrix.registry }}/jethub-homeassistant:${tag_l}" \ | |
"${{ matrix.registry }}/armv7-homeassistant:${tag_r}" \ | |
--os linux --arch arm --variant=v7 | |
docker manifest annotate "${{ matrix.registry }}/jethub-homeassistant:${tag_l}" \ | |
"${{ matrix.registry }}/aarch64-homeassistant:${tag_r}" \ | |
--os linux --arch arm64 --variant=v8 | |
docker manifest push --purge "${{ matrix.registry }}/jethub-homeassistant:${tag_l}" | |
} | |
function validate_image() { | |
local image=${1} | |
if ! cas authenticate --signerID [email protected] "docker://${image}"; then | |
echo "Invalid signature!" | |
exit 1 | |
fi | |
} | |
docker pull "${{ matrix.registry }}/amd64-homeassistant:${{ needs.init.outputs.version }}" | |
docker pull "${{ matrix.registry }}/i386-homeassistant:${{ needs.init.outputs.version }}" | |
docker pull "${{ matrix.registry }}/armhf-homeassistant:${{ needs.init.outputs.version }}" | |
docker pull "${{ matrix.registry }}/armv7-homeassistant:${{ needs.init.outputs.version }}" | |
docker pull "${{ matrix.registry }}/aarch64-homeassistant:${{ needs.init.outputs.version }}" | |
validate_image "${{ matrix.registry }}/amd64-homeassistant:${{ needs.init.outputs.version }}" | |
validate_image "${{ matrix.registry }}/i386-homeassistant:${{ needs.init.outputs.version }}" | |
validate_image "${{ matrix.registry }}/armhf-homeassistant:${{ needs.init.outputs.version }}" | |
validate_image "${{ matrix.registry }}/armv7-homeassistant:${{ needs.init.outputs.version }}" | |
validate_image "${{ matrix.registry }}/aarch64-homeassistant:${{ needs.init.outputs.version }}" | |
# Create version tag | |
create_manifest "${{ needs.init.outputs.version }}" "${{ needs.init.outputs.version }}" | |
# Create general tags | |
if [[ "${{ needs.init.outputs.version }}" =~ d ]]; then | |
create_manifest "dev" "${{ needs.init.outputs.version }}" | |
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 |