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
This commit is contained in:
Joakim Sørensen
2020-05-26 17:53:04 +02:00
committed by GitHub
parent 327142edc2
commit 001a81b77f
34 changed files with 671 additions and 38 deletions
+36
View File
@@ -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 }}
+23
View File
@@ -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
+31
View File
@@ -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 }}"
+37
View File
@@ -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"
+23
View File
@@ -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
+23
View File
@@ -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
+28
View File
@@ -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
+30
View File
@@ -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 }}
+36
View File
@@ -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 }}
-30
View File
@@ -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 }}"
+1
View File
@@ -0,0 +1 @@
__pycache__
View File
View File
+46
View File
@@ -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())
+27
View File
@@ -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())
View File
+40
View File
@@ -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())
+23
View File
@@ -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()
+20
View File
@@ -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 "<img" in info or "![" in info:
print("Has image(s)")
return
print("There should be images to show the user what they get.")
exit(1)
if __name__ == "__main__":
check()
+13
View File
@@ -0,0 +1,13 @@
from scripts.changed.category import get_category
from scripts.helpers.info import get_info
def check():
info = get_info()
if not info:
print("No information provided.")
exit(1)
if __name__ == "__main__":
check()
+35
View File
@@ -0,0 +1,35 @@
from scripts.changed.category import get_category
from scripts.helpers.manifest import get_manifest
def check():
if get_category() != "integration":
print("Only integrations are checked.")
return
manifest = get_manifest()
issues = []
if manifest.get("domain") is None:
issues.append("No domain")
if manifest.get("documentation") is None:
issues.append("No documentation")
if manifest.get("issue_tracker") is None:
issues.append("No issue_tracker")
if manifest.get("codeowners") is None:
issues.append("No codeowners")
if manifest.get("homeassistant"):
issues.append("homeassistant is not valid here")
if issues:
for issue in issues:
print(issue)
exit(1)
if __name__ == "__main__":
check()
+36
View File
@@ -0,0 +1,36 @@
import asyncio
import json
import os
from glob import glob
from aiogithubapi import GitHub
from scripts.changed.repo import get_repo
TOKEN = os.getenv("GITHUB_TOKEN")
async def check():
repo = get_repo()
issues = []
async with GitHub(TOKEN) as github:
repository = await github.get_repo(repo)
repo = repository.attributes
if not repo["has_issues"]:
issues.append("Issues not enabled.")
if not repo["description"]:
issues.append("No description. (https://hacs.xyz/docs/publish/start#description)")
if not repo["topics"]:
issues.append("No topics. (https://hacs.xyz/docs/publish/start#topics)")
if issues:
for issue in issues:
print(issue)
exit(1)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(check())
+48
View File
@@ -0,0 +1,48 @@
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")
requirements = manifest.get("requirements")
if domain is None:
print("No domain")
exit(1)
if not requirements:
print("No requirements found")
return
async with GitHub(TOKEN) as github:
repository = await github.get_repo("home-assistant/wheels-custom-integrations")
files = await repository.get_contents("components")
components = [x.attributes["name"] for x in files]
if domain in components or f"{domain}.json" in components:
print(
f"{domain} is added to https://github.com/home-assistant/wheels-custom-integrations, NICE!"
)
return
print(
f"{domain} is not added to https://github.com/home-assistant/wheels-custom-integrations"
)
print("This is needed to ensure the best possible experience for the user")
exit(1)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(check())
View File
+12
View File
@@ -0,0 +1,12 @@
import json
import os
from glob import glob
from scripts.helpers.manifest import get_manifest
def get_domain():
manifest = get_manifest()
return manifest.get('domain')
if __name__ == "__main__":
print(get_domain())
+21
View File
@@ -0,0 +1,21 @@
import json
import os
from glob import glob
def get_hacs_manifest():
files = []
for dir, _, _ in os.walk("/tmp/addition"):
files.extend(glob(os.path.join(dir, "*hacs.json")))
if len(files) != 1:
print("No HACS manifest")
exit(1)
hacs_manifest = files.pop()
print(f"Found HACS manifest at {hacs_manifest.replace('/tmp/addition','')}")
with open(hacs_manifest, "r") as mf:
hacs_manifest = json.loads(mf.read())
return hacs_manifest or {}
+21
View File
@@ -0,0 +1,21 @@
import os
from scripts.helpers.hacs_manifest import get_hacs_manifest
ALTERNATIVES = {
"info": ["info", "INFO", "info.md", "INFO.md", "info.MD", "INFO.MD"],
"readme": ["readme", "README", "readme.md", "README.md", "readme.MD", "README.MD"],
}
def get_info():
manifest = get_hacs_manifest()
info = "readme" if manifest.get("render_readme", False) else "info"
content = ""
for alternative in ALTERNATIVES[info]:
if os.path.exists(f"/tmp/addition/{alternative}"):
print(f"Found info file at /{alternative}")
with open(f"/tmp/addition/{alternative}", "r") as alt:
content = alt.read()
return content
+16
View File
@@ -0,0 +1,16 @@
import json
import os
from glob import glob
def get_integration_path():
files = []
for dir, _, _ in os.walk("/tmp/addition"):
files.extend(glob(os.path.join(dir, "*manifest.json")))
if len(files) != 1:
print("No manifest")
exit(1)
return files.pop().replace("/manifest.json", "")
if __name__ == "__main__":
print(get_integration_path())
+11
View File
@@ -0,0 +1,11 @@
import json
import os
from glob import glob
from scripts.helpers.integration_path import get_integration_path
def get_manifest():
manifest = f"{get_integration_path()}/manifest.json"
with open(manifest, "r") as mf:
manifest = json.loads(mf.read())
return manifest or {}
+10 -2
View File
@@ -1,10 +1,18 @@
import json import json
categories = ["blacklist", "appdaemon", "integration", "netdaemon", "plugin", "python_script", "theme"] categories = [
"blacklist",
"appdaemon",
"integration",
"netdaemon",
"plugin",
"python_script",
"theme",
]
for category in categories: for category in categories:
with open(category, "r") as cat_file: with open(category, "r") as cat_file:
content = json.loads(cat_file.read()) content = json.loads(cat_file.read())
if content != sorted(content, key=str.casefold): if content != sorted(content, key=str.casefold):
print(f"{category} is not sorted correctly") print(f"{category} is not sorted correctly")
exit(1) exit(1)
+15 -4
View File
@@ -3,7 +3,9 @@ import json
if len(sys.argv) < 3: if len(sys.argv) < 3:
print(' Usage: python3 scripts/remove_repo.py [repository] [removal_type] "[reason]" [link]') print(
' Usage: python3 scripts/remove_repo.py [repository] [removal_type] "[reason]" [link]'
)
exit(1) exit(1)
try: try:
@@ -30,7 +32,7 @@ remove = {
"link": link, "link": link,
"reason": reason, "reason": reason,
"removal_type": removal_type, "removal_type": removal_type,
"repository": repo "repository": repo,
} }
orgs = ["custom-cards", "custom-components"] orgs = ["custom-cards", "custom-components"]
@@ -40,7 +42,14 @@ categorycontent = None
blacklistcontent = None blacklistcontent = None
removedcontent = None removedcontent = None
for category in ["appdaemon", "integration", "netdaemon", "plugin", "python_script", "theme"]: for category in [
"appdaemon",
"integration",
"netdaemon",
"plugin",
"python_script",
"theme",
]:
with open(category, "r") as cat_file: with open(category, "r") as cat_file:
content = json.loads(cat_file.read()) content = json.loads(cat_file.read())
if remove["repository"] in content: if remove["repository"] in content:
@@ -75,7 +84,9 @@ if remove["link"] is not None:
removedcontent.append(data) removedcontent.append(data)
with open("blacklist", "w") as blacklist_file: with open("blacklist", "w") as blacklist_file:
blacklist_file.write(json.dumps(sorted(blacklistcontent, key=str.casefold), indent=2)) blacklist_file.write(
json.dumps(sorted(blacklistcontent, key=str.casefold), indent=2)
)
with open("removed", "w") as removed_file: with open("removed", "w") as removed_file:
removed_file.write(json.dumps(removedcontent, indent=2)) removed_file.write(json.dumps(removedcontent, indent=2))
+9 -2
View File
@@ -1,6 +1,14 @@
import json import json
categories = ["blacklist", "appdaemon", "integration", "netdaemon", "plugin", "python_script", "theme"] categories = [
"blacklist",
"appdaemon",
"integration",
"netdaemon",
"plugin",
"python_script",
"theme",
]
for category in categories: for category in categories:
with open(category, "r") as cat_file: with open(category, "r") as cat_file:
@@ -8,4 +16,3 @@ for category in categories:
with open(category, "w") as cat_file: with open(category, "w") as cat_file:
cat_file.write(json.dumps(sorted(content, key=str.casefold), indent=2)) cat_file.write(json.dumps(sorted(content, key=str.casefold), indent=2))