-
Notifications
You must be signed in to change notification settings - Fork 9
Created a yml file for auto-generating pystubs on workflow #111
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
base: master
Are you sure you want to change the base?
Created a yml file for auto-generating pystubs on workflow #111
Conversation
WalkthroughA GitHub Actions workflow is added to automatically generate Python type stubs on merges to master and pull requests. The workflow installs mypy, runs stubgen to create type stubs for the package, and commits any generated files using bot credentials. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related issues
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.github/workflows/generate-pystubs.yml (1)
29-33: Add error handling for stubgen failures.If stubgen fails on line 33 (e.g., due to syntax errors in the package or missing dependencies), the script continues and attempts to commit/push anyway. This masks the underlying issue.
Add error handling to exit early on stubgen failure:
- name: Generate type stubs run: | # Adjust 'src' to your code folder mkdir -p stubs + set -e stubgen -p your_package_name -o stubs + echo "Type stubs generated successfully"The
set -eflag ensures the workflow stops if any command fails.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/generate-pystubs.yml(1 hunks)
🔇 Additional comments (1)
.github/workflows/generate-pystubs.yml (1)
35-41: Ensure git push credentials and branch protection are compatible.The workflow uses bot credentials to commit and push to master. Verify that:
- The bot account has write permissions to the repository and branch.
- Branch protection rules (if any) allow force-pushes or bypass for bots, or the workflow must be adjusted.
- The
git push(line 41) does not fail silently if the branch is ahead or behind upstream.Consider adding explicit error handling:
git add stubs/ git commit -m "Auto-generate PyStubs on merge to master" || echo "No changes to commit" - git push + git push || echo "Warning: git push failed (branch may be protected or out of sync)"Alternatively, use
git push --force-with-leaseif you want to ensure the push succeeds, but only if you understand the implications for concurrent commits.
| on: | ||
| push: | ||
| branches: | ||
| - master # or 'main' if that’s your default branch | ||
| pull_request: | ||
| branches: [ master ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reconsider triggering on pull_request events.
The workflow is configured to run on both push to master and pull_request to master. This creates conflicting behavior:
- On push: The workflow generates stubs, commits, and pushes (desired).
- On pull_request: The workflow still attempts
git push(line 41), which typically fails or behaves unexpectedly on PR branches due to branch protection or read-only restrictions.
For PR events, the workflow likely should only validate that stubs can be generated without committing changes. Consider splitting logic by event type:
- name: Commit and push generated stubs
+ if: github.event_name == 'push'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add stubs/
git commit -m "Auto-generate PyStubs on merge to master" || echo "No changes to commit"
git push
+
+ - name: Validate stubs generation (PR only)
+ if: github.event_name == 'pull_request'
+ run: |
+ echo "Stubs generated successfully for validation"Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
.github/workflows/generate-pystubs.yml lines 3-8: the workflow currently runs on
both push and pull_request but still performs a git push step which fails on PR
runs; update the workflow to branch behavior by event type so PRs only run
generation/validation and pushes only occur on push events. Modify the job/steps
to conditionally skip the commit/push step when github.event_name != 'push' (or
add separate jobs keyed to github.event_name == 'pull_request' for validation
and github.event_name == 'push' for commit-and-push), and ensure the PR job
exits non-zero if generated stubs differ (to surface required changes) while the
push job performs the git commit and push.
|
Hey,@Dravis-Xam thanks for the PR Let's address the comments by CodeRabbit first |
|
Hey @Dravis-Xam , The only thing remaining, is to address the review comments by coderabbitai then we are good to merge 😄 |
Summary by CodeRabbit
New Features
Chores