mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-09-05 09:23:33 +02:00
Validate completed app_config migration
This commit is contained in:
131
.github/workflows/agent-migrate-app-config.yml
vendored
131
.github/workflows/agent-migrate-app-config.yml
vendored
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
name: Migrate add-on config map names
|
name: Validate add-on config map migration
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -7,10 +7,10 @@ on:
|
|||||||
- agent/support-app-config-linter
|
- agent/support-app-config-linter
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
migrate:
|
validate:
|
||||||
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
|
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -21,92 +21,75 @@ jobs:
|
|||||||
ref: ${{ github.event.pull_request.head.ref }}
|
ref: ${{ github.event.pull_request.head.ref }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Replace legacy map names
|
- name: Validate repository migration
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
python3 - <<'PY'
|
git diff --check "${{ github.event.pull_request.base.sha }}...HEAD"
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
LEGACY = b"addon_config"
|
|
||||||
CURRENT = b"app_config"
|
|
||||||
HELPER = Path(".github/workflows/agent-migrate-app-config.yml")
|
|
||||||
CHANGELOG_NOTE = "- Migrate legacy add-on configuration map names to current app configuration terminology.\n"
|
|
||||||
|
|
||||||
|
|
||||||
def tracked_paths() -> list[Path]:
|
|
||||||
output = subprocess.check_output(["git", "ls-files", "-z"])
|
|
||||||
return [Path(value.decode()) for value in output.split(b"\0") if value]
|
|
||||||
|
|
||||||
|
|
||||||
paths = tracked_paths()
|
|
||||||
affected_addons: set[str] = set()
|
|
||||||
for path in paths:
|
|
||||||
if len(path.parts) != 2 or path.name not in {
|
|
||||||
"config.json",
|
|
||||||
"config.yaml",
|
|
||||||
"config.yml",
|
|
||||||
}:
|
|
||||||
continue
|
|
||||||
if path.is_symlink() or not path.is_file():
|
|
||||||
continue
|
|
||||||
if LEGACY in path.read_bytes():
|
|
||||||
affected_addons.add(path.parts[0])
|
|
||||||
|
|
||||||
if not affected_addons:
|
|
||||||
raise SystemExit("No add-on manifests containing addon_config were found")
|
|
||||||
|
|
||||||
for addon in sorted(affected_addons):
|
|
||||||
changelog = Path(addon) / "CHANGELOG.md"
|
|
||||||
if not changelog.is_file():
|
|
||||||
raise SystemExit(f"Missing required changelog: {changelog}")
|
|
||||||
text = changelog.read_text(encoding="utf-8")
|
|
||||||
if CHANGELOG_NOTE.strip() not in text:
|
|
||||||
changelog.write_text(CHANGELOG_NOTE + text, encoding="utf-8")
|
|
||||||
|
|
||||||
replaced_files: list[Path] = []
|
|
||||||
for path in paths:
|
|
||||||
if path == HELPER or path.is_symlink() or not path.is_file():
|
|
||||||
continue
|
|
||||||
data = path.read_bytes()
|
|
||||||
if LEGACY not in data or b"\0" in data:
|
|
||||||
continue
|
|
||||||
path.write_bytes(data.replace(LEGACY, CURRENT))
|
|
||||||
replaced_files.append(path)
|
|
||||||
|
|
||||||
print(f"Affected add-ons: {len(affected_addons)}")
|
|
||||||
print(f"Files with terminology replacements: {len(replaced_files)}")
|
|
||||||
print("Affected add-ons:")
|
|
||||||
for addon in sorted(affected_addons):
|
|
||||||
print(f"- {addon}")
|
|
||||||
PY
|
|
||||||
|
|
||||||
git diff --check
|
|
||||||
|
|
||||||
if git grep -n addon_config -- ':!.github/workflows/agent-migrate-app-config.yml'; then
|
if git grep -n addon_config -- ':!.github/workflows/agent-migrate-app-config.yml'; then
|
||||||
echo "Legacy addon_config references remain outside the temporary migration workflow" >&2
|
echo "Legacy map-name references remain outside the temporary validation workflow" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
changed_configs=$(git diff --name-only -- '*config.json' '*config.yaml' '*config.yml' | wc -l)
|
changed_configs=$(git diff --name-only "${{ github.event.pull_request.base.sha }}...HEAD" -- '*config.json' '*config.yaml' '*config.yml' | wc -l)
|
||||||
|
changed_changelogs=$(git diff --name-only "${{ github.event.pull_request.base.sha }}...HEAD" -- '*/CHANGELOG.md' | wc -l)
|
||||||
if [ "$changed_configs" -eq 0 ]; then
|
if [ "$changed_configs" -eq 0 ]; then
|
||||||
echo "No add-on manifests changed" >&2
|
echo "No add-on manifests changed" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Changed manifests: $changed_configs"
|
if [ "$changed_changelogs" -lt "$changed_configs" ]; then
|
||||||
|
echo "Fewer changelogs than changed manifests: $changed_changelogs < $changed_configs" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Commit migration
|
echo "Changed manifests: $changed_configs"
|
||||||
|
echo "Changed changelogs: $changed_changelogs"
|
||||||
|
|
||||||
|
- name: Run compatibility normalizer unit tests
|
||||||
|
run: python3 .github/scripts/test_prepare_addon_lint_config.py
|
||||||
|
|
||||||
|
- name: Create current-schema linter fixtures
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
mkdir -p .tmp-addon-linter-short .tmp-addon-linter-long
|
||||||
|
|
||||||
git config user.name "github-actions[bot]"
|
cat > .tmp-addon-linter-short/config.yaml <<'SHORT_FIXTURE'
|
||||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
---
|
||||||
git add -u
|
name: App Config Short Form Fixture
|
||||||
git diff --cached --check
|
version: "1.0.0"
|
||||||
git commit -m "Migrate legacy addon_config maps to app_config"
|
slug: app_config_short_fixture
|
||||||
git push origin HEAD:${{ github.event.pull_request.head.ref }}
|
description: Validates current Home Assistant short-form app map names
|
||||||
|
arch:
|
||||||
|
- amd64
|
||||||
|
map:
|
||||||
|
- app_config:rw
|
||||||
|
- all_app_configs:ro
|
||||||
|
SHORT_FIXTURE
|
||||||
|
|
||||||
|
cat > .tmp-addon-linter-long/config.yaml <<'LONG_FIXTURE'
|
||||||
|
---
|
||||||
|
name: App Config Long Form Fixture
|
||||||
|
version: "1.0.0"
|
||||||
|
slug: app_config_long_fixture
|
||||||
|
description: Validates current Home Assistant long-form app map names
|
||||||
|
arch:
|
||||||
|
- amd64
|
||||||
|
map:
|
||||||
|
- type: app_config
|
||||||
|
read_only: false
|
||||||
|
- type: all_app_configs
|
||||||
|
read_only: true
|
||||||
|
LONG_FIXTURE
|
||||||
|
|
||||||
|
- name: Verify short-form current map names through upstream linter
|
||||||
|
uses: ./.github/actions/addon-linter
|
||||||
|
with:
|
||||||
|
path: ./.tmp-addon-linter-short
|
||||||
|
|
||||||
|
- name: Verify long-form current map names through upstream linter
|
||||||
|
uses: ./.github/actions/addon-linter
|
||||||
|
with:
|
||||||
|
path: ./.tmp-addon-linter-long
|
||||||
|
|||||||
Reference in New Issue
Block a user