From 4b2f40a9806d1beb262f7b6ce9b15ef9060d8019 Mon Sep 17 00:00:00 2001 From: Guy Khmelnitsky <3136012+GuyKh@users.noreply.github.com> Date: Thu, 4 Mar 2021 10:44:06 +0200 Subject: [PATCH 1/4] Add Version to manifest --- custom_components/authenticated/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/authenticated/manifest.json b/custom_components/authenticated/manifest.json index 12301fa..955f953 100644 --- a/custom_components/authenticated/manifest.json +++ b/custom_components/authenticated/manifest.json @@ -1,8 +1,9 @@ { "domain": "authenticated", "name": "Authenticated", + "version": "1.3.0", "documentation": "https://github.com/custom-components/authenticated", "dependencies": [], "codeowners": ["@ludeeus"], "requirements": [] -} \ No newline at end of file +} From e3755551435455c0a69db6dd48264711e6da8647 Mon Sep 17 00:00:00 2001 From: Guy Khmelnitsky <3136012+GuyKh@users.noreply.github.com> Date: Thu, 4 Mar 2021 17:13:03 +0200 Subject: [PATCH 2/4] Add GitHub Actions Build.yaml --- .github/workflows/build.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..25068ac --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,27 @@ +name: Build + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Get version + id: version + uses: home-assistant/actions/helpers/version@master + + - name: Patch manifest and zip + run: | + sed -i 's/v0.0.0/${{ steps.version.outputs.version }}/' custom_components/authenticated/manifest.json + zip authenticated.zip -r custom_components/authenticated/ + - uses: gacts/upload-to-release@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + file: authenticated.zip + type: application/zip From aca108bb970b60d5efb638274a675f6cb511adae Mon Sep 17 00:00:00 2001 From: Guy Khmelnitsky <3136012+GuyKh@users.noreply.github.com> Date: Thu, 4 Mar 2021 17:13:20 +0200 Subject: [PATCH 3/4] Update manifest.json --- custom_components/authenticated/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/authenticated/manifest.json b/custom_components/authenticated/manifest.json index 955f953..668345a 100644 --- a/custom_components/authenticated/manifest.json +++ b/custom_components/authenticated/manifest.json @@ -1,7 +1,7 @@ { "domain": "authenticated", "name": "Authenticated", - "version": "1.3.0", + "version": "v0.0.0", "documentation": "https://github.com/custom-components/authenticated", "dependencies": [], "codeowners": ["@ludeeus"], From a86ef4fbf1896d1b9abbec80aa9a734d8a54f3ab Mon Sep 17 00:00:00 2001 From: GuyKhmel <3136012+GuyKh@users.noreply.github.com> Date: Sat, 6 Mar 2021 18:53:33 +0200 Subject: [PATCH 4/4] Update Version based on INTEGRATION_VERSION --- .github/workflows/build.yaml | 27 ---------- .github/workflows/release.yaml | 65 +++++++++++++++++++++++ custom_components/authenticated/const.py | 24 +++++++++ custom_components/authenticated/sensor.py | 14 ++--- 4 files changed, 93 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 custom_components/authenticated/const.py diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 25068ac..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: Build - -on: - release: - types: [published] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Get version - id: version - uses: home-assistant/actions/helpers/version@master - - - name: Patch manifest and zip - run: | - sed -i 's/v0.0.0/${{ steps.version.outputs.version }}/' custom_components/authenticated/manifest.json - zip authenticated.zip -r custom_components/authenticated/ - - uses: gacts/upload-to-release@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - file: authenticated.zip - type: application/zip diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..3a357d2 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,65 @@ +# This GitHub action workflow is meant to be copyable to any repo that have the same structure. +# - Your integration exist under custom_components/{INTEGRATION_NAME}/[integration files] +# - You are using GitHub releases to publish new versions +# - You have a INTEGRATION_VERSION constant in custom_components/{INTEGRATION_NAME}/const.py + +name: Release Workflow + +on: + release: + types: [published] + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: đŸ“Ĩ Checkout the repository + uses: actions/checkout@v2 + + - name: đŸ”ĸ Get release version + id: version + uses: home-assistant/actions/helpers/version@master + + - name: ℹī¸ Get integration information + id: information + run: | + name=$(find custom_components/ -type d -maxdepth 1 | tail -n 1 | cut -d "/" -f2) + echo "::set-output name=name::$name" + + - name: 🖊ī¸ Set version number + run: | + sed -i '/INTEGRATION_VERSION = /c\INTEGRATION_VERSION = "${{ steps.version.outputs.version }}"' \ + "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py" + jq '.version = "${{ steps.version.outputs.version }}"' \ + "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json" > tmp \ + && mv -f tmp "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json" + + - name: 👀 Validate data + run: | + if ! grep -q 'INTEGRATION_VERSION = "${{ steps.version.outputs.version }}"' ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py; then + echo "The version in custom_components/${{ steps.information.outputs.name }}/const.py was not correct" + cat ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py | grep INTEGRATION_VERSION + exit 1 + fi + manifestversion=$(jq -r '.version' ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json) + if [ "$manifestversion" != "${{ steps.version.outputs.version }}" ]; then + echo "The version in custom_components/${{ steps.information.outputs.name }}/manifest.json was not correct" + echo "$manifestversion" + exit 1 + fi + + - name: đŸ“Ļ Create zip file for the integration + run: | + cd "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}" + zip ${{ steps.information.outputs.name }}.zip -r ./ + + - name: 📤 Upload the zip file as a release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/${{ steps.information.outputs.name }}.zip" + asset_name: ${{ steps.information.outputs.name }}.zip + asset_content_type: application/zip \ No newline at end of file diff --git a/custom_components/authenticated/const.py b/custom_components/authenticated/const.py new file mode 100644 index 0000000..88a38db --- /dev/null +++ b/custom_components/authenticated/const.py @@ -0,0 +1,24 @@ +"""Constants for authenticated.""" + +DOMAIN = "authenticated" +INTEGRATION_VERSION = "main" +ISSUE_URL = "https://github.com/custom-components/authenticated/issues" + +STARTUP = f""" +------------------------------------------------------------------- +{DOMAIN} +Version: {INTEGRATION_VERSION} +This is a custom component +If you have any issues with this you need to open an issue here: +https://github.com/custom-components/authenticated/issues +------------------------------------------------------------------- +""" + + +CONF_NOTIFY = "enable_notification" +CONF_EXCLUDE = "exclude" +CONF_EXCLUDE_CLIENTS = "exclude_clients" +CONF_PROVIDER = "provider" +CONF_LOG_LOCATION = "log_location" + +OUTFILE = ".ip_authenticated.yaml" diff --git a/custom_components/authenticated/sensor.py b/custom_components/authenticated/sensor.py index d96245a..89ebef9 100644 --- a/custom_components/authenticated/sensor.py +++ b/custom_components/authenticated/sensor.py @@ -18,15 +18,10 @@ from homeassistant.helpers.entity import Entity from .providers import PROVIDERS +from .const import OUTFILE, CONF_NOTIFY, CONF_EXCLUDE, CONF_EXCLUDE_CLIENTS, CONF_PROVIDER, CONF_LOG_LOCATION, STARTUP _LOGGER = logging.getLogger(__name__) -CONF_NOTIFY = "enable_notification" -CONF_EXCLUDE = "exclude" -CONF_EXCLUDE_CLIENTS = "exclude_clients" -CONF_PROVIDER = "provider" -CONF_LOG_LOCATION = "log_location" - ATTR_HOSTNAME = "hostname" ATTR_COUNTRY = "country" ATTR_REGION = "region" @@ -39,10 +34,6 @@ SCAN_INTERVAL = timedelta(minutes=1) PLATFORM_NAME = "authenticated" - -LOGFILE = "home-assistant.log" -OUTFILE = ".ip_authenticated.yaml" - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_PROVIDER, default="ipapi"): vol.In( @@ -62,6 +53,9 @@ def humanize_time(timestring): def setup_platform(hass, config, add_devices, discovery_info=None): + # Print startup message + _LOGGER.info(STARTUP) + """Create the sensor""" notify = config.get(CONF_NOTIFY) exclude = config.get(CONF_EXCLUDE)