mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-30 04:14:04 +02:00
Enhance onpush_builder.yaml with workflow_call support
Added support for workflow calls and updated environment variable handling in the onpush_builder workflow.
This commit is contained in:
52
.github/workflows/onpush_builder.yaml
vendored
52
.github/workflows/onpush_builder.yaml
vendored
@@ -3,6 +3,7 @@
|
|||||||
name: Builder
|
name: Builder
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_call:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
@@ -165,6 +166,7 @@ jobs:
|
|||||||
ADDON: ${{ matrix.addon }}
|
ADDON: ${{ matrix.addon }}
|
||||||
ARCH: ${{ matrix.arch }}
|
ARCH: ${{ matrix.arch }}
|
||||||
REPOSITORY: ${{ github.repository }}
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
GITHUB_SHA_VALUE: ${{ github.sha }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -173,43 +175,44 @@ jobs:
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
addon = os.environ["ADDON"]
|
addon = os.environ["ADDON"]
|
||||||
arch = os.environ["ARCH"]
|
arch = os.environ["ARCH"]
|
||||||
repository = os.environ["REPOSITORY"]
|
repository = os.environ["REPOSITORY"]
|
||||||
|
github_sha = os.environ["GITHUB_SHA_VALUE"]
|
||||||
addon_dir = Path(addon)
|
addon_dir = Path(addon)
|
||||||
output_path = Path(os.environ["GITHUB_OUTPUT"])
|
output_path = Path(os.environ["GITHUB_OUTPUT"])
|
||||||
|
|
||||||
|
|
||||||
def load_file(path: Path):
|
def load_file(path: Path):
|
||||||
text = path.read_text(encoding="utf-8")
|
text = path.read_text(encoding="utf-8")
|
||||||
if path.suffix == ".json":
|
if path.suffix == ".json":
|
||||||
return json.loads(text)
|
return json.loads(text)
|
||||||
return yaml.safe_load(text) or {}
|
return yaml.safe_load(text) or {}
|
||||||
|
|
||||||
|
|
||||||
def first_existing(*names: str):
|
def first_existing(*names: str):
|
||||||
for name in names:
|
for name in names:
|
||||||
path = addon_dir / name
|
path = addon_dir / name
|
||||||
if path.exists():
|
if path.exists():
|
||||||
return path
|
return path
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
config_path = first_existing("config.json", "config.yaml", "config.yml")
|
config_path = first_existing("config.json", "config.yaml", "config.yml")
|
||||||
if config_path is None:
|
if config_path is None:
|
||||||
raise SystemExit(f"No config file found in {addon}")
|
raise SystemExit(f"No config file found in {addon}")
|
||||||
|
|
||||||
build_path = first_existing("build.json", "build.yaml", "build.yml")
|
build_path = first_existing("build.json", "build.yaml", "build.yml")
|
||||||
config = load_file(config_path)
|
config = load_file(config_path)
|
||||||
build = load_file(build_path) if build_path else {}
|
build = load_file(build_path) if build_path else {}
|
||||||
|
|
||||||
build_from_map = build.get("build_from") or {}
|
build_from_map = build.get("build_from") or {}
|
||||||
arch_list = list(build_from_map.keys()) if build_from_map else list(config.get("arch") or [])
|
arch_list = list(build_from_map.keys()) if build_from_map else list(config.get("arch") or [])
|
||||||
build_arch = arch in arch_list
|
build_arch = arch in arch_list
|
||||||
|
|
||||||
image_raw = str(config.get("image") or "").strip()
|
image_raw = str(config.get("image") or "").strip()
|
||||||
image = image_raw.replace("{arch}", arch)
|
image = image_raw.replace("{arch}", arch)
|
||||||
version = str(config.get("version") or "").strip()
|
version = str(config.get("version") or "").strip()
|
||||||
@@ -218,16 +221,16 @@ jobs:
|
|||||||
url = str(config.get("url") or "").strip()
|
url = str(config.get("url") or "").strip()
|
||||||
build_from = str(build_from_map.get(arch) or "").strip()
|
build_from = str(build_from_map.get(arch) or "").strip()
|
||||||
build_date = datetime.now(timezone.utc).replace(microsecond=0).isoformat()
|
build_date = datetime.now(timezone.utc).replace(microsecond=0).isoformat()
|
||||||
|
|
||||||
dockerfile = addon_dir / f"Dockerfile.{arch}"
|
dockerfile = addon_dir / f"Dockerfile.{arch}"
|
||||||
if dockerfile.exists():
|
if dockerfile.exists():
|
||||||
dockerfile_name = dockerfile.name
|
dockerfile_path = str(dockerfile)
|
||||||
has_dockerfile = True
|
has_dockerfile = True
|
||||||
else:
|
else:
|
||||||
dockerfile = addon_dir / "Dockerfile"
|
dockerfile = addon_dir / "Dockerfile"
|
||||||
dockerfile_name = dockerfile.name
|
dockerfile_path = str(dockerfile)
|
||||||
has_dockerfile = dockerfile.exists()
|
has_dockerfile = dockerfile.exists()
|
||||||
|
|
||||||
labels = [
|
labels = [
|
||||||
f"io.hass.name={name}",
|
f"io.hass.name={name}",
|
||||||
f"io.hass.description={description}",
|
f"io.hass.description={description}",
|
||||||
@@ -235,29 +238,31 @@ jobs:
|
|||||||
]
|
]
|
||||||
if url:
|
if url:
|
||||||
labels.append(f"io.hass.url={url}")
|
labels.append(f"io.hass.url={url}")
|
||||||
|
|
||||||
build_args = [
|
build_args = [
|
||||||
|
f"BUILD_ARCH={arch}",
|
||||||
|
f"BUILD_VERSION={version}",
|
||||||
f"BUILD_DATE={build_date}",
|
f"BUILD_DATE={build_date}",
|
||||||
f"BUILD_DESCRIPTION={description}",
|
f"BUILD_DESCRIPTION={description}",
|
||||||
f"BUILD_NAME={name}",
|
f"BUILD_NAME={name}",
|
||||||
f"BUILD_REF={os.environ.get('GITHUB_SHA', '')}",
|
f"BUILD_REF={github_sha}",
|
||||||
f"BUILD_REPOSITORY={repository}",
|
f"BUILD_REPOSITORY={repository}",
|
||||||
]
|
]
|
||||||
if build_from:
|
if build_from:
|
||||||
build_args.insert(0, f"BUILD_FROM={build_from}")
|
build_args.insert(2, f"BUILD_FROM={build_from}")
|
||||||
|
|
||||||
|
|
||||||
def write_output(key: str, value: str):
|
def write_output(key: str, value: str):
|
||||||
with output_path.open("a", encoding="utf-8") as fh:
|
with output_path.open("a", encoding="utf-8") as fh:
|
||||||
print(f"{key}<<__EOF__", file=fh)
|
print(f"{key}<<__EOF__", file=fh)
|
||||||
print(value, file=fh)
|
print(value, file=fh)
|
||||||
print("__EOF__", file=fh)
|
print("__EOF__", file=fh)
|
||||||
|
|
||||||
|
|
||||||
write_output("architectures", json.dumps(arch_list))
|
write_output("architectures", json.dumps(arch_list))
|
||||||
write_output("build_arch", "true" if build_arch else "false")
|
write_output("build_arch", "true" if build_arch else "false")
|
||||||
write_output("has_dockerfile", "true" if has_dockerfile else "false")
|
write_output("has_dockerfile", "true" if has_dockerfile else "false")
|
||||||
write_output("dockerfile", dockerfile_name)
|
write_output("dockerfile", dockerfile_path)
|
||||||
write_output("image", image)
|
write_output("image", image)
|
||||||
write_output("version", version)
|
write_output("version", version)
|
||||||
write_output("name", name)
|
write_output("name", name)
|
||||||
@@ -412,3 +417,4 @@ jobs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
git push origin HEAD:master
|
git push origin HEAD:master
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user