From b615cfcd6c30552732c1437459801ce4c952d954 Mon Sep 17 00:00:00 2001 From: Max Winterstein Date: Mon, 28 Nov 2022 23:27:47 +0100 Subject: [PATCH] :construction_worker: Add automated builds --- .github/paths-filter.yml | 5 + .../eufy_create_mr_and_build_image.yaml | 25 -- .../workflows/eufy_manually_build_image.yml | 34 --- .github/workflows/onpr_check-pr.yaml | 260 ++++++++++++++++++ .github/workflows/onpush_build.yaml | 104 +++++++ .../workflows/toogoodtogo-ha-mqtt-bridge.yml | 33 --- 6 files changed, 369 insertions(+), 92 deletions(-) create mode 100644 .github/paths-filter.yml delete mode 100644 .github/workflows/eufy_manually_build_image.yml create mode 100644 .github/workflows/onpr_check-pr.yaml create mode 100644 .github/workflows/onpush_build.yaml delete mode 100644 .github/workflows/toogoodtogo-ha-mqtt-bridge.yml diff --git a/.github/paths-filter.yml b/.github/paths-filter.yml new file mode 100644 index 0000000..3a877ef --- /dev/null +++ b/.github/paths-filter.yml @@ -0,0 +1,5 @@ +# AUTO BUILDS # +# From https://github.com/Poeschl/Hassio-Addons +# name: slug/filename ; could be slug/config.* for all files +adsb-multi-portal-feeder: adsb-multi-portal-feeder/config.* # Image : yes +angry-ip-scanner: angry-ip-scanner/config.* # Image : yes diff --git a/.github/workflows/eufy_create_mr_and_build_image.yaml b/.github/workflows/eufy_create_mr_and_build_image.yaml index d4d3214..f4fafef 100644 --- a/.github/workflows/eufy_create_mr_and_build_image.yaml +++ b/.github/workflows/eufy_create_mr_and_build_image.yaml @@ -14,31 +14,6 @@ jobs: - run: cd eufy-ha-mqtt-bridge && ./version-updater.sh - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - if: ${{ env.CONTINUE }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - if: ${{ env.CONTINUE }} - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - if: ${{ env.CONTINUE }} - - - name: Test build - uses: home-assistant/builder@2022.11.0 - with: - args: | - --all \ - --aarch64 \ - --target eufy-ha-mqtt-bridge \ - --docker-hub maxwinterstein - if: ${{ env.CONTINUE }} - - name: Create Pull Request uses: peter-evans/create-pull-request@v4 with: diff --git a/.github/workflows/eufy_manually_build_image.yml b/.github/workflows/eufy_manually_build_image.yml deleted file mode 100644 index 30af338..0000000 --- a/.github/workflows/eufy_manually_build_image.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: eufy_manually_build_image - -on: - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - inputs: - version: - description: "Image Tag" - required: true - -jobs: - eufy-ha-mqtt-bridge: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Test build - uses: home-assistant/builder@2022.11.0 - with: - args: | - --all \ - --aarch64 \ - --target eufy-ha-mqtt-bridge \ - --docker-hub maxwinterstein diff --git a/.github/workflows/onpr_check-pr.yaml b/.github/workflows/onpr_check-pr.yaml new file mode 100644 index 0000000..c90bb04 --- /dev/null +++ b/.github/workflows/onpr_check-pr.yaml @@ -0,0 +1,260 @@ +# yamllint disable rule:line-length +# shellcheck disable=SC2043 +--- +name: Check PR Build +on: + pull_request: + branches: + - main + +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@v3 + + - 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: | + # shellcheck disable=SC2076,SC2059 + 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-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@v3 + + - name: 🔎 Check if a label for the addon exists + shell: bash + run: | + labeltext=$(sed -nr "/${{ matrix.addon }}/p" '.github/paths-filter.yml') + if [[ -z "$labeltext" ]]; then + echo "::error::There is no label for this addon! Please add it to .github/paths-filter.yml" + exit 1 + fi + addon-linter: + name: Addon linting + if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }} + runs-on: ubuntu-latest + needs: check-addon-changes + continue-on-error: true + strategy: + fail-fast: false + matrix: + addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }} + steps: + - name: â†Šī¸ Checkout + uses: actions/checkout@v3 + + - 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@v3 + + - name: â„šī¸ Gather addon info + id: information + uses: frenck/action-addon-information@v1.4 + with: + path: "./${{ matrix.addon }}/" + + - name: đŸ—„ī¸ Cache docker layers + uses: actions/cache@v3 + 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: | + # shellcheck disable=SC2076,SC2059 + labels="io.hass.version=${{ steps.information.outputs.version }}" + labels=$(printf '%s' "$labels\nio.hass.name=${{ steps.information.outputs.name }}") + labels=$(printf '%s' "$labels\nio.hass.description=${{ steps.information.outputs.description }}") + labels=$(printf '%s' "$labels\nio.hass.type=addon") + labels=$(printf '%s' "$labels\nio.hass.url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/master/${{ matrix.addon }}") + labels=$(printf '%s' "$labels\norg.opencontainers.image.title=${{ steps.information.outputs.name }}") + labels=$(printf '%s' "$labels\norg.opencontainers.image.description=${{ steps.information.outputs.description }}") + labels=$(printf '%s' "$labels\norg.opencontainers.image.version=${{ steps.information.outputs.version }}") + labels=$(printf '%s' "$labels\norg.opencontainers.image.authors=Poeschl ") + labels=$(printf '%s' "$labels\norg.opencontainers.image.url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}") + labels=$(printf '%s' "$labels\norg.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/master/${{ matrix.addon }}") + labels=$(printf '%s' "$labels\norg.opencontainers.image.created=$(date -Is)") + labels=$(printf '%s' "$labels\norg.opencontainers.image.revision=${GITHUB_SHA}") + echo "Generic labels: $labels" + armhf_labels=$(printf '%s' "$labels\nio.hass.arch=armhf") + armv7_labels=$(printf '%s' "$labels\nio.hass.arch=armv7") + aarch64_labels=$(printf '%s' "$labels\nio.hass.arch=aarch64") + amd64_labels=$(printf '%s' "$labels\nio.hass.arch=amd64") + i386_labels=$(printf '%s' "$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@v2 + + - name: đŸ—ī¸ Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: đŸ’ŋ Build Addon - armhf + if: ${{ steps.information.outputs.armhf == 'true' }} + uses: docker/build-push-action@v3 + 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@v3 + 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@v3 + 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@v3 + 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@v3 + 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 \ No newline at end of file diff --git a/.github/workflows/onpush_build.yaml b/.github/workflows/onpush_build.yaml new file mode 100644 index 0000000..fb29799 --- /dev/null +++ b/.github/workflows/onpush_build.yaml @@ -0,0 +1,104 @@ +# yamllint disable rule:line-length +# inspired from https://github.com/Poeschl/Hassio-Addons +--- +name: Builder + +env: + BUILD_ARGS: "" + +on: + push: + branches: + - main + paths: + - "**/config.*" + +jobs: + check-addon-changes: + runs-on: ubuntu-latest + outputs: + changedAddons: ${{ steps.filter.outputs.changes }} + steps: + - name: â†Šī¸ Checkout + uses: actions/checkout@v3 + + - name: 📂 Detect changed files + uses: dorny/paths-filter@v2 + id: filter + with: + filters: .github/paths-filter.yml + + lint_config: + if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }} + needs: check-addon-changes + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }} + steps: + - name: â†Šī¸ Checkout + uses: actions/checkout@v3 + - name: 🔎 Run Home Assistant Add-on Lint + uses: frenck/action-addon-linter@v2 + with: + path: "./${{ matrix.addon }}" + + build: + if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }} + needs: check-addon-changes + runs-on: ubuntu-latest + environment: CR_PAT + name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on + strategy: + matrix: + addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }} + arch: ["aarch64", "amd64", "armv7"] + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Get information + id: info + uses: home-assistant/actions/helpers/info@master + with: + path: "./${{ matrix.addon }}" + + - name: Check if add-on should be built + id: check + env: + HEAD: "${{ github.head_ref }}" + run: | + # shellcheck disable=SC2157,SC2086 + if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then + echo "::set-output name=build_arch::true"; + echo "::set-output name=image::$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)"; + if [[ -z "$HEAD" ]] && [[ "${{ github.event_name }}" == "push" ]]; then + echo "BUILD_ARGS=" >> $GITHUB_ENV; + fi + else + echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build"; + echo "::set-output name=build_arch::false"; + fi + - name: Login to GitHub Container Registry + if: env.BUILD_ARGS != '--test' + uses: docker/login-action@v2.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build ${{ matrix.addon }} add-on + if: steps.check.outputs.build_arch == 'true' + uses: home-assistant/builder@master + env: + CAS_API_KEY: ${{ secrets.CAS_API_KEY }} + with: + args: | + ${{ env.BUILD_ARGS }} \ + --${{ matrix.arch }} \ + --target /data/${{ matrix.addon }} \ + --image "${{ steps.check.outputs.image }}" \ + --docker-hub "ghcr.io/${{ github.repository_owner }}" \ + --addon \ No newline at end of file diff --git a/.github/workflows/toogoodtogo-ha-mqtt-bridge.yml b/.github/workflows/toogoodtogo-ha-mqtt-bridge.yml deleted file mode 100644 index 0df8a75..0000000 --- a/.github/workflows/toogoodtogo-ha-mqtt-bridge.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: toogoodtogo-ha-mqtt-bridge - -on: - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - inputs: - version: - description: "Image Tag" - required: true - -jobs: - toogoodtogo-ha-mqtt-bridge: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - # - name: Set up QEMU - # uses: docker/setup-qemu-action@v2 - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v2 - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - uses: home-assistant/builder@2022.11.0 - with: - args: | - --all \ - --target toogoodtogo-ha-mqtt-bridge \ - --docker-hub maxwinterstein --version ${{ github.event.inputs.version }}