Update to newest build system

This commit is contained in:
Colin Seymour
2026-06-14 17:02:21 +00:00
parent 4c9e18d975
commit 4f844af772
2 changed files with 108 additions and 39 deletions
+57 -22
View File
@@ -11,41 +11,76 @@ on:
type: string type: string
jobs: jobs:
publish: init:
name: Publish name: Initialize build
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
packages: write outputs:
strategy: version: ${{ steps.version.outputs.version }}
matrix: matrix: ${{ steps.matrix.outputs.matrix }}
arch: ["amd64", "aarch64"]
steps: steps:
- name: Checkout the repository - name: Checkout the repository
uses: actions/checkout@v6.0.3 uses: actions/checkout@v6.0.3
- name: Get version - name: Get version
id: version
run: | run: |
version=${{ inputs.version }} version="${{ inputs.version }}"
if [ -n "$version" ]; then if [ -n "$version" ]; then
echo "latest_release=$version" >> $GITHUB_ENV echo "version=${version}" >> "$GITHUB_OUTPUT"
else else
echo "latest_release=$(curl --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" --silent https://api.github.com/repos/$GITHUB_REPOSITORY/releases/latest | jq -r .tag_name | sed s/v// )" >> $GITHUB_ENV echo "version=$(curl --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" --silent "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest" | jq -r .tag_name | sed s/v//)" >> "$GITHUB_OUTPUT"
fi fi
- name: Login to GitHub Container Registry - name: Build matrix
uses: docker/login-action@v4.2.0 id: matrix
with: run: |
registry: ghcr.io # Derive the per-arch build matrix from config.json. amd64 and aarch64
username: ${{ github.repository_owner }} # build on native runners (no QEMU). Base image, build args and labels
password: ${{ secrets.GITHUB_TOKEN }} # all live in the Dockerfile, so nothing extra is needed here.
image_template=$(jq -r '.image' config.json)
architectures=$(jq -r '.arch[]' config.json)
matrix='{"include":[]}'
for arch in $architectures; do
case "${arch}" in
amd64) os="ubuntu-24.04" ;;
aarch64) os="ubuntu-24.04-arm" ;;
*) echo "::error::Unsupported architecture: ${arch}"; exit 1 ;;
esac
image="${image_template//\{arch\}/${arch}}"
matrix=$(jq -c \
--arg arch "$arch" \
--arg os "$os" \
--arg image "$image" \
'.include += [{arch: $arch, os: $os, image: $image}]' <<< "${matrix}")
done
echo "matrix=${matrix}" >> "$GITHUB_OUTPUT"
build:
name: Build ${{ matrix.arch }} image
needs: init
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.init.outputs.matrix) }}
steps:
- name: Checkout the repository
uses: actions/checkout@v6.0.3
- name: Build and publish - name: Build and publish
uses: home-assistant/builder@2026.03.2 uses: home-assistant/builder/actions/build-image@2026.03.2
with: with:
args: | arch: ${{ matrix.arch }}
--${{ matrix.arch }} \ image: ${{ matrix.image }}
--version ${{ env.latest_release }} \ image-tags: |
--target /data/ \ ${{ needs.init.outputs.version }}
--addon latest
container-registry-password: ${{ secrets.GITHUB_TOKEN }}
push: "true"
cosign: "false"
version: ${{ needs.init.outputs.version }}
+51 -17
View File
@@ -5,9 +5,6 @@ on:
branches: branches:
- main - main
paths: paths:
- build.yaml
- config.yaml
- build.json
- config.json - config.json
- Dockerfile - Dockerfile
- rootfs/** - rootfs/**
@@ -15,34 +12,71 @@ on:
branches: branches:
- main - main
paths: paths:
- build.yaml
- config.yaml
- build.json
- config.json - config.json
- Dockerfile - Dockerfile
- rootfs/** - rootfs/**
jobs: jobs:
build: init:
name: Initialize build
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Build add-on permissions:
contents: read
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Check out repository
uses: actions/checkout@v6.0.3
- name: Build matrix
id: matrix
run: |
# Derive the per-arch build matrix from config.json. amd64 and aarch64
# build on native runners (no QEMU). Base image, build args and labels
# all live in the Dockerfile, so nothing extra is needed here.
image_template=$(jq -r '.image' config.json)
architectures=$(jq -r '.arch[]' config.json)
matrix='{"include":[]}'
for arch in $architectures; do
case "${arch}" in
amd64) os="ubuntu-24.04" ;;
aarch64) os="ubuntu-24.04-arm" ;;
*) echo "::error::Unsupported architecture: ${arch}"; exit 1 ;;
esac
image="${image_template//\{arch\}/${arch}}"
matrix=$(jq -c \
--arg arch "$arch" \
--arg os "$os" \
--arg image "$image" \
'.include += [{arch: $arch, os: $os, image: $image}]' <<< "${matrix}")
done
echo "matrix=${matrix}" >> "$GITHUB_OUTPUT"
build:
name: Build ${{ matrix.arch }} add-on
needs: init
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy: strategy:
matrix: fail-fast: false
arch: ["amd64", "aarch64"] matrix: ${{ fromJSON(needs.init.outputs.matrix) }}
steps: steps:
- name: Check out repository - name: Check out repository
uses: actions/checkout@v6.0.3 uses: actions/checkout@v6.0.3
- name: Build add-on - name: Build add-on
uses: home-assistant/builder@2026.03.2 uses: home-assistant/builder/actions/build-image@2026.03.2
with: with:
args: | arch: ${{ matrix.arch }}
--test \ image: ${{ matrix.image }}
--${{ matrix.arch }} \ image-tags: test
--target /data/ \ container-registry-password: ${{ secrets.GITHUB_TOKEN }}
--addon load: "true"
cosign: "false"
version: test
- name: Image labels - name: Image labels
run: | run: |
docker inspect ghcr.io/lildude/ha-addon-teslamate-${{ matrix.arch }} --format='{{json .Config.Labels}}' | jq docker inspect ${{ matrix.image }}:test --format='{{json .Config.Labels}}' | jq