forked from scipopt/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
198 lines (179 loc) · 7.48 KB
/
Copy pathstubs.yml
File metadata and controls
198 lines (179 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Check type stubs
env:
version: 10.0.0
on:
push:
branches:
- "master"
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- "master"
workflow_dispatch:
defaults:
run:
shell: bash
jobs:
stubtest:
if: (github.event_name != 'pull_request') || (github.event.pull_request.draft == false)
runs-on: ubuntu-24.04
env:
PYTHON_VERSION: "3.14"
steps:
- uses: actions/checkout@v6
- name: Install dependencies (SCIPOptSuite)
run: |
wget --quiet --no-check-certificate "https://github.com/scipopt/scip/releases/download/v${{ env.version }}/scipoptsuite_${{ env.version }}-1+jammy_amd64.deb"
sudo apt-get update && sudo apt install -y ./scipoptsuite_${{ env.version }}-1+jammy_amd64.deb
- name: Setup python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install PySCIPOpt
run: |
export CFLAGS="-O0 -ggdb -Wall -Wextra -Werror -Wno-error=deprecated-declarations" # Debug mode. More warnings. Warnings as errors, but allow deprecated declarations.
python -m pip install . -v 2>&1 | tee build.log
- name: Install typing dependencies
run: |
python -m pip install -r requirements/pylock.types.toml
- name: Run MyPy
run: python -m mypy --package pyscipopt
- name: Run stubtest
id: stubtest
run: stubs/test.sh
- name: Check baseline test files are up to date
run: |
./stubs/baseline.sh
# we need to ignore the .deb file we download above
if [[ -n $(git status --porcelain --untracked-files=no) ]]; then
echo "Baseline test files are out of date, run: ./stubs/baseline.sh on Python ${{ env.PYTHON_VERSION }} to update"
exit 1
fi
- name: Stub regeneration hint
if: failure() && steps.stubtest.outcome == 'failure'
run: |
echo "Type stubs are out of date. Please regenerate them locally:"
echo ""
echo " python scripts/generate_stubs.py"
echo " pip install ruff"
echo " ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix"
echo " ruff format src/pyscipopt/scip.pyi"
echo ""
echo "Then commit the updated scip.pyi file."
echo ""
echo "Tip: You can set up a pre-commit hook to do this automatically."
echo "See .pre-commit-config.yaml in the repository root."
lint:
runs-on: ubuntu-latest
env:
FILES: src/pyscipopt/scip.pyi
steps:
- uses: actions/checkout@v6
- name: Install Ruff
uses: astral-sh/ruff-action@v3
with:
args: "--version"
- name: Lint type stubs
run: ruff check ${{ env.FILES }} --extend-select ANN,I,PYI,RUF100
- name: Format check type stubs
run: ruff format --check ${{ env.FILES }}
# =============================================================================
# AUTO-REGENERATION STEPS (disabled)
# =============================================================================
# TODO: To enable automatic stub regeneration in CI, uncomment the code below
# and add the following to the stubtest job:
# - Add these permissions to stubtest job:
# permissions:
# contents: write
# pull-requests: write
# - Add these to the checkout step:
# with:
# ref: ${{ github.head_ref || github.ref }}
# repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
# token: ${{ secrets.GITHUB_TOKEN }}
# fetch-depth: 0
# - Change "Run MyPy" and "Run stubtest" to have continue-on-error: true
# and rename to "Run MyPy (before regeneration)" / "Run stubtest (before regeneration)"
# - Add "needs: stubtest" to the lint job
# - Remove the "Stub regeneration hint" step
#
# Then uncomment these steps:
#
# - name: Check if safe to run generate_stubs.py
# id: check_script
# run: |
# # For same-repo PRs, always allow running the script
# if [[ "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]] || [[ "${{ github.event_name }}" != "pull_request" ]]; then
# echo "allowed=true" >> $GITHUB_OUTPUT
# echo "Same-repo PR or push - allowing regeneration"
# else
# # For fork PRs, only allow if script is unchanged from master
# git fetch origin master
# if git diff --quiet origin/master -- scripts/generate_stubs.py; then
# echo "allowed=true" >> $GITHUB_OUTPUT
# echo "Fork PR with unchanged script - allowing regeneration"
# else
# echo "allowed=false" >> $GITHUB_OUTPUT
# echo "::warning::Fork PR with modified scripts/generate_stubs.py - skipping auto-regeneration for security"
# fi
# fi
#
# - name: Regenerate stubs
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
# run: |
# python scripts/generate_stubs.py
# pip install ruff
# ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix
# ruff format src/pyscipopt/scip.pyi
# cp src/pyscipopt/scip.pyi "$(python -c 'import pyscipopt; print(pyscipopt.__path__[0])')/scip.pyi"
#
# - name: Run MyPy (after regeneration)
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
# run: python -m mypy --package pyscipopt
#
# - name: Run stubtest (after regeneration)
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
# run: stubs/test.sh
#
# - name: Commit and push updated stubs
# id: commit
# 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
# run: |
# git config user.name "github-actions[bot]"
# git config user.email "github-actions[bot]@users.noreply.github.com"
# git add src/pyscipopt/scip.pyi
# DIFF=$(git diff --cached --stat)
# echo "diff<<EOF" >> $GITHUB_OUTPUT
# echo "$DIFF" >> $GITHUB_OUTPUT
# echo "EOF" >> $GITHUB_OUTPUT
# DETAILED_DIFF=$(git diff --cached src/pyscipopt/scip.pyi | head -100 || true)
# echo "detailed_diff<<EOF" >> $GITHUB_OUTPUT
# echo "$DETAILED_DIFF" >> $GITHUB_OUTPUT
# echo "EOF" >> $GITHUB_OUTPUT
# if git diff --cached --quiet; then
# echo "committed=false" >> $GITHUB_OUTPUT
# else
# git commit -m "Auto-regenerate type stubs"
# git push
# echo "committed=true" >> $GITHUB_OUTPUT
# fi
#
# - name: Comment on PR
# if: steps.commit.outputs.committed == 'true'
# env:
# GH_TOKEN: ${{ github.token }}
# run: |
# gh pr comment ${{ github.event.pull_request.number }} --body "## 🤖 Type stubs automatically regenerated
#
# The type stubs were out of date and have been automatically regenerated.
#
# <details>
# <summary>Changes summary</summary>
#
# \`\`\`
# ${{ steps.commit.outputs.diff }}
# \`\`\`
#
# </details>"