From 967d5caae1270268c9301cc66e740b82e8bc9b2c Mon Sep 17 00:00:00 2001 From: Anarion Date: Fri, 8 Mar 2024 17:40:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Add=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/release-drafter.yml | 49 +++++++++++++++++++++++++ .github/scripts/update_hacs_manifest.py | 28 ++++++++++++++ .github/workflows/release-drafter.yml | 27 ++++++++++++++ .github/workflows/release.yml | 28 ++++++++++++++ .github/workflows/validate.yaml | 23 ++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 .github/release-drafter.yml create mode 100644 .github/scripts/update_hacs_manifest.py create mode 100644 .github/workflows/release-drafter.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/validate.yaml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..cead55b --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,49 @@ +name-template: 'v$RESOLVED_VERSION 🌈' +tag-template: 'v$RESOLVED_VERSION' +change-template: '- #$NUMBER $TITLE @$AUTHOR' +sort-direction: ascending +exclude-contributors: + - 'github-actions[bot]' + - 'github-actions' + - 'renovate[bot]' + - 'renovate' +exclude-labels: + - 'skip-changelog' + - 'dependencies' +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: | + ## Changes + + $CHANGES + + $CONTRIBUTORS +autolabeler: + - label: 'bug' + branch: + - '/fix\/.+/' + - label: 'enhancement' + branch: + - '/feature\/.+/' + - '/feat\/.+/' diff --git a/.github/scripts/update_hacs_manifest.py b/.github/scripts/update_hacs_manifest.py new file mode 100644 index 0000000..193d624 --- /dev/null +++ b/.github/scripts/update_hacs_manifest.py @@ -0,0 +1,28 @@ +"""Update the manifest file.""" +import json +import os +import sys + + +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/tech/manifest.json", + ) as manifestfile: + manifest = json.load(manifestfile) + + manifest["version"] = version + + with open( + f"{os.getcwd()}/custom_components/tech/manifest.json", + "w", + ) as manifestfile: + manifestfile.write(json.dumps(manifest, indent=4, sort_keys=True)) + + +update_manifest() diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..3a092da --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,27 @@ +name: Release Drafter + +on: + push: + branches: + - main + pull_request: + types: [opened, reopened, synchronize] + +jobs: + update_release_draft: + name: Update release draft + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Create Release + uses: release-drafter/release-drafter@v6 + with: + disable-releaser: github.ref != 'refs/heads/main' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..988c320 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +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@v4 + - name: "Set manifest version number" + run: | + python3 ${{ github.workspace }}/.github/scripts/update_hacs_manifest.py --version ${{ github.ref_name }} + - name: Create zip + run: | + cd custom_components/tech + zip tech.zip -r ./ + - name: Upload zip to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./custom_components/tech/tech.zip + asset_name: tech.zip + tag: ${{ github.ref }} + overwrite: true diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml new file mode 100644 index 0000000..6c3ed8c --- /dev/null +++ b/.github/workflows/validate.yaml @@ -0,0 +1,23 @@ +name: Validate + +on: + push: + pull_request: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + validate-hassfest: + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v4" + - uses: home-assistant/actions/hassfest@master + validate-hacs: + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v4" + - name: HACS validation + uses: "hacs/action@main" + with: + category: "integration"