-
Notifications
You must be signed in to change notification settings - Fork 159
426 lines (350 loc) · 15.3 KB
/
ci.yml
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# If you change the name, change the link on the README.md for the badge too
name: Tests
on:
push:
paths:
- sc2/**
- examples/**
- test/**
- docs_generate/**
- .pre-commit-config.yaml
- generate_dicts_from_data_json.py
- generate_id_constants_from_stableid.py
- uv.lock
- pyproject.toml
- README.md
- .github/workflows/ci.yml
pull_request:
branches:
- master
- develop
env:
# Docker image version, see https://hub.docker.com/r/burnysc2/python-sc2-docker/tags
# This version should always lack behind one version behind the docker-ci.yml because it is possible that it doesn't exist
VERSION_NUMBER: "1.0.2"
# TODO Change to '3.13' when a new image has been pushed
LATEST_PYTHON_VERSION: "3.11"
LATEST_SC2_VERSION: "4.10"
jobs:
run_pre_commit_hook:
name: Run pre-commit hook
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.LATEST_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.LATEST_PYTHON_VERSION }}
- name: Install uv
run: pip install uv
- name: Install dependencies
run: |
uv sync --frozen --no-cache --no-install-project
uv run pre-commit install
- name: Run pre-commit hooks
run: uv run pre-commit run --all-files --hook-stage push
generate_dicts_from_data_json:
name: Generate dicts from data.json
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.LATEST_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.LATEST_PYTHON_VERSION }}
- name: Install uv
run: pip install uv
- name: Install dependencies
run: |
uv sync --frozen --no-cache --no-install-project
uv run pre-commit install
- name: Run generate dicts
# Check if newly generated file is the same as existing file
# Run pre-commit hook to format files, always return exit code 0 to not end CI run
run: |
mv sc2/dicts sc2/dicts_old
uv run python generate_dicts_from_data_json.py
uv run pre-commit run --all-files --hook-stage push || true
rm -rf sc2/dicts/__pycache__ sc2/dicts_old/__pycache__
- name: Upload generated dicts folder as artifact
uses: actions/upload-artifact@v3
with:
name: Generated_dicts
path: sc2/dicts
- name: Compare generated dict files
# Exit code will be 0 if the results of both commands are equal
run: |
[[ `ls sc2/dicts | md5sum` == `ls sc2/dicts_old | md5sum` ]]
run_pytest_tests:
# Run pytest tests on pickle files (pre-generated SC2 API observations)
name: Run pytest
needs: [run_pre_commit_hook, generate_dicts_from_data_json]
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# Python 3.6 fails due to: https://www.python.org/dev/peps/pep-0563/
# If all type annotations were removed, this library should run in py3.6 and perhaps even 3.5
# Python 3.7 support has been dropped due to missing cached_property (new since Python 3.8) https://docs.python.org/3/library/functools.html#functools.cached_property
# Python 3.8 support has been dropped because numpy >=1.26.0 requires Python >=3.9 (this numpy version is required to run python 3.12)
# Python 3.9 support has been dropped since numpy >=2.1.0 (this numpy version is required to run python 3.13)
os: [macos-latest, windows-latest, ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
run: pip install uv
- name: Install dependencies
run: uv sync --frozen --no-cache --no-install-project
- name: Run pytest
run: uv run python -m pytest test
# Run benchmarks
- name: Run benchmark benchmark_array_creation
run: uv run python -m pytest test/benchmark_array_creation.py
- name: Run benchmark benchmark_distance_two_points
run: uv run python -m pytest test/benchmark_distance_two_points.py
- name: Run benchmark benchmark_distances_cdist
run: uv run python -m pytest test/benchmark_distances_cdist.py
- name: Run benchmark benchmark_distances_points_to_point
run: uv run python -m pytest test/benchmark_distances_points_to_point.py
- name: Run benchmark benchmark_distances_units
run: uv run python -m pytest test/benchmark_distances_units.py
- name: Run benchmark benchmark_bot_ai_prepare_units
run: uv run python -m pytest test/benchmark_prepare_units.py
- name: Run benchmark benchmark_bot_ai_init
run: uv run python -m pytest test/benchmark_bot_ai_init.py
run_test_bots:
# Run test bots that download the SC2 linux client and run it
name: Run testbots linux
needs: [run_pytest_tests]
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
# Do not allow this test to cancel. Finish all jobs regardless of error
fail-fast: false
matrix:
os: [ubuntu-latest]
# TODO Add '3.12' and '3.13' when a new image has been pushed
python-version: ["3.10", "3.11"]
sc2-version: ["4.10"]
env:
IMAGE_NAME: burnysc2/python-sc2:local
steps:
# Copy data from repository
- uses: actions/checkout@v3
- name: Print directories and files
run: sudo apt-get install tree && tree
- name: Load and build docker image
# Build docker image from Dockerfile using specific python and sc2 version
env:
BUILD_ARGS: --build-arg PYTHON_VERSION=${{ matrix.python-version }} --build-arg SC2_VERSION=${{ matrix.sc2-version }}
run: docker build -f test/Dockerfile -t $IMAGE_NAME $BUILD_ARGS --build-arg VERSION_NUMBER=${{ env.VERSION_NUMBER }} .
- name: Run autotest_bot.py
# Run bot and list resulting files (replay file, stable_id.json)
run: |
docker run -i -d --name my_container $IMAGE_NAME
docker exec -i my_container bash -c "python test/travis_test_script.py test/autotest_bot.py"
docker exec -i my_container bash -c "tree"
docker rm -f my_container
- name: Run upgradestest_bot.py
run: |
docker run -i -d --name my_container $IMAGE_NAME
docker exec -i my_container bash -c "python test/travis_test_script.py test/upgradestest_bot.py"
docker exec -i my_container bash -c "tree"
docker rm -f my_container
- name: Run damagetest_bot.py
run: |
docker run -i -d --name my_container $IMAGE_NAME
docker exec -i my_container bash -c "python test/travis_test_script.py test/damagetest_bot.py"
docker exec -i my_container bash -c "tree"
docker rm -f my_container
- name: Run queries_test_bot.py
run: |
docker run -i -d --name my_container $IMAGE_NAME
docker exec -i my_container bash -c "python test/travis_test_script.py test/queries_test_bot.py"
docker exec -i my_container bash -c "tree"
docker rm -f my_container
run_example_bots:
# Run example bots against computer
name: Run example bots against computer
needs: [run_pytest_tests]
runs-on: ubuntu-latest
timeout-minutes: 60
env:
IMAGE_NAME: burnysc2/python-sc2-docker:local
steps:
# Copy data from repository
- uses: actions/checkout@v3
- name: Print directories and files
run: sudo apt-get install tree && tree
- name: Load and build docker image
# Build docker image from Dockerfile using specific python and sc2 version
env:
BUILD_ARGS: --build-arg PYTHON_VERSION=${{ env.LATEST_PYTHON_VERSION }} --build-arg SC2_VERSION=${{ env.LATEST_SC2_VERSION }}
run: docker build -f test/Dockerfile -t $IMAGE_NAME $BUILD_ARGS --build-arg VERSION_NUMBER=${{ env.VERSION_NUMBER }} .
- name: Run example bots vs computer
run: |
docker run -i -d --name my_container $IMAGE_NAME
docker exec -i my_container bash -c "python test/run_example_bots_vs_computer.py"
docker exec -i my_container bash -c "tree"
docker rm -f my_container
# TODO Fix in main.py "run_multiple_games" or "a_run_multiple_games" or "a_run_multiple_games_nokill"
# run_bot_vs_bot:
# # Run bot vs bot
# name: Run example bots against each other
# needs: [run_pytest_tests]
# timeout-minutes: 60
# env:
# IMAGE_NAME: burnysc2/python-sc2-docker:local
#
# steps:
# # Copy data from repository
# - uses: actions/checkout@v3
#
# - name: Print directories and files
# run: |
# sudo apt-get install tree
# tree
#
# - name: Load and build docker image
# # Build docker image from Dockerfile using specific python and sc2 version
# env:
# BUILD_ARGS: --build-arg PYTHON_VERSION=${{ env.LATEST_PYTHON_VERSION }} --build-arg SC2_VERSION=${{ env.LATEST_SC2_VERSION }}
# run: |
# docker build -f test/Dockerfile -t $IMAGE_NAME $BUILD_ARGS --build-arg VERSION_NUMBER=${{ env.VERSION_NUMBER }} .
#
# - name: Run example bots vs each other
# run: |
# docker run -i -d --name my_container $IMAGE_NAME
# docker exec -i my_container bash -c "python test/run_example_bots_vs_each_other.py"
# docker exec -i my_container bash -c "tree"
# docker rm -f my_container
run_coverage:
# Run and upload coverage report
# This coverage test does not cover the whole testing range, check /bat_files/rune_code_coverage.bat
name: Run coverage
needs: [run_test_bots, run_example_bots]
runs-on: ubuntu-latest
timeout-minutes: 30
env:
IMAGE_NAME: burnysc2/python-sc2-docker:local
steps:
- uses: actions/checkout@v3
- name: Load and build docker image
# Build docker image from Dockerfile using specific python and sc2 version
env:
BUILD_ARGS: --build-arg PYTHON_VERSION=${{ env.LATEST_PYTHON_VERSION }} --build-arg SC2_VERSION=${{ env.LATEST_SC2_VERSION }}
run: docker build -f test/Dockerfile -t $IMAGE_NAME $BUILD_ARGS --build-arg VERSION_NUMBER=${{ env.VERSION_NUMBER }} .
- name: Set up container
run: |
mkdir htmlcov
docker run -i -d \
--mount type=bind,source=$(pwd)/htmlcov,destination=/root/python-sc2/htmlcov \
--name my_container \
$IMAGE_NAME
echo "Install dev requirements because only non dev requirements exist in the docker image at the moment"
docker exec -i my_container bash -c "uv sync --frozen --no-cache --no-install-project"
- name: Run coverage on tests
run: docker exec -i my_container bash -c "uv run pytest --cov=./"
- name: Run coverage on autotest_bot.py
run: docker exec -i my_container bash -c "uv run coverage run -a test/travis_test_script.py test/autotest_bot.py"
- name: Run coverage on upgradestest_bot.py
run: docker exec -i my_container bash -c "uv run coverage run -a test/travis_test_script.py test/upgradestest_bot.py"
- name: Run coverage on damagetest_bot.py
run: docker exec -i my_container bash -c "uv run coverage run -a test/travis_test_script.py test/damagetest_bot.py"
- name: Run coverage on queries_test_bot.py
run: docker exec -i my_container bash -c "uv run coverage run -a test/travis_test_script.py test/queries_test_bot.py"
# Bots might run differently long each time and create flucuations in code coverage - better to mock behavior instead
# - name: Run coverage on example bots
# run: |
# docker exec -i my_container bash -c "uv run coverage run -a test/run_example_bots_vs_computer.py"
- name: Generate xml coverage file
run: |
docker exec -i my_container bash -c "uv run coverage xml"
docker cp my_container:/root/python-sc2/coverage.xml $(pwd)/coverage.xml
- name: Generate html coverage files in htmlcov/ folder
run: |
docker exec -i my_container bash -c "uv run coverage html"
echo "Upload htmlcov folder because it was mounted in container, so it will be available in host machine"
- name: Upload htmlcov/ folder as artifact
uses: actions/upload-artifact@v3
with:
name: Coverage_report
path: htmlcov
run_radon:
name: Run radon complexity analysis
needs: [run_test_bots, run_example_bots]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.LATEST_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.LATEST_PYTHON_VERSION }}
- name: Install uv
run: pip install uv
- name: Install dependencies
run: uv sync --frozen --no-cache --no-install-project
- name: Run uv radon
run: uv run radon cc sc2/ -a -nb
release_to_github_pages:
name: GitHub Pages
needs: [run_test_bots, run_example_bots]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.LATEST_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.LATEST_PYTHON_VERSION }}
- name: Install uv
run: pip install uv
- name: Install dependencies
run: uv sync --frozen --no-cache --no-install-project
- name: Build docs from scratch
run: |
echo "<meta http-equiv=\"refresh\" content=\"0; url=./docs/index.html\" />" > index.html
mkdir -p docs
cd docs_generate
uv run sphinx-build -a -E -b html . ../docs
- name: Remove files unrelated to docs
run: |
rm -rf data dockerfiles docs_generate examples sc2 test
rm uv.lock
- name: Publish to Github Pages
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
BASE_BRANCH: develop # The branch the action should deploy from.
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: . # The folder the action should deploy.
release_to_pypi:
name: Pypi package release
needs: [run_test_bots, run_example_bots]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.LATEST_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.LATEST_PYTHON_VERSION }}
- name: Install uv
run: pip install uv
- name: Build package
run: uv build
- name: Publish to pypi
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
continue-on-error: true
run: uv publish --token ${{ secrets.pypi_burny_common_token }}