Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/generate-pystubs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Generate PyStubs on Merge

on:
push:
branches:
- master # or 'main' if that’s your default branch
pull_request:
branches: [ master ]
Comment on lines +3 to +8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.


jobs:
generate-stubs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # needed for committing changes later

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
pip install mypy

- name: Generate type stubs
run: |
# Adjust 'src' to your code folder
mkdir -p stubs
stubgen -p your_package_name -o stubs

- name: Commit and push generated stubs
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