-
Notifications
You must be signed in to change notification settings - Fork 77
Add GitHub workflow for syncing HA device classes + constants #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
TheJulianJES
wants to merge
17
commits into
dev
Choose a base branch
from
zigpy-bot/sync-device-classes
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ff19dfb
Add device class sync workflow comparing constants against HA
zigpy-review-bot 97b39fd
Drop homeassistant from testing extras
zigpy-review-bot 6050721
Add --write mode to compare_constants for auto-syncing
zigpy-review-bot 4d9713f
Open a PR from the device class sync workflow
zigpy-review-bot 99d6f11
Replace compare_constants with a verbatim HA syncer
zigpy-review-bot b4658ac
Sync device classes against HA Core dev and open a PR
zigpy-review-bot 590810a
Add UnitOfDensity/UnitOfRatio and a backwards-compat unit constants s…
zigpy-review-bot a7b7c42
Drop zha-quirks from the sync workflow
zigpy-review-bot 3970f37
Handle enums HA removes and anchor new-enum insertion
zigpy-review-bot 60ad061
Update tools/README for the sync tool's current behavior
zigpy-review-bot b268441
Fix sync_constants docstring contradiction on removal
zigpy-review-bot 8632808
Harden sync workflow and enum removal after review
zigpy-review-bot f09bd34
Drop the ruff format step and summarise changes in the PR body
zigpy-review-bot b8b6444
Correct sync docs and a units.py comment
zigpy-review-bot 369c4cf
Report per-enum member and value changes in the sync summary
zigpy-review-bot 6922dcf
Set pipefail in the sync step so a tool failure fails the run
zigpy-review-bot 3b356b9
Address PR review: pin Python >=3.14.2 and simplify app-user step
zigpy-review-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| name: Sync device classes from Home Assistant | ||
|
|
||
| # Copies ZHA's local copies of Home Assistant enums (unit enums, device class / | ||
| # mode enums) verbatim from Home Assistant's `dev` branch via | ||
| # `tools/sync_constants.py`, then opens/updates a single pull request with the | ||
| # result. The PR always targets the `sync/device-classes` branch, so each run | ||
| # updates the same PR rather than opening new ones. | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| schedule: | ||
| - cron: "45 6 * * *" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| # Serialise runs so a manual dispatch can't race the scheduled one on the | ||
| # shared sync/device-classes branch. | ||
| concurrency: | ||
| group: sync-device-classes | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| sync: | ||
| name: Sync device classes | ||
| runs-on: ubuntu-latest | ||
| if: github.repository == 'zigpy/zha' | ||
| steps: | ||
| # Uses a GitHub App so the pull request is authored by the bot account and | ||
| # triggers CI (a PR opened with the default GITHUB_TOKEN would not). The App | ||
| # ID / private key must be configured as a repository variable and secret. | ||
| - name: Generate a token | ||
| id: app-token | ||
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 | ||
| with: | ||
| app-id: ${{ vars.SYNC_APP_ID }} | ||
| private-key: ${{ secrets.SYNC_APP_PRIVATE_KEY }} | ||
| permission-contents: write | ||
| permission-pull-requests: write | ||
|
|
||
| - name: Get the app user id | ||
| id: app-user | ||
| run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | ||
| env: | ||
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
|
|
||
| - name: Checkout ZHA | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| token: ${{ steps.app-token.outputs.token }} | ||
|
|
||
| - name: Checkout Home Assistant Core (dev) | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| repository: home-assistant/core | ||
| ref: dev | ||
| path: lib/home-assistant | ||
|
|
||
| - name: Set up uv | ||
| uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 | ||
| with: | ||
| enable-cache: true | ||
|
|
||
| - name: Install Home Assistant | ||
| # The sync tool imports only `homeassistant` and reads ZHA's files as | ||
| # text (it never imports ZHA), so ZHA itself is not installed — avoiding a | ||
| # joint resolution of ZHA's and HA-dev's pins. HA requires Python 3.14.2+. | ||
| run: | | ||
| uv venv --python 3.14 | ||
| uv pip install -e ./lib/home-assistant | ||
|
TheJulianJES marked this conversation as resolved.
|
||
|
|
||
| - name: Sync constants | ||
| # No separate format step: the tool emits ruff-clean output, and the pull | ||
| # request's own pre-commit CI runs the repo-pinned ruff as the check. | ||
| # Capture the tool's summary of what changed for the PR body. | ||
| run: | | ||
| set -o pipefail # the default step shell lacks it, so `| tee` would hide a tool failure | ||
| .venv/bin/python -m tools.sync_constants | tee "$RUNNER_TEMP/sync.txt" | ||
| { | ||
| echo 'Automated copy of the Home Assistant enums ZHA mirrors, generated by' | ||
| echo '`python -m tools.sync_constants` against the Home Assistant `dev` branch.' | ||
| echo 'Please review before merging.' | ||
| echo | ||
| echo '<details><summary>Sync output</summary>' | ||
| echo | ||
| echo '```' | ||
| cat "$RUNNER_TEMP/sync.txt" | ||
| echo '```' | ||
| echo | ||
| echo '</details>' | ||
| } > "$RUNNER_TEMP/pr-body.md" | ||
|
|
||
| - name: Create pull request | ||
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 | ||
| with: | ||
| token: ${{ steps.app-token.outputs.token }} | ||
| add-paths: zha/ | ||
| commit-message: "Sync device classes from Home Assistant" | ||
| committer: "${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.app-user.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>" | ||
| author: "${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.app-user.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>" | ||
| branch: sync/device-classes | ||
| delete-branch: true | ||
| title: "Sync device classes from Home Assistant" | ||
| body-path: ${{ runner.temp }}/pr-body.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.