|
| 1 | +name: Check type stubs |
| 2 | +env: |
| 3 | + version: 10.0.0 |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - "master" |
| 9 | + pull_request: |
| 10 | + types: [opened, synchronize, reopened, ready_for_review] |
| 11 | + branches: |
| 12 | + - "master" |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +defaults: |
| 16 | + run: |
| 17 | + shell: bash |
| 18 | + |
| 19 | +jobs: |
| 20 | + stubtest: |
| 21 | + if: (github.event_name != 'pull_request') || (github.event.pull_request.draft == false) |
| 22 | + runs-on: ubuntu-24.04 |
| 23 | + env: |
| 24 | + PYTHON_VERSION: "3.14" |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v6 |
| 28 | + |
| 29 | + - name: Install dependencies (SCIPOptSuite) |
| 30 | + run: | |
| 31 | + wget --quiet --no-check-certificate "https://github.com/scipopt/scip/releases/download/v${{ env.version }}/scipoptsuite_${{ env.version }}-1+jammy_amd64.deb" |
| 32 | + sudo apt-get update && sudo apt install -y ./scipoptsuite_${{ env.version }}-1+jammy_amd64.deb |
| 33 | +
|
| 34 | + - name: Setup python ${{ env.PYTHON_VERSION }} |
| 35 | + uses: actions/setup-python@v4 |
| 36 | + with: |
| 37 | + python-version: ${{ env.PYTHON_VERSION }} |
| 38 | + |
| 39 | + - name: Install mypy |
| 40 | + run: | |
| 41 | + python -m pip install mypy |
| 42 | +
|
| 43 | + - name: Install PySCIPOpt |
| 44 | + run: | |
| 45 | + export CFLAGS="-O0 -ggdb -Wall -Wextra -Werror -Wno-error=deprecated-declarations" # Debug mode. More warnings. Warnings as errors, but allow deprecated declarations. |
| 46 | + python -m pip install . -v 2>&1 | tee build.log |
| 47 | +
|
| 48 | + - name: Run MyPy |
| 49 | + run: python -m mypy --package pyscipopt |
| 50 | + |
| 51 | + - name: Run stubtest |
| 52 | + id: stubtest |
| 53 | + run: stubs/test.sh |
| 54 | + |
| 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 | +
|
| 70 | + lint: |
| 71 | + runs-on: ubuntu-latest |
| 72 | + env: |
| 73 | + FILES: src/pyscipopt/scip.pyi |
| 74 | + |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v6 |
| 77 | + |
| 78 | + - name: Install Ruff |
| 79 | + uses: astral-sh/ruff-action@v3 |
| 80 | + with: |
| 81 | + args: "--version" |
| 82 | + |
| 83 | + - name: Lint type stubs |
| 84 | + run: ruff check ${{ env.FILES }} --extend-select ANN,I,PYI,RUF100 |
| 85 | + |
| 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