Skip to content

CI

CI #2235

Workflow file for this run

name: CI
on:
push:
pull_request:
workflow_dispatch:
inputs:
type:
description: 'Type (edge/proxy)'
default: 'edge'
required: true
jobs:
variables:
runs-on: ubuntu-latest
outputs:
ARCH_LIST: ${{ env.ARCH_LIST }}
ADDON_LIST: ${{ env.ADDON_LIST }}
BUILD_ARGS: ${{ env.BUILD_ARGS }}
steps:
- uses: actions/checkout@v3
- name: "ARGS: default"
run: |
echo "ADDON_LIST=['zigbee2mqtt', 'zigbee2mqtt-edge']" >> $GITHUB_ENV
echo "BUILD_ARGS=--no-latest --test" >> $GITHUB_ENV
- name: "ARGS: zigbee2mqtt-proxy" # Build of addon proxy version
if: github.ref == 'refs/heads/master' && (github.event_name == 'workflow_dispatch' && github.event.inputs.type == 'proxy')
run: |
echo "ADDON_LIST=['zigbee2mqtt-proxy']" >> $GITHUB_ENV
echo "BUILD_ARGS=--no-cache" >> $GITHUB_ENV
- name: "ARGS: zigbee2mqtt-edge" # Build of addon edge version
if: github.ref == 'refs/heads/master' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.type == 'edge'))
run: |
echo "ADDON_LIST=['zigbee2mqtt-edge']" >> $GITHUB_ENV
echo "BUILD_ARGS=--no-cache" >> $GITHUB_ENV
- name: "ARGS: zigbee2mqtt" # Build of addon release version
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
run: |
echo "ADDON_LIST=['zigbee2mqtt']" >> $GITHUB_ENV
echo "BUILD_ARGS=--no-cache --docker-hub-check" >> $GITHUB_ENV
- name: Determine arch
id: determine_arch
run: |
ARCH_LIST=$(jq -r -c '.arch' ./${{ fromJSON(env.ADDON_LIST)[0] }}/config.json)
echo "Found the following arches: $ARCH_LIST"
echo "ARCH_LIST=$ARCH_LIST" >> $GITHUB_ENV
build:
runs-on: ubuntu-latest
needs: variables
env:
BUILD_ARGS: ${{needs.variables.outputs.BUILD_ARGS}}
strategy:
matrix:
arch: ${{fromJSON(needs.variables.outputs.ARCH_LIST)}}
addon: ${{fromJSON(needs.variables.outputs.ADDON_LIST)}}
steps:
- uses: actions/checkout@v3
- name: Log in to docker.io
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
uses: docker/login-action@v3
with:
username: koenkk
password: ${{ secrets.DOCKER_KEY }}
- name: Log in to ghcr.io
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: koenkk
password: ${{ secrets.GH_TOKEN }}
- name: Prepare data folder
run: |
if [ "${{ matrix.addon }}" != "zigbee2mqtt-proxy" ]; then
cp -R common/rootfs ${{ matrix.addon }}
cp common/Dockerfile ${{ matrix.addon }}
fi
cp common/build.yaml ${{ matrix.addon }}
- name: Build
uses: home-assistant/builder@master
# Note: if running without `--test`, image is pushed to docker.io
with:
args: |
--${{ matrix.arch }} \
--target ${{ matrix.addon }} \
${{ env.BUILD_ARGS }}
# Keep pushing to docker.io as it is unclear how
# HA handles config.json updates (especially for the unversioned edge)
- name: Push to docker.io
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
run: |
CONFIG_IMAGE=$(cat ${{ matrix.addon }}/config.json | jq -r '.image | sub("{arch}"; "${{ matrix.arch }}")')
CONFIG_VERSION=$(cat ${{ matrix.addon }}/config.json | jq -r .version)
VERSIONS=("latest" "$CONFIG_VERSION")
for VERSION in "${VERSIONS[@]}"; do
GHCR_IMAGE="$CONFIG_IMAGE:$CONFIG_VERSION"
DOCKER_IO_IMAGE=$(echo "$GHCR_IMAGE" | sed 's|ghcr\.io\/||')
echo "Push: $GHCR_IMAGE -> $DOCKER_IO_IMAGE"
docker pull $GHCR_IMAGE
docker tag $GHCR_IMAGE $DOCKER_IO_IMAGE
docker push $DOCKER_IO_IMAGE
done