Add pre-commit auto-update workflow - #853
Conversation
Add pre-commit auto-update workflow by copying changes from equivalent zppy-interfaces PR: https://github.com/E3SM-Project/zppy-interfaces/pull/57/changes
There was a problem hiding this comment.
Pull request overview
This PR adds automation for keeping pre-commit hook versions up to date in the
zppy repo, including a GitHub Actions workflow and a helper script to
propagate updated versions into other pinned dependency locations.
Changes:
- Add a
pre_commit_update_workflowscheduled/manual GitHub Actions workflow to
runpre-commit-updateand open a PR with the results. - Add
scripts/sync_pre_commit_versions.pyto sync pinned tool versions based
on.pre-commit-config.yaml. - Update existing pinned-version guidance and mypy hook dependencies to align
with the new workflow/script.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
scripts/sync_pre_commit_versions.py |
New script to derive versions from .pre-commit-config.yaml and apply them to pinned dependency files. |
conda/dev.yml |
Updates QA-tool comment to describe the intended update flow. |
.pre-commit-config.yaml |
Adds a mypy additional_dependencies entry and a note about syncing pins. |
.github/workflows/pre_commit_update_workflow.yml |
New scheduled workflow to auto-update pre-commit hooks and open a PR. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| auto-update: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 |
There was a problem hiding this comment.
We should probably use the latest version if we can.
There was a problem hiding this comment.
It would be worth adding dependebot to update them.
| hooks: | ||
| - id: mypy | ||
| args: ["--config=pyproject.toml"] | ||
| additional_dependencies: [types-PyYAML] |
There was a problem hiding this comment.
This seems to work fine for zppy-interfaces: https://github.com/E3SM-Project/zppy-interfaces/blob/main/.pre-commit-config.yaml#L44
Add a `qa` extra (pinned to the same black/flake8/isort/mypy/etc. versions as `.pre-commit-config.yaml`) and a `dev` extra to `pyproject.toml`, plus the missing `flake8-isort` and `types-PyYAML` pins in `conda/dev.yml`. Also add `[tool.pre-commit-update.yaml]` so `pre-commit-update` doesn't reformat the whole config on its next run. Brings zppy in line with the version-pinning pattern already used in zppy-interfaces, so `scripts/sync_pre_commit_versions.py --check` passes here too. Generated by Claude (Anthropic).
flake8-isort==6.1.1 pins isort<6, which conflicts with the isort==6.0.1 pin introduced in the previous commit and broke the conda env solve in CI. 6.1.2 raises the cap to isort<7, which is compatible. Change made in .pre-commit-config.yaml and propagated to conda/dev.yml and pyproject.toml via `python scripts/sync_pre_commit_versions.py`. Claude-generated, verified against the flake8-isort 6.1.1/6.1.2 PyPI metadata.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (5)
.github/workflows/pre_commit_update_workflow.yml:18
- The workflow requests
issues: writebut doesn’t appear to interact with issues. Reducing token permissions to only what’s used follows least-privilege and limits blast radius if a token is misused.
permissions:
contents: write
pull-requests: write
issues: write
.github/workflows/pre_commit_update_workflow.yml:29
- This workflow clones the repository later (
git clone ... update-pre-commit-deps), so the initialactions/checkoutstep is unused work. Consider removing it to reduce runtime and avoid confusion about which working tree subsequent commands operate on.
- uses: actions/checkout@v7
.github/workflows/pre_commit_update_workflow.yml:90
gh pr createwill fail if a PR fromupdate-pre-commit-depsalready exists (e.g., previous month’s PR still open), which would make this scheduled workflow brittle. Consider making this step idempotent by detecting an existing PR for the branch and updating it (or exiting successfully) instead of failing the run.
gh pr create \
--title "Update pre-commit and its dependencies" \
--body "This PR was auto-generated to update pre-commit and its dependencies." \
--head update-pre-commit-deps \
--reviewer ${{ env.REVIEWERS }} \
pyproject.toml:46
- The comment says these versions “always match … .pre-commit-config.yaml”, but this list includes non-pinned constraints like
types-PyYAML>=…while.pre-commit-config.yamlusestypes-PyYAMLwith no version. Consider rewording to clarify that only pinned tool versions are meant to be synchronized.
# make sure these always match conda/dev.yml and .pre-commit-config.yaml
# (run `python scripts/sync_pre_commit_versions.py` to sync them)
scripts/sync_pre_commit_versions.py:1
- Using
#!/usr/bin/env pythoncan resolve to Python 2 or fail on systems wherepythonisn’t installed. Since this repository targets Python 3, usepython3in the shebang for safer direct execution.
#!/usr/bin/env python
|
|
|
Thanks @xylar, looks like it passed! https://github.com/E3SM-Project/zppy/actions/runs/31820401775 |
|
That created #854. It required a few fixes, but I was eventually able to merge it. |
Add pre-commit auto-update workflow
Summary
Objectives:
Issue resolution:
Select one: This pull request is...
Small Change