From 001a81b77f2003388a63cb61b0eec716c42ca938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Tue, 26 May 2020 17:53:04 +0200 Subject: [PATCH] New Github actions (#481) * Test new check * Add quote * test * test * move check * move back * use env * test multistep * test trigger * if: github.event.label.name * quotes * hassfest? * Fix clone * Update hassfest * check hassfest * Use real domain * Lmit * Test hassfest * Check domain * Fix domain * No changes * Enable on unlable * Change HACS validate * Move inputs * Add dummy integration * TEst * Move to env * Fix repo * Remove entry --- .github/workflows/check-brands.yml | 36 ++++++++++++++ .github/workflows/check-hacs-manifest.yml | 23 +++++++++ .github/workflows/check-hacs.yaml | 31 ++++++++++++ .github/workflows/check-hassfest.yml | 37 ++++++++++++++ .github/workflows/check-images.yml | 23 +++++++++ .github/workflows/check-info.yml | 23 +++++++++ .github/workflows/check-manifest.yml | 28 +++++++++++ .github/workflows/check-repository.yml | 30 ++++++++++++ .github/workflows/check-wheels.yml | 36 ++++++++++++++ .../workflows/{lint_jq.yml => lint-jq.yml} | 0 .../{lint_sorted.yml => lint-sorted.yml} | 0 .github/workflows/validate.yaml | 30 ------------ .gitignore | 1 + scripts/__init__.py | 0 scripts/changed/__init__.py | 0 scripts/changed/category.py | 46 ++++++++++++++++++ scripts/changed/repo.py | 27 +++++++++++ scripts/check/__init__.py | 0 scripts/check/brands.py | 40 ++++++++++++++++ scripts/check/hacs_manifest.py | 23 +++++++++ scripts/check/images.py | 20 ++++++++ scripts/check/info.py | 13 +++++ scripts/check/manifest.py | 35 ++++++++++++++ scripts/check/repository.py | 36 ++++++++++++++ scripts/check/wheels.py | 48 +++++++++++++++++++ scripts/helpers/__init__.py | 0 scripts/helpers/domain.py | 12 +++++ scripts/helpers/hacs_manifest.py | 21 ++++++++ scripts/helpers/info.py | 21 ++++++++ scripts/helpers/integration_path.py | 16 +++++++ scripts/helpers/manifest.py | 11 +++++ scripts/is_sorted.py | 12 ++++- scripts/remove_repo.py | 19 ++++++-- scripts/sort.py | 11 ++++- 34 files changed, 671 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/check-brands.yml create mode 100644 .github/workflows/check-hacs-manifest.yml create mode 100644 .github/workflows/check-hacs.yaml create mode 100644 .github/workflows/check-hassfest.yml create mode 100644 .github/workflows/check-images.yml create mode 100644 .github/workflows/check-info.yml create mode 100644 .github/workflows/check-manifest.yml create mode 100644 .github/workflows/check-repository.yml create mode 100644 .github/workflows/check-wheels.yml rename .github/workflows/{lint_jq.yml => lint-jq.yml} (100%) rename .github/workflows/{lint_sorted.yml => lint-sorted.yml} (100%) delete mode 100644 .github/workflows/validate.yaml create mode 100644 .gitignore create mode 100644 scripts/__init__.py create mode 100644 scripts/changed/__init__.py create mode 100644 scripts/changed/category.py create mode 100644 scripts/changed/repo.py create mode 100644 scripts/check/__init__.py create mode 100644 scripts/check/brands.py create mode 100644 scripts/check/hacs_manifest.py create mode 100644 scripts/check/images.py create mode 100644 scripts/check/info.py create mode 100644 scripts/check/manifest.py create mode 100644 scripts/check/repository.py create mode 100644 scripts/check/wheels.py create mode 100644 scripts/helpers/__init__.py create mode 100644 scripts/helpers/domain.py create mode 100644 scripts/helpers/hacs_manifest.py create mode 100644 scripts/helpers/info.py create mode 100644 scripts/helpers/integration_path.py create mode 100644 scripts/helpers/manifest.py diff --git a/.github/workflows/check-brands.yml b/.github/workflows/check-brands.yml new file mode 100644 index 0000000..b77e612 --- /dev/null +++ b/.github/workflows/check-brands.yml @@ -0,0 +1,36 @@ +name: "Check Brands" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Set category + id: category + run: echo "::set-output name=category::$(python3 -m scripts.changed.category)" + + - name: Install dependencies + if: steps.category.outputs.category == 'integration' + run: | + python3 -m pip install setuptools wheel + python3 -m pip install aiogithubapi + + - name: Check home-assistant/brands + if: steps.category.outputs.category == 'integration' + run: python3 -m scripts.check.brands + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/check-hacs-manifest.yml b/.github/workflows/check-hacs-manifest.yml new file mode 100644 index 0000000..1421794 --- /dev/null +++ b/.github/workflows/check-hacs-manifest.yml @@ -0,0 +1,23 @@ +name: "Check HACS Manifest" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Check HACS manifest + run: python3 -m scripts.check.hacs_manifest diff --git a/.github/workflows/check-hacs.yaml b/.github/workflows/check-hacs.yaml new file mode 100644 index 0000000..3bcda28 --- /dev/null +++ b/.github/workflows/check-hacs.yaml @@ -0,0 +1,31 @@ +name: "Check HACS" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Set category + id: category + run: echo "::set-output name=category::$(python3 -m scripts.changed.category)" + + - name: Set repository + id: repository + run: echo "::set-output name=repository::$(python3 -m scripts.changed.repo)" + + - name: HACS validation + uses: "hacs/integration/action@master" + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + env: + REPOSITORY: "${{ steps.repository.outputs.repository }}" + CATEGORY: "${{ steps.category.outputs.category }}" \ No newline at end of file diff --git a/.github/workflows/check-hassfest.yml b/.github/workflows/check-hassfest.yml new file mode 100644 index 0000000..c5a6e2e --- /dev/null +++ b/.github/workflows/check-hassfest.yml @@ -0,0 +1,37 @@ +name: "Check hassfest" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Set category + id: category + run: echo "::set-output name=category::$(python3 -m scripts.changed.category)" + + - name: Pull Home Assistant Container + if: steps.category.outputs.category == 'integration' + run: docker pull homeassistant/home-assistant:beta + + - name: Run hassfest + if: steps.category.outputs.category == 'integration' + run: | + integration=$(python3 -m scripts.helpers.integration_path) + domain=$(python3 -m scripts.helpers.domain) + docker run --entrypoint="" -v "$integration":"/$domain" \ + homeassistant/home-assistant:beta python3 -m \ + script.hassfest --action validate --integration-path "/$domain" \ No newline at end of file diff --git a/.github/workflows/check-images.yml b/.github/workflows/check-images.yml new file mode 100644 index 0000000..5576840 --- /dev/null +++ b/.github/workflows/check-images.yml @@ -0,0 +1,23 @@ +name: "Check Images" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Check images + run: python3 -m scripts.check.images diff --git a/.github/workflows/check-info.yml b/.github/workflows/check-info.yml new file mode 100644 index 0000000..bcddd54 --- /dev/null +++ b/.github/workflows/check-info.yml @@ -0,0 +1,23 @@ +name: "Check Info" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Check info + run: python3 -m scripts.check.info diff --git a/.github/workflows/check-manifest.yml b/.github/workflows/check-manifest.yml new file mode 100644 index 0000000..e0ebe7c --- /dev/null +++ b/.github/workflows/check-manifest.yml @@ -0,0 +1,28 @@ +name: "Check Manifest" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Set category + id: category + run: echo "::set-output name=category::$(python3 -m scripts.changed.category)" + + - name: Check manifest + if: steps.category.outputs.category == 'integration' + run: python3 -m scripts.check.manifest diff --git a/.github/workflows/check-repository.yml b/.github/workflows/check-repository.yml new file mode 100644 index 0000000..294fd37 --- /dev/null +++ b/.github/workflows/check-repository.yml @@ -0,0 +1,30 @@ +name: "Check Repository" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Install dependencies + run: | + python3 -m pip install setuptools wheel + python3 -m pip install aiogithubapi + + - name: Check repository + run: python3 -m scripts.check.repository + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/check-wheels.yml b/.github/workflows/check-wheels.yml new file mode 100644 index 0000000..07186cf --- /dev/null +++ b/.github/workflows/check-wheels.yml @@ -0,0 +1,36 @@ +name: "Check Wheels" +on: + pull_request: + types: unlabeled + +jobs: + check: + if: github.event.label.name == 'Not finished' + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Clone origin + run: git clone --depth 1 https://github.com/hacs/default /tmp/default + + - name: Clone new addition + run: | + repo=$(python3 -m scripts.changed.repo) + git clone --depth 1 "https://github.com/$repo" /tmp/addition + + - name: Set category + id: category + run: echo "::set-output name=category::$(python3 -m scripts.changed.category)" + + - name: Install dependencies + if: steps.category.outputs.category == 'integration' + run: | + python3 -m pip install setuptools wheel + python3 -m pip install aiogithubapi + + - name: Check home-assistant/wheels-custom-integrations + if: steps.category.outputs.category == 'integration' + run: python3 -m scripts.check.wheels + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/lint_jq.yml b/.github/workflows/lint-jq.yml similarity index 100% rename from .github/workflows/lint_jq.yml rename to .github/workflows/lint-jq.yml diff --git a/.github/workflows/lint_sorted.yml b/.github/workflows/lint-sorted.yml similarity index 100% rename from .github/workflows/lint_sorted.yml rename to .github/workflows/lint-sorted.yml diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml deleted file mode 100644 index 2a2d823..0000000 --- a/.github/workflows/validate.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: "Validate with HACS" -on: - pull_request: - branches: - - master - -jobs: - validate: - runs-on: ubuntu-latest - name: Validate - steps: - - name: Check out repository - uses: actions/checkout@v2 - - - name: Get file changes - id: get_file_changes - uses: dorner/file-changes-action@v1.2.0 - with: - githubToken: ${{ secrets.GITHUB_TOKEN }} - plaintext: true - - - name: export file changes - run: export CHANGED_FILES="${{ steps.get_file_changes.outputs.files }}" - - - name: HACS validation - uses: "hacs/integration/action@master" - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - env: - CHANGED_FILES: "${{ steps.get_file_changes.outputs.files }}" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/scripts/__init__.py b/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/changed/__init__.py b/scripts/changed/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/changed/category.py b/scripts/changed/category.py new file mode 100644 index 0000000..231703a --- /dev/null +++ b/scripts/changed/category.py @@ -0,0 +1,46 @@ +import json + + +DEFAULT = "/tmp/default" + +CATEGORIES = [ + "appdaemon", + "integration", + "netdaemon", + "plugin", + "python_script", + "theme", +] + +CURRENT = {} +CHANGED = {} + + +def get_category(): + for category in CATEGORIES: + with open(f"{DEFAULT}/{category}", "r") as default: + CURRENT[category] = json.loads(default.read()) + + for category in CATEGORIES: + with open(category, "r") as default: + CHANGED[category] = json.loads(default.read()) + + for category in CATEGORIES: + for repo in CURRENT[category]: + if repo in CHANGED[category]: + CHANGED[category].remove(repo) + + changed = [] + for category in CATEGORIES: + if CHANGED[category]: + changed.append(category) + + if len(changed) != 1: + print(f"Bad data {changed}") + exit(1) + + return changed.pop() + + +if __name__ == "__main__": + print(get_category()) diff --git a/scripts/changed/repo.py b/scripts/changed/repo.py new file mode 100644 index 0000000..1596f1c --- /dev/null +++ b/scripts/changed/repo.py @@ -0,0 +1,27 @@ +import json +from scripts.changed.category import get_category + +DEFAULT = "/tmp/default" + + +def get_repo(): + category = get_category() + with open(f"{DEFAULT}/{category}", "r") as default: + current = json.loads(default.read()) + + with open(category, "r") as default: + new = json.loads(default.read()) + + for repo in current: + if repo in new: + new.remove(repo) + + if len(new) != 1: + print(f"Bad data {new}") + exit(1) + + return new.pop() + + +if __name__ == "__main__": + print(get_repo()) diff --git a/scripts/check/__init__.py b/scripts/check/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/check/brands.py b/scripts/check/brands.py new file mode 100644 index 0000000..7f7e811 --- /dev/null +++ b/scripts/check/brands.py @@ -0,0 +1,40 @@ +import asyncio +import json +import os +from glob import glob + +from aiogithubapi import GitHub +from scripts.changed.category import get_category +from scripts.changed.repo import get_repo +from scripts.helpers.manifest import get_manifest + +TOKEN = os.getenv("GITHUB_TOKEN") + + +async def check(): + if get_category() != "integration": + print("Only integrations are checked.") + return + + manifest = get_manifest() + + domain = manifest.get("domain") + if domain is None: + print("No domain") + exit(1) + + async with GitHub(TOKEN) as github: + repository = await github.get_repo("home-assistant/brands") + files = await repository.get_contents("custom_integrations") + if domain not in [x.attributes["name"] for x in files]: + print(f"{domain} is not added to https://github.com/home-assistant/brands") + print("This is needed to ensure the best possible experience for the user") + exit(1) + else: + print( + f"{domain} is added to https://github.com/home-assistant/brands, NICE!" + ) + + +if __name__ == "__main__": + asyncio.get_event_loop().run_until_complete(check()) diff --git a/scripts/check/hacs_manifest.py b/scripts/check/hacs_manifest.py new file mode 100644 index 0000000..c1a9a03 --- /dev/null +++ b/scripts/check/hacs_manifest.py @@ -0,0 +1,23 @@ +from scripts.changed.category import get_category +from scripts.helpers.hacs_manifest import get_hacs_manifest + + +def check(): + if get_category() != "integration": + print("Only integrations are checked.") + return + + manifest = get_hacs_manifest() + issues = [] + + if manifest.get("name") is None: + issues.append("No name") + + if issues: + for issue in issues: + print(issue) + exit(1) + + +if __name__ == "__main__": + check() diff --git a/scripts/check/images.py b/scripts/check/images.py new file mode 100644 index 0000000..df6cb6d --- /dev/null +++ b/scripts/check/images.py @@ -0,0 +1,20 @@ +from scripts.changed.category import get_category +from scripts.helpers.info import get_info + + +def check(): + if get_category() not in ["plugin", "theme"]: + print("Only plugin and theme are checked.") + return + + info = get_info() + if "