From f3b8882cb4dfd1df5f1a21fddc4e47471599fa8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Nenz=C3=A9n?= Date: Wed, 13 Sep 2023 20:34:53 +0000 Subject: [PATCH] Adds github actions (#5) --- .github/release-drafter.yml | 35 +++++++++++++++++++++ .github/workflows/cron.yaml | 36 ++++++++++++++++++++++ .github/workflows/release-drafter.yaml | 18 +++++++++++ .github/workflows/release.yaml | 35 +++++++++++++++++++++ .github/workflows/validate.yaml | 42 ++++++++++++++++++++++++++ hacs.json | 7 +++-- manage/update_manifest.py | 25 +++++++++++++++ 7 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/cron.yaml create mode 100644 .github/workflows/release-drafter.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/validate.yaml create mode 100644 manage/update_manifest.py diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..1cd618b --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,35 @@ +name-template: 'v$RESOLVED_VERSION 🌈' +tag-template: 'v$RESOLVED_VERSION' +change-template: '- #$NUMBER $TITLE @$AUTHOR' +sort-direction: ascending +categories: + - title: '🚀 Features' + labels: + - 'feature' + - 'enhancement' + + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + + - title: '🧰 Maintenance' + label: 'chore' + +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: patch +template: | + [![Downloads for this release](https://img.shields.io/github/downloads/JohNan/home-assistant-flichub/v$RESOLVED_VERSION/total.svg)](https://github.com/JohNan/home-assistant-flichub/releases/v$RESOLVED_VERSION) + ## Changes + + $CHANGES \ No newline at end of file diff --git a/.github/workflows/cron.yaml b/.github/workflows/cron.yaml new file mode 100644 index 0000000..e571d42 --- /dev/null +++ b/.github/workflows/cron.yaml @@ -0,0 +1,36 @@ +name: "Cron actions 16:30 every 4 days" +on: + schedule: + - cron: '30 16 */4 * *' + +jobs: + validate-hassfest: + name: With hassfest + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: "Update manifest.json" + run: | + python3 ${{ github.workspace }}/manage/update_manifest.py + + - name: Hassfest validation + uses: home-assistant/actions/hassfest@master + + validate-hacs: + name: With HACS action + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: "Update manifest.json" + run: | + python3 ${{ github.workspace }}/manage/update_manifest.py + + - name: HACS Validation + uses: hacs/action@main + with: + category: integration + comment: False diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml new file mode 100644 index 0000000..fc3be14 --- /dev/null +++ b/.github/workflows/release-drafter.yaml @@ -0,0 +1,18 @@ +name: Release Drafter + +on: + push: + branches: + - main + +jobs: + update_release_draft: + name: Update release draft + runs-on: ubuntu-latest + steps: + - name: Create Release + uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..70f315e --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,35 @@ +name: Release + +on: + release: + types: [published] + +jobs: + release_zip_file: + name: Prepare release asset + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Get version + id: version + uses: home-assistant/actions/helpers/version@master + + - name: "Set version number" + run: | + python3 ${{ github.workspace }}/manage/update_manifest.py --version ${{ steps.version.outputs.version }} + + - name: Create zip + run: | + cd custom_components/flichub + zip flichub.zip -r ./ + + - name: Upload zip to release + uses: svenstaro/upload-release-action@v1-release + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./custom_components/flichub/flichub.zip + asset_name: flichub.zip + tag: ${{ github.ref }} + overwrite: true \ No newline at end of file diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml new file mode 100644 index 0000000..2f4fd70 --- /dev/null +++ b/.github/workflows/validate.yaml @@ -0,0 +1,42 @@ +name: "Validate" + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + validate-hassfest: + name: With hassfest + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: "Update manifest.json" + run: | + python3 ${{ github.workspace }}/manage/update_manifest.py + + - name: Hassfest validation + uses: home-assistant/actions/hassfest@master + + validate-hacs: + name: With HACS action + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: "Update manifest.json" + run: | + python3 ${{ github.workspace }}/manage/update_manifest.py + + - name: HACS Validation + uses: hacs/action@main + with: + ignore: brands + category: integration + comment: True diff --git a/hacs.json b/hacs.json index b1f7a65..3aa9554 100644 --- a/hacs.json +++ b/hacs.json @@ -1,7 +1,8 @@ { "name": "Flic Hub", "hacs": "1.6.0", - "domains": ["binary_sensor", "sensor", "switch"], - "iot_class": "Cloud Polling", - "homeassistant": "0.118.0" + "homeassistant": "2021.12.0", + "hide_default_branch": true, + "zip_release": true, + "filename": "flichub.zip" } diff --git a/manage/update_manifest.py b/manage/update_manifest.py new file mode 100644 index 0000000..9fdf912 --- /dev/null +++ b/manage/update_manifest.py @@ -0,0 +1,25 @@ +"""Update the manifest file.""" +import sys +import json +import os + + +def update_manifest(): + """Update the manifest file.""" + version = "0.0.0" + for index, value in enumerate(sys.argv): + if value in ["--version", "-V"]: + version = sys.argv[index + 1] + + with open(f"{os.getcwd()}/custom_components/flichub/manifest.json") as manifestfile: + manifest = json.load(manifestfile) + + manifest["version"] = version + + with open( + f"{os.getcwd()}/custom_components/flichub/manifest.json", "w" + ) as manifestfile: + manifestfile.write(json.dumps(manifest, indent=4, sort_keys=True)) + + +update_manifest() \ No newline at end of file