4949 run : python -m mypy --package pyscipopt
5050
5151 - name : Run stubtest
52+ id : stubtest
5253 run : stubs/test.sh
5354
55+ - name : Stub regeneration hint
56+ if : failure() && steps.stubtest.outcome == 'failure'
57+ run : |
58+ echo "Type stubs are out of date. Please regenerate them locally:"
59+ echo ""
60+ echo " python scripts/generate_stubs.py"
61+ echo " pip install ruff"
62+ echo " ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix"
63+ echo " ruff format src/pyscipopt/scip.pyi"
64+ echo ""
65+ echo "Then commit the updated scip.pyi file."
66+ echo ""
67+ echo "Tip: You can set up a pre-commit hook to do this automatically."
68+ echo "See .pre-commit-config.yaml in the repository root."
69+
5470 lint :
5571 runs-on : ubuntu-latest
5672 env :
@@ -67,5 +83,104 @@ jobs:
6783 - name : Lint type stubs
6884 run : ruff check ${{ env.FILES }} --extend-select ANN,I,PYI,RUF100
6985
70- - name : Format type stubs
71- run : ruff format ${{ env.FILES }}
86+ - name : Format check type stubs
87+ run : ruff format --check ${{ env.FILES }}
88+
89+ # =============================================================================
90+ # AUTO-REGENERATION STEPS (disabled)
91+ # =============================================================================
92+ # TODO: To enable automatic stub regeneration in CI, uncomment the code below
93+ # and add the following to the stubtest job:
94+ # - Add these permissions to stubtest job:
95+ # permissions:
96+ # contents: write
97+ # pull-requests: write
98+ # - Add these to the checkout step:
99+ # with:
100+ # ref: ${{ github.head_ref || github.ref }}
101+ # repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
102+ # token: ${{ secrets.GITHUB_TOKEN }}
103+ # fetch-depth: 0
104+ # - Change "Run MyPy" and "Run stubtest" to have continue-on-error: true
105+ # and rename to "Run MyPy (before regeneration)" / "Run stubtest (before regeneration)"
106+ # - Add "needs: stubtest" to the lint job
107+ # - Remove the "Stub regeneration hint" step
108+ #
109+ # Then uncomment these steps:
110+ #
111+ # - name: Check if safe to run generate_stubs.py
112+ # id: check_script
113+ # run: |
114+ # # For same-repo PRs, always allow running the script
115+ # if [[ "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]] || [[ "${{ github.event_name }}" != "pull_request" ]]; then
116+ # echo "allowed=true" >> $GITHUB_OUTPUT
117+ # echo "Same-repo PR or push - allowing regeneration"
118+ # else
119+ # # For fork PRs, only allow if script is unchanged from master
120+ # git fetch origin master
121+ # if git diff --quiet origin/master -- scripts/generate_stubs.py; then
122+ # echo "allowed=true" >> $GITHUB_OUTPUT
123+ # echo "Fork PR with unchanged script - allowing regeneration"
124+ # else
125+ # echo "allowed=false" >> $GITHUB_OUTPUT
126+ # echo "::warning::Fork PR with modified scripts/generate_stubs.py - skipping auto-regeneration for security"
127+ # fi
128+ # fi
129+ #
130+ # - name: Regenerate stubs
131+ # if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
132+ # run: |
133+ # python scripts/generate_stubs.py
134+ # pip install ruff
135+ # ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix
136+ # ruff format src/pyscipopt/scip.pyi
137+ # cp src/pyscipopt/scip.pyi "$(python -c 'import pyscipopt; print(pyscipopt.__path__[0])')/scip.pyi"
138+ #
139+ # - name: Run MyPy (after regeneration)
140+ # if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
141+ # run: python -m mypy --package pyscipopt
142+ #
143+ # - name: Run stubtest (after regeneration)
144+ # if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
145+ # run: stubs/test.sh
146+ #
147+ # - name: Commit and push updated stubs
148+ # id: commit
149+ # if: steps.stubtest_before.outcome == 'failure' && github.event_name == 'pull_request' && steps.check_script.outputs.allowed == 'true' && github.event.pull_request.head.repo.full_name == github.repository
150+ # run: |
151+ # git config user.name "github-actions[bot]"
152+ # git config user.email "github-actions[bot]@users.noreply.github.com"
153+ # git add src/pyscipopt/scip.pyi
154+ # DIFF=$(git diff --cached --stat)
155+ # echo "diff<<EOF" >> $GITHUB_OUTPUT
156+ # echo "$DIFF" >> $GITHUB_OUTPUT
157+ # echo "EOF" >> $GITHUB_OUTPUT
158+ # DETAILED_DIFF=$(git diff --cached src/pyscipopt/scip.pyi | head -100 || true)
159+ # echo "detailed_diff<<EOF" >> $GITHUB_OUTPUT
160+ # echo "$DETAILED_DIFF" >> $GITHUB_OUTPUT
161+ # echo "EOF" >> $GITHUB_OUTPUT
162+ # if git diff --cached --quiet; then
163+ # echo "committed=false" >> $GITHUB_OUTPUT
164+ # else
165+ # git commit -m "Auto-regenerate type stubs"
166+ # git push
167+ # echo "committed=true" >> $GITHUB_OUTPUT
168+ # fi
169+ #
170+ # - name: Comment on PR
171+ # if: steps.commit.outputs.committed == 'true'
172+ # env:
173+ # GH_TOKEN: ${{ github.token }}
174+ # run: |
175+ # gh pr comment ${{ github.event.pull_request.number }} --body "## 🤖 Type stubs automatically regenerated
176+ #
177+ # The type stubs were out of date and have been automatically regenerated.
178+ #
179+ # <details>
180+ # <summary>Changes summary</summary>
181+ #
182+ # \`\`\`
183+ # ${{ steps.commit.outputs.diff }}
184+ # \`\`\`
185+ #
186+ # </details>"
0 commit comments