mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-10 09:51:02 +01:00
277 lines
11 KiB
YAML
277 lines
11 KiB
YAML
# shellcheck disable=SC2076,SC2059
|
||
name: Check PR Build
|
||
on:
|
||
pull_request:
|
||
branches:
|
||
- master
|
||
|
||
jobs:
|
||
check-addon-changes:
|
||
runs-on: ubuntu-latest
|
||
outputs:
|
||
changedAddons: ${{ steps.filter.outputs.changes }}
|
||
changedChangelogFiles: ${{ steps.changed-files.outputs.changelogs_files }}
|
||
steps:
|
||
- name: ↩️ Checkout
|
||
uses: actions/checkout@v2
|
||
|
||
- name: 📂 Detect chanced addons
|
||
uses: dorny/paths-filter@v2
|
||
id: filter
|
||
with:
|
||
filters: .github/paths-filter.yml
|
||
|
||
- name: 📂 Detect chanced files
|
||
uses: dorny/paths-filter@v2
|
||
id: changed-files
|
||
with:
|
||
list-files: csv
|
||
filters: |
|
||
changelogs:
|
||
- '**/CHANGELOG.md'
|
||
check-changed-changelog:
|
||
name: Check if CHANGELOG.md changed
|
||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
||
runs-on: ubuntu-latest
|
||
needs: check-addon-changes
|
||
strategy:
|
||
fail-fast: false
|
||
matrix:
|
||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
||
steps:
|
||
- name: 🔎 Check for updated CHANGELOG.md
|
||
shell: bash
|
||
run: |
|
||
if [[ ! "${{ needs.check-addon-changes.outputs.changedChangelogFiles }}" =~ "${{ matrix.addon }}/CHANGELOG.md" ]]; then
|
||
echo "::error::No new entries in ${{ matrix.addon }} CHANGELOG.md file!"
|
||
exit 1
|
||
fi
|
||
check-version-matching:
|
||
name: Check for same addon versions
|
||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
||
runs-on: ubuntu-latest
|
||
needs: check-addon-changes
|
||
strategy:
|
||
fail-fast: false
|
||
matrix:
|
||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
||
steps:
|
||
- name: ↩️ Checkout
|
||
uses: actions/checkout@v2
|
||
|
||
- name: 🔎 Check if versions of CHANGELOG.md and config.json match
|
||
shell: bash
|
||
run: |
|
||
config_version=$(sed -nr "s/.*version.*\"(.+)\".*/\1/p" "${{ matrix.addon }}/config.json")
|
||
changelog_version=$(sed -nr "0,/#{1,2}\s+(\S+)\s+-.*/{s//\1/p}" "${{ matrix.addon }}/CHANGELOG.md")
|
||
if [[ ! "$config_version" = "$changelog_version" ]]; then
|
||
echo "::error::The config version does not match the latest Changelog version!"
|
||
exit 1
|
||
fi
|
||
check-addon-label:
|
||
name: Check for existance of the addon label
|
||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
||
runs-on: ubuntu-latest
|
||
needs: check-addon-changes
|
||
strategy:
|
||
fail-fast: false
|
||
matrix:
|
||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
||
steps:
|
||
- name: ↩️ Checkout
|
||
uses: actions/checkout@v2
|
||
|
||
- name: 🔎 Check if a label for the addon exists
|
||
shell: bash
|
||
run: |
|
||
labeltext=$(sed -nr "s/name:\s(${{ matrix.addon }}).*/\1/p" '.github/labels.yaml')
|
||
if [[ -z "$labeltext" ]]; then
|
||
echo "::error::There is no label for this addon! Please add it to .github/labels.yaml and .github/labeler.yaml"
|
||
exit 1
|
||
fi
|
||
addon-linter:
|
||
name: Addon linting
|
||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
||
runs-on: ubuntu-latest
|
||
needs: check-addon-changes
|
||
strategy:
|
||
fail-fast: false
|
||
matrix:
|
||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
||
steps:
|
||
- name: ↩️ Checkout
|
||
uses: actions/checkout@v2
|
||
|
||
- name: 🔎 Run Home Assistant Add-on Lint
|
||
uses: frenck/action-addon-linter@v2
|
||
with:
|
||
path: "./${{ matrix.addon }}"
|
||
|
||
check-build:
|
||
name: Test addon build
|
||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
||
runs-on: ubuntu-latest
|
||
needs: check-addon-changes
|
||
strategy:
|
||
fail-fast: false
|
||
matrix:
|
||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
||
steps:
|
||
- name: ↩️ Checkout
|
||
uses: actions/checkout@v2
|
||
|
||
- name: ℹ️ Gather addon info
|
||
id: information
|
||
uses: frenck/action-addon-information@v1.3.1
|
||
with:
|
||
path: "./${{ matrix.addon }}/"
|
||
|
||
- name: 🗄️ Cache docker layers
|
||
uses: actions/cache@v2
|
||
with:
|
||
path: /tmp/buildx-cache
|
||
key: ${{ runner.os }}-buildx-${{ matrix.addon }}-${{ hashFiles('**/Dockerfile') }}
|
||
restore-keys: ${{ runner.os }}-buildx-${{ matrix.addon }}-
|
||
|
||
- name: 🔖 Create addon image tags
|
||
id: tags
|
||
shell: bash
|
||
run: |
|
||
imagetemplate=${{ steps.information.outputs.image }}
|
||
version=${{ steps.information.outputs.version }}
|
||
echo "Using imagetemplate '$imagetemplate'"
|
||
echo "::set-output name=armhf::${imagetemplate/\{arch\}/armhf}:${version}"
|
||
echo "::set-output name=armv7::${imagetemplate/\{arch\}/armv7}:${version}"
|
||
echo "::set-output name=aarch64::${imagetemplate/\{arch\}/aarch64}:${version}"
|
||
echo "::set-output name=amd64::${imagetemplate/\{arch\}/amd64}:${version}"
|
||
echo "::set-output name=i386::${imagetemplate/\{arch\}/i386}:${version}"
|
||
- name: 🏷️ Create addon labels
|
||
id: labels
|
||
shell: bash
|
||
run: |
|
||
labels="io.hass.version=${{ steps.information.outputs.version }}"
|
||
labels=$(printf "$labels\nio.hass.name=${{ steps.information.outputs.name }}")
|
||
labels=$(printf "$labels\nio.hass.description=${{ steps.information.outputs.description }}")
|
||
labels=$(printf "$labels\nio.hass.type=addon")
|
||
labels=$(printf "$labels\nio.hass.url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/master/${{ matrix.addon }}")
|
||
labels=$(printf "$labels\norg.opencontainers.image.title=${{ steps.information.outputs.name }}")
|
||
labels=$(printf "$labels\norg.opencontainers.image.description=${{ steps.information.outputs.description }}")
|
||
labels=$(printf "$labels\norg.opencontainers.image.version=${{ steps.information.outputs.version }}")
|
||
labels=$(printf "$labels\norg.opencontainers.image.authors=Poeschl <Poeschl@users.noreply.github.com>")
|
||
labels=$(printf "$labels\norg.opencontainers.image.url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}")
|
||
labels=$(printf "$labels\norg.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/master/${{ matrix.addon }}")
|
||
labels=$(printf "$labels\norg.opencontainers.image.created=$(date -Is)")
|
||
labels=$(printf "$labels\norg.opencontainers.image.revision=${GITHUB_SHA}")
|
||
echo "Generic labels: $labels"
|
||
armhf_labels=$(printf "$labels\nio.hass.arch=armhf")
|
||
armv7_labels=$(printf "$labels\nio.hass.arch=armv7")
|
||
aarch64_labels=$(printf "$labels\nio.hass.arch=aarch64")
|
||
amd64_labels=$(printf "$labels\nio.hass.arch=amd64")
|
||
i386_labels=$(printf "$labels\nio.hass.arch=i386")
|
||
# allow multiline outputs, see https://github.community/t/set-output-truncates-multiline-strings/16852
|
||
armhf_labels="${armhf_labels//$'\n'/'%0A'}"
|
||
armv7_labels="${armv7_labels//$'\n'/'%0A'}"
|
||
aarch64_labels="${aarch64_labels//$'\n'/'%0A'}"
|
||
amd64_labels="${amd64_labels//$'\n'/'%0A'}"
|
||
i386_labels="${i386_labels//$'\n'/'%0A'}"
|
||
echo "::set-output name=armhf::$armhf_labels"
|
||
echo "::set-output name=armv7::$armv7_labels"
|
||
echo "::set-output name=aarch64::$aarch64_labels"
|
||
echo "::set-output name=amd64::$amd64_labels"
|
||
echo "::set-output name=i386::$i386_labels"
|
||
- name: 💽 Create addon build-args
|
||
id: build_args
|
||
shell: bash
|
||
run: |
|
||
echo "::set-output name=armhf::BUILD_FROM=$(jq -r '.build_from.armhf // empty' ${{ steps.information.outputs.build }})"
|
||
echo "::set-output name=armv7::BUILD_FROM=$(jq -r '.build_from.armv7 // empty' ${{ steps.information.outputs.build }})"
|
||
echo "::set-output name=aarch64::BUILD_FROM=$(jq -r '.build_from.aarch64 // empty' ${{ steps.information.outputs.build }})"
|
||
echo "::set-output name=amd64::BUILD_FROM=$(jq -r '.build_from.amd64 // empty' ${{ steps.information.outputs.build }})"
|
||
echo "::set-output name=i386::BUILD_FROM=$(jq -r '.build_from.i386 // empty' ${{ steps.information.outputs.build }})"
|
||
- name: 🏗️ Set up QEMU
|
||
uses: docker/setup-qemu-action@v1
|
||
|
||
- name: 🏗️ Set up Docker Buildx
|
||
uses: docker/setup-buildx-action@v1
|
||
|
||
- name: 💿 Build Addon - armhf
|
||
if: ${{ steps.information.outputs.armhf == 'true' }}
|
||
uses: docker/build-push-action@v2
|
||
with:
|
||
context: ${{ matrix.addon }}
|
||
push: false
|
||
load: true
|
||
file: ${{ matrix.addon }}/Dockerfile
|
||
tags: ${{ steps.tags.outputs.armhf }}
|
||
labels: |
|
||
${{ steps.labels.outputs.armhf }}
|
||
build-args: ${{ steps.build_args.outputs.armhf }}
|
||
cache-from: type=local,src=/tmp/buildx-cache/armhf
|
||
cache-to: type=local,dest=/tmp/buildx-cache-new/armhf
|
||
|
||
- name: 💿 Build Addon - armv7
|
||
if: ${{ steps.information.outputs.armv7 == 'true' }}
|
||
uses: docker/build-push-action@v2
|
||
with:
|
||
context: ${{ matrix.addon }}
|
||
push: false
|
||
load: true
|
||
file: ${{ matrix.addon }}/Dockerfile
|
||
tags: ${{ steps.tags.outputs.armv7 }}
|
||
labels: |
|
||
${{ steps.labels.outputs.armv7 }}
|
||
build-args: ${{ steps.build_args.outputs.armv7 }}
|
||
cache-from: type=local,src=/tmp/buildx-cache/armv7
|
||
cache-to: type=local,dest=/tmp/buildx-cache-new/armv7
|
||
|
||
- name: 💿 Build Addon - aarch64
|
||
if: ${{ steps.information.outputs.aarch64 == 'true' }}
|
||
uses: docker/build-push-action@v2
|
||
with:
|
||
context: ${{ matrix.addon }}
|
||
push: false
|
||
load: true
|
||
file: ${{ matrix.addon }}/Dockerfile
|
||
tags: ${{ steps.tags.outputs.aarch64 }}
|
||
labels: |
|
||
${{ steps.labels.outputs.aarch64 }}
|
||
build-args: ${{ steps.build_args.outputs.aarch64 }}
|
||
cache-from: type=local,src=/tmp/buildx-cache/aarch64
|
||
cache-to: type=local,dest=/tmp/buildx-cache-new/aarch64
|
||
|
||
- name: 💿 Build Addon - amd64
|
||
if: ${{ steps.information.outputs.amd64 == 'true' }}
|
||
uses: docker/build-push-action@v2
|
||
with:
|
||
context: ${{ matrix.addon }}
|
||
push: false
|
||
load: true
|
||
file: ${{ matrix.addon }}/Dockerfile
|
||
tags: ${{ steps.tags.outputs.amd64 }}
|
||
labels: |
|
||
${{ steps.labels.outputs.amd64 }}
|
||
build-args: ${{ steps.build_args.outputs.amd64 }}
|
||
cache-from: type=local,src=/tmp/buildx-cache/amd64
|
||
cache-to: type=local,dest=/tmp/buildx-cache-new/amd64
|
||
|
||
- name: 💿 Build Addon - i386
|
||
if: ${{ steps.information.outputs.i386 == 'true' }}
|
||
uses: docker/build-push-action@v2
|
||
with:
|
||
context: ${{ matrix.addon }}
|
||
push: false
|
||
load: true
|
||
file: ${{ matrix.addon }}/Dockerfile
|
||
tags: ${{ steps.tags.outputs.i386 }}
|
||
labels: |
|
||
${{ steps.labels.outputs.i386 }}
|
||
build-args: ${{ steps.build_args.outputs.i386 }}
|
||
cache-from: type=local,src=/tmp/buildx-cache/i386
|
||
cache-to: type=local,dest=/tmp/buildx-cache-new/i386
|
||
|
||
# Fix for https://github.com/docker/build-push-action/issues/252
|
||
- name: 🗄️ Update cache Folder
|
||
run: |
|
||
rm -rf /tmp/buildx-cache
|
||
mv /tmp/buildx-cache-new /tmp/buildx-cache
|