-
Notifications
You must be signed in to change notification settings - Fork 56
230 lines (229 loc) · 7.32 KB
/
reusable-precommit.yml
File metadata and controls
230 lines (229 loc) · 7.32 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: Pre-commit (reusable)
on:
workflow_call:
inputs:
batfish_repo:
description: "Git repo containing Batfish"
required: false
default: "batfish/batfish"
type: string
batfish_ref:
description: "Git ref for Batfish version to release"
required: false
default: "master"
type: string
secrets:
PYBATFISH_CODECOV_TOKEN:
required: true
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Run checks
run: |
pip install pre-commit
pre-commit run --all-files
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Run checks
run: |
pip install --upgrade pip wheel 'setuptools>=77.0.1'
pip install -e .[dev]
mypy pybatfish tests
bf_build:
runs-on: ubuntu-latest
steps:
- name: Checkout Batfish repo
uses: actions/checkout@v6
with:
repository: ${{ inputs.batfish_repo }}
ref: ${{ inputs.batfish_ref }}
- name: Bazel cache
uses: actions/cache@v5
with:
path: "~/.cache/bazel"
key: ${{runner.os}}-bazel-17-${{ hashFiles('.bazelversion', 'WORKSPACE', 'maven_install.json') }}-${{ needs.get_date.outputs.ymd }}
restore-keys: |
${{runner.os}}-bazel-17-${{ hashFiles('.bazelversion', 'WORKSPACE', 'maven_install.json') }}-
- uses: actions/setup-java@v5
with:
distribution: "temurin"
java-version: "17"
- name: Build JAR
run: |
bazel build //projects/allinone:allinone_main_deploy.jar
cp bazel-bin/projects/allinone/allinone_main_deploy.jar allinone.jar
- name: Questions tar
run: |
TMP_DIR=$(mktemp -d)
QUESTION_DIR=${TMP_DIR}/questions
mkdir -p ${QUESTION_DIR}
cp -r questions/{stable,experimental} ${QUESTION_DIR}
tar -czf questions.tgz -C ${TMP_DIR} questions
- name: Upload JAR
uses: actions/upload-artifact@v7
with:
name: bf_jar
path: allinone.jar
- name: Upload questions
uses: actions/upload-artifact@v7
with:
name: bf_questions
path: questions.tgz
unit_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}
- name: Run tests
run: |
pip install --upgrade pip wheel
pip install -e .[dev]
pytest tests
- name: codecov
# Let codecov upload fail - codecov goes down not infrequently.
continue-on-error: true
run: |
version=$(echo ${{ matrix.python_version }} | sed s/\\.//)
bash <(curl -s https://codecov.io/bash) -t ${{ secrets.PYBATFISH_CODECOV_TOKEN }} -F unit${version}
strategy:
matrix:
python_version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
integration_tests:
runs-on: ubuntu-latest
needs:
- bf_build
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: "temurin"
java-version: "17"
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}
- name: Download bf JAR
uses: actions/download-artifact@v8
with:
name: bf_jar
- name: Download questions
uses: actions/download-artifact@v8
with:
name: bf_questions
- name: Run tests
run: |
tar -xzf questions.tgz
coordinator_args=(\
-templatedirs=questions \
-periodassignworkms=5 \
)
allinone_args=(\
-runclient=false
-coordinatorargs="$(echo -n "${coordinator_args[@]}")" \
)
java -cp allinone.jar org.batfish.allinone.Main "${allinone_args[@]}" 2>&1 > batfish.log &
pip install -e .[dev] -q
pytest tests/integration
- name: codecov
# Let codecov upload fail - codecov goes down not infrequently.
continue-on-error: true
run: |
version=$(echo ${{ matrix.python_version }} | sed s/\\.//)
bash <(curl -s https://codecov.io/bash) -t ${{ secrets.PYBATFISH_CODECOV_TOKEN }} -F integration${version}
strategy:
matrix:
python_version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
doc_tests:
runs-on: ubuntu-latest
needs:
- bf_build
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: "temurin"
java-version: "17"
- uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Download bf JAR
uses: actions/download-artifact@v8
with:
name: bf_jar
- name: Download questions
uses: actions/download-artifact@v8
with:
name: bf_questions
- name: Run tests
run: |
tar -xzf questions.tgz
java -cp allinone.jar org.batfish.allinone.Main -runclient false -coordinatorargs '-templatedirs questions -periodassignworkms=5' 2>&1 > batfish.log &
pip install --upgrade pip setuptools wheel -q
pip install -e .[dev] -q
pytest docs
pytest pybatfish --doctest-modules
build_docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: "temurin"
java-version: "17"
- uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Build docs
run: |
sudo apt update -qq
sudo apt -qq install -y pandoc
pip install --upgrade pip setuptools wheel -q
pip install -e .[dev] -q
pushd docs
make html
popd
- name: Upload docs
uses: actions/upload-artifact@v7
with:
name: docs
path: docs/build/html
readthedocs_build:
runs-on: ubuntu-22.04 # Match ReadTheDocs OS
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.10" # Match ReadTheDocs Python version
- name: Build docs in ReadTheDocs-like environment
run: |
sudo apt update -qq
sudo apt -qq install -y pandoc
export READTHEDOCS_OUTPUT=../../RTDOUT
# The remaining commands are copied direct from readthedocs.org build logs
# We may need to update them if RTD changes what it does.
python -m pip install --upgrade --no-cache-dir pip setuptools
python -m pip install --upgrade --no-cache-dir sphinx
python -m pip install --upgrade --upgrade-strategy only-if-needed --no-cache-dir .[dev]
cd docs/source ## This command is not copied, but it seems that RTD switches directories invisible at some point
python -m sphinx -T -W --keep-going -b html -d _build/doctrees -D language=en . $READTHEDOCS_OUTPUT/html