Change action (#708)

This commit is contained in:
Joakim Sørensen
2020-11-21 20:23:42 +01:00
committed by GitHub
parent e90672e427
commit 2854a6ea59
13 changed files with 4 additions and 368 deletions
+4 -34
View File
@@ -37,24 +37,10 @@ jobs:
name: repositories
path: /tmp/repositories
matrix:
owner:
runs-on: ubuntu-latest
name: ${{ matrix.checks.name }}
name: Check Owner
needs: preflight
strategy:
fail-fast: False
matrix:
checks:
- { check: "archived", name: "Check Archived", deps: True }
- { check: "brands", name: "Check Brands", deps: True }
- { check: "fork", name: "Check Fork", deps: True }
- { check: "hacs_manifest", name: "Check HACS Manifest" }
- { check: "images", name: "Check Images" }
- { check: "info", name: "Check Info" }
- { check: "manifest", name: "Check Manifest" }
- { check: "owner", name: "Check Owner", deps: True }
- { check: "repository", name: "Check Repository", deps: True }
- { check: "wheels", name: "Check Wheels", deps: True }
steps:
- name: Check out repository
uses: actions/checkout@v2
@@ -66,11 +52,10 @@ jobs:
path: /tmp/repositories
- name: Install dependencies if needed
if: matrix.checks.deps
run: make init
- name: Run the check
run: python3 -m scripts.check.${{ matrix.checks.check }}
run: python3 -m scripts.check.owner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -112,24 +97,9 @@ jobs:
--action validate \
--integration-path /$domain \
"
hacs:
runs-on: ubuntu-latest
name: "Check HACS"
needs: preflight
steps:
- name: HACS validation
uses: "hacs/integration/action@main"
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
env:
REPOSITORY: ${{needs.preflight.outputs.repository}}
CATEGORY: ${{needs.preflight.outputs.category}}
hacs-new:
runs-on: ubuntu-latest
name: "Run HACS action"
name: "Run HACS Action"
needs: preflight
steps:
- name: HACS action
-24
View File
@@ -1,24 +0,0 @@
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():
print("Information: https://hacs.xyz/docs/publish/include#check-archived")
repo = get_repo()
async with GitHub(TOKEN) as github:
repository = await github.get_repo(repo)
repo = repository.attributes
if repo["archived"]:
exit("::error::Repository is archived")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(check())
-44
View File
@@ -1,44 +0,0 @@
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():
print("Information: https://hacs.xyz/docs/publish/include#check-brands")
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")
core = await repository.get_contents("core_integrations")
custom = await repository.get_contents("custom_integrations")
if domain not in [x.attributes["name"] for x in core + custom]:
exit(
f"::error::{domain} is not added to https://github.com/home-assistant/brands, "
+ "this is needed to ensure the best possible experience for the user"
)
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())
-14
View File
@@ -1,14 +0,0 @@
from scripts.helpers.event import get_event
def check():
event = get_event()
labels = event.get("pull_request", {}).get("labels", [])
for label in labels:
if label["name"] == "Not finished":
exit("::error::Pull request is not ready for CI runs")
if __name__ == "__main__":
check()
-24
View File
@@ -1,24 +0,0 @@
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():
print("Information: https://hacs.xyz/docs/publish/include#check-fork")
repo = get_repo()
async with GitHub(TOKEN) as github:
repository = await github.get_repo(repo)
repo = repository.attributes
if repo["fork"]:
exit("::warning:: {repo} is a fork")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(check())
-26
View File
@@ -1,26 +0,0 @@
from scripts.changed.category import get_category
from scripts.helpers.hacs_manifest import get_hacs_manifest
def check():
print("Information: https://hacs.xyz/docs/publish/include#check-hacs-manifest")
if get_category() != "integration":
print("Only integrations are checked.")
return
manifest = get_hacs_manifest()
fail = "::error::Missing required value for key '{key}' in {path}"
path = "hacs.json"
issues = []
if manifest.get("name") is None:
issues.append(fail.format(key="name", path=path))
if issues:
for issue in issues:
print(issue)
exit(1)
if __name__ == "__main__":
check()
-20
View File
@@ -1,20 +0,0 @@
from scripts.changed.category import get_category
from scripts.helpers.info import get_info
def check():
print("Information: https://hacs.xyz/docs/publish/include#check-images")
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
exit("::error::There should be images to show the user what they get.")
if __name__ == "__main__":
check()
-13
View File
@@ -1,13 +0,0 @@
from scripts.changed.category import get_category
from scripts.helpers.info import get_info
def check():
print("Information: https://hacs.xyz/docs/publish/include#check-info")
info = get_info()
if not info:
exit("::error::No information provided.")
if __name__ == "__main__":
check()
-38
View File
@@ -1,38 +0,0 @@
from scripts.changed.category import get_category
from scripts.helpers.manifest import get_manifest
from scripts.helpers.integration_path import get_integration_path
def check():
print("Information: https://hacs.xyz/docs/publish/include#check-manifest")
if get_category() != "integration":
print("Only integrations are checked.")
return
fail = "::error::Missing required value for key '{key}' in {path}"
integration = get_integration_path()
path = f"{integration.replace('/tmp/repositories/addition/', '')}/manifest.json"
manifest = get_manifest()
issues = []
if manifest.get("domain") is None or manifest.get("domain") == "":
issues.append(fail.format(key="domain", path=path))
if manifest.get("documentation") is None or manifest.get("documentation") == "":
issues.append(fail.format(key="documentation", path=path))
if manifest.get("issue_tracker") is None or manifest.get("issue_tracker") == "":
issues.append(fail.format(key="issue_tracker", path=path))
if manifest.get("codeowners") is None:
issues.append(fail.format(key="codeowners", path=path))
if issues:
for issue in issues:
print(issue)
exit(1)
if __name__ == "__main__":
check()
-40
View File
@@ -1,40 +0,0 @@
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():
print("Information: https://hacs.xyz/docs/publish/include#check-repository")
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("::error::Issues not enabled.")
if not repo["description"]:
issues.append(
"::error::No description. (https://hacs.xyz/docs/publish/start#description)"
)
if not repo["topics"]:
issues.append(
"::error::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())
-47
View File
@@ -1,47 +0,0 @@
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():
print("Information: https://hacs.xyz/docs/publish/include#check-wheels")
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:
exit("No domain")
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
exit(
f"::error::{domain} is not added to https://github.com/home-assistant/wheels-custom-integrations, "
+ "this is needed to ensure the best possible experience for the user"
)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(check())
-23
View File
@@ -1,23 +0,0 @@
import json
import os
from glob import glob
def get_hacs_manifest():
files = []
for dir, _, _ in os.walk("/tmp/repositories/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/repositories/addition','')}"
)
with open(hacs_manifest, "r") as mf:
hacs_manifest = json.loads(mf.read())
return hacs_manifest or {}
-21
View File
@@ -1,21 +0,0 @@
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/repositories/addition/{alternative}"):
print(f"Found info file at /{alternative}")
with open(f"/tmp/repositories/addition/{alternative}", "r") as alt:
content = alt.read()
return content