From 61ca8fb98c6b612c1ca3fc46c2677a76e7372a51 Mon Sep 17 00:00:00 2001 From: Max Winterstein Date: Thu, 21 Jan 2021 20:22:33 +0100 Subject: [PATCH] Update github actions and add version-updater script --- .../eufy-ha-mqtt-bridge-release.yaml | 19 ------- .../eufy_create_mr_and_build_image.yaml | 53 +++++++++++++++++++ ...idge.yml => eufy_manually_build_image.yml} | 2 +- eufy-ha-mqtt-bridge/version-updater.sh | 26 +++++++++ 4 files changed, 80 insertions(+), 20 deletions(-) delete mode 100644 .github/workflows/eufy-ha-mqtt-bridge-release.yaml create mode 100644 .github/workflows/eufy_create_mr_and_build_image.yaml rename .github/workflows/{eufy-ha-mqtt-bridge.yml => eufy_manually_build_image.yml} (97%) create mode 100755 eufy-ha-mqtt-bridge/version-updater.sh diff --git a/.github/workflows/eufy-ha-mqtt-bridge-release.yaml b/.github/workflows/eufy-ha-mqtt-bridge-release.yaml deleted file mode 100644 index 9d3eb66..0000000 --- a/.github/workflows/eufy-ha-mqtt-bridge-release.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: eufy-ha-mqtt-bridge-release-trigger - -on: - workflow_dispatch: - repository_dispatch: - types: [createMR] -jobs: - createMR: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: 'sed -i "s|\"version\": \".*$|\"version\": \"${{ github.event.client_payload.version }}\",|" eufy-ha-mqtt-bridge/config.json' - - run: 'sed -i "s|VERSION=.*$|VERSION=${{ github.event.client_payload.version }}|" eufy-ha-mqtt-bridge/Dockerfile-real' - - run: sed -i "2 a $(head -n3 eufy-ha-mqtt-bridge/CHANGELOG.md | tail -n1 | perl -pe 's/(\d+\.)(\d+)(.*)/$1.($2+1).".0]"/e') - $(date +%Y-%m-%d)" eufy-ha-mqtt-bridge/CHANGELOG.md - - run: sed -i "3 a - Update \`eufy-ha-mqtt-bridge\` to \`${{ github.event.client_payload.version }}\` [Changelog](https://github.com/matijse/eufy-ha-mqtt-bridge/releases)\n" eufy-ha-mqtt-bridge/CHANGELOG.md - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - title: Update eufy-mqtt-ha-bridge to version ${{ github.event.client_payload.version }} diff --git a/.github/workflows/eufy_create_mr_and_build_image.yaml b/.github/workflows/eufy_create_mr_and_build_image.yaml new file mode 100644 index 0000000..070858f --- /dev/null +++ b/.github/workflows/eufy_create_mr_and_build_image.yaml @@ -0,0 +1,53 @@ +name: eufy_create_mr_and_build_image + +on: + workflow_dispatch: +jobs: + create_mr_and_build_image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: cd eufy-ha-mqtt-bridge && ./version-updater.sh + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + title: Update eufy-mqtt-ha-bridge to version ${{ env.MQTT_BRIDGE_VERSION }} + commit-message: Update eufy-mqtt-ha-bridge to version ${{ env.MQTT_BRIDGE_VERSION }} + committer: Max Winterstein + author: Max Winterstein + assignees: MaxWinterstein + body: | + Update report + - Update related files of eufy-mqtt-ha-bridge to version ${{ env.MQTT_BRIDGE_VERSION }} [Changelog][1] + - Build docker image, check [DockerHub][2] + + [1]: https://github.com/matijse/eufy-ha-mqtt-bridge/releases + [2]: https://hub.docker.com/r/maxwinterstein/homeassistant-addon-eufy-ha-mqtt-bridge + if: ${{ env.CONTINUE }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + if: ${{ env.CONTINUE }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + if: ${{ env.CONTINUE }} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + if: ${{ env.CONTINUE }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: eufy-ha-mqtt-bridge/ + file: eufy-ha-mqtt-bridge/Dockerfile-real + platforms: linux/amd64,linux/arm/v7,linux/arm64 + push: true + tags: | + maxwinterstein/homeassistant-addon-eufy-ha-mqtt-bridge:${{ env.ADDON_NEXT_VERSION }} + if: ${{ env.CONTINUE }} diff --git a/.github/workflows/eufy-ha-mqtt-bridge.yml b/.github/workflows/eufy_manually_build_image.yml similarity index 97% rename from .github/workflows/eufy-ha-mqtt-bridge.yml rename to .github/workflows/eufy_manually_build_image.yml index 65d2aa3..dd6f3f4 100644 --- a/.github/workflows/eufy-ha-mqtt-bridge.yml +++ b/.github/workflows/eufy_manually_build_image.yml @@ -1,4 +1,4 @@ -name: eufy-ha-mqtt-bridge +name: eufy_manually_build_image on: # Allows you to run this workflow manually from the Actions tab diff --git a/eufy-ha-mqtt-bridge/version-updater.sh b/eufy-ha-mqtt-bridge/version-updater.sh new file mode 100755 index 0000000..1636ebb --- /dev/null +++ b/eufy-ha-mqtt-bridge/version-updater.sh @@ -0,0 +1,26 @@ +#!/bin/bash +echo "Fetching eufy-ha-mqtt-bridge version" +MQTT_BRIDGE_VERSION=$(curl -s https://api.github.com/repos/matijse/eufy-ha-mqtt-bridge/releases/latest | grep tag_name | cut -d : -f 2,3 | tr -d \" | tr -d ',' | tr -d ' ') +echo "Newest version of eufy-ha-mqtt-bridge: $MQTT_BRIDGE_VERSION" +echo "MQTT_BRIDGE_VERSION=$MQTT_BRIDGE_VERSION" >> $GITHUB_ENV + +echo "Check if $MQTT_BRIDGE_VERSION is already used..." +grep "ARG VERSION=${MQTT_BRIDGE_VERSION}" Dockerfile-real && { echo "Version is the same, nothing to do"; exit 0; } || echo "Version is different, will continue..." +echo "CONTINUE=true" >> $GITHUB_ENV; + +echo "Reading current addon version" +ADDON_CURR_VERSION=$(grep version config.json | cut -d '"' -f 4) +ADDON_NEXT_VERSION=$(echo $ADDON_CURR_VERSION| perl -pe 's/(\d+\.)(\d+)(.*)/$1.($2+1).".0"/e') +echo "ADDON_NEXT_VERSION=$ADDON_NEXT_VERSION" >> $GITHUB_ENV +echo "Update config..." +sed -i.bak "s|\ \ \"version\": \".*$|\ \ \"version\": \"$ADDON_NEXT_VERSION\",|" config.json + +echo "Update Dockerfile..." +sed -i.bak "s|eufy-ha-mqtt-bridge:.*$|eufy-ha-mqtt-bridge:${ADDON_NEXT_VERSION}|" Dockerfile +sed -i.bak "s|VERSION=.*$|VERSION=${MQTT_BRIDGE_VERSION}|" Dockerfile-real + +echo "Update CHANGELOG..." +sed -i.bak "2 a ## [${ADDON_NEXT_VERSION}] - $(date +%Y-%m-%d)" CHANGELOG.md +sed -i.bak "3 a - Update \`eufy-ha-mqtt-bridge\` to \`${MQTT_BRIDGE_VERSION}\` [Changelog](https://github.com/matijse/eufy-ha-mqtt-bridge/releases)\n" CHANGELOG.md + +rm *.bak #cleanup, mac os related problem \ No newline at end of file