forked from robotology-legacy/gym-ignition
-
Notifications
You must be signed in to change notification settings - Fork 2
574 lines (498 loc) · 19 KB
/
cicd.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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
name: CI/CD
on:
push:
branches: ["**"]
tags-ignore: ["**"]
pull_request:
workflow_dispatch:
release:
types: [published]
jobs:
# =============
build-colcon:
# =============
name: 'colcon@${{ matrix.gazebo }}'
if: |
(github.event_name == 'push' && github.ref != 'refs/heads/master') ||
(github.event_name == 'pull_request' && github.event.pull_request.base.ref != 'master')
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
gazebo:
# - dome
# - edifice
- garden
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache
steps:
- name: '🔍️ Inspect Environment'
run: |
env | grep ^GITHUB
echo ""
cat ${GITHUB_EVENT_PATH}
echo ""
env
- name: '⬇️️ Install dependencies'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
lz4 \
git \
wget \
gpg-agent \
ninja-build \
build-essential \
software-properties-common \
libeigen3-dev \
libxml2-dev \
coinor-libipopt-dev \
libassimp-dev \
libirrlicht-dev \
libglfw3-dev \
swig
- name: '🐍 Initialize Python'
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: '🚚 Compilation cache'
uses: actions/cache@v3
with:
path: ${{ env.CCACHE_DIR }}
# We include the commit sha in the cache key, as new cache entries are
# only created if there is no existing entry for the key yet.
key: ${{ runner.os }}-ccache-${{ matrix.gazebo }}-${{ github.sha }}
# Restore any ccache cache entry, if none for the key above exists
restore-keys: ${{ runner.os }}-ccache-${{ matrix.gazebo }}
- name: '🚚 Enable ccache'
run: |
sudo apt-get update
sudo apt-get install -y ccache
echo "/usr/lib/ccache" >> $GITHUB_PATH
ccache --set-config=max_size=5.0G
ccache --set-config=sloppiness=file_macro,locale,time_macros
ccache -p
ccache -s
- name: '⚙️ Add osrf ppa'
run: |
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" >\
/etc/apt/sources.list.d/gazebo-stable.list'
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt-get update
- name: '⚙️ Prepare colcon workspace'
run: |
pip install vcstool colcon-common-extensions
sudo mkdir -p /workspace/src /workspace/install
sudo chmod -R a+rw /workspace
cd /workspace/src
wget -O - ${TAGS_YAML} | vcs import
echo $(sort -u $(find . -iname 'packages-'$(lsb_release -cs)'.apt' -o -iname 'packages.apt') | grep -v -E "^libgz|^libsdformat" | tr '\n' ' ') \
> /workspace/install/pkg.txt
xargs -a /workspace/install/pkg.txt sudo apt-get install -y --no-install-recommends
env:
TAGS_YAML: https://raw.githubusercontent.com/gazebo-tooling/gazebodistro/master/collection-${{ matrix.gazebo }}.yaml
- name: '🏗️ Build idyntree'
run: |
cd /workspace/src
pip install numpy
git clone https://github.com/robotology/idyntree.git
cd ..
colcon build \
--packages-select iDynTree \
--cmake-args \
-GNinja \
-DIDYNTREE_USES_PYTHON:BOOL=ON \
-DIDYNTREE_USES_IPOPT:BOOL=ON \
-DCMAKE_BUILD_TYPE=Debug \
--merge-install
- name: '🏗️ Build colcon workspace'
run: |
cd /workspace
colcon graph
colcon build \
--cmake-args \
-GNinja \
-DBUILD_TESTING:BOOL=OFF \
-DCMAKE_BUILD_TYPE=Debug \
--merge-install
- name: '📈 Ccache stats'
run: ccache --show-stats
- name: '📦️ Compress the workspace'
run: tar -I lz4 -cf /tmp/workspace_install.tar.lz4 /workspace/install
- name: '⬆️ Upload the workspace'
uses: actions/upload-artifact@v4
with:
path: /tmp/workspace_install.tar.lz4
name: workspace-${{ matrix.gazebo }}
retention-days: 1
# ===============
build-and-test:
# ===============
name: 'Build and Test [${{matrix.type}}|${{matrix.gazebo}}|${{matrix.python}}]'
if: always()
needs: [ build-colcon ]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
type:
- User
- Developer
gazebo:
# - dome
# - edifice
- garden
python:
- '3.10'
steps:
- name: '🔍 Inspect Environment'
run: |
env | grep ^GITHUB
echo ""
cat ${GITHUB_EVENT_PATH}
echo ""
env
- name: '⬇️ Install build dependencies'
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
lz4 \
git \
wget \
cmake \
gpg-agent \
ninja-build \
build-essential \
software-properties-common
- name: '🐍 Initialize Python'
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: '🔀 Clone repository'
uses: actions/checkout@master
- name: '🔀 Download all refs'
run: git fetch --prune --unshallow
# ================
# Install Gazebo
# ================
- name: '⚙️ Add osrf ppa'
if: contains(matrix.os, 'ubuntu')
run: |
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" >\
/etc/apt/sources.list.d/gazebo-stable.list'
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt-get update
- name: '[🔒️|stable] Install Gazebo from ppa'
if: |
contains(matrix.os, 'ubuntu') && (
github.event_name == 'release' ||
github.ref == 'refs/heads/master' ||
(github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master')
)
run: sudo apt-get install -y --no-install-recommends gz-${{ matrix.gazebo }}
- name: '[🧪|nightly] Download pre-built colcon workspace'
uses: actions/download-artifact@v4
if: |
contains(matrix.os, 'ubuntu') && (
(github.event_name == 'push' && github.ref != 'refs/heads/master') ||
(github.event_name == 'pull_request' && github.event.pull_request.base.ref != 'master')
)
with:
path: /tmp
name: workspace-${{ matrix.gazebo }}
- name: '[🧪|nightly] Setup colcon workspace'
if: |
contains(matrix.os, 'ubuntu') && (
(github.event_name == 'push' && github.ref != 'refs/heads/master') ||
(github.event_name == 'pull_request' && github.event.pull_request.base.ref != 'master')
)
run: |
sudo tar -I lz4 -xf /tmp/workspace_install.tar.lz4 -C /
xargs -a /workspace/install/pkg.txt sudo apt-get install -y --no-install-recommends
echo "source /workspace/install/setup.bash" | sudo tee -a /etc/bash.bashrc
# =============
# Build project
# =============
# This is required because ScenarIO needs to import the iDynTree targets
- name: '⬇️ Install iDynTree dependencies'
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libxml2-dev coinor-libipopt-dev libeigen3-dev libassimp-dev swig
pip install numpy
- name: '🤖 Install iDynTree'
shell: bash -i -e {0}
run: |
export PYTHONPATH=/workspace/install/iDynTree/lib/python3/dist-packages:$PYTHONPATH
IDYNTREE_PYTHON_PKG=$(python3 -c 'import idyntree, pathlib; print(pathlib.Path(idyntree.__file__).parent)')
echo "PYTHONPATH=/workspace/install/iDynTree/lib/python3/dist-packages:$PYTHONPATH" >> $GITHUB_ENV
echo "CMAKE_PREFIX_PATH=$IDYNTREE_PYTHON_PKG" >> $GITHUB_ENV
# Note: In order to execute the setup.sh script, the file /etc/bash.bashrc must be sourced.
# To do that, we change the shell to a bash interactive session with 'bash -i -e'.
# Developer installation
- name: '[👷|developer] Build and Install C++ ScenarIO'
if: matrix.type == 'Developer'
shell: bash -i -e {0}
run: |
env
cmake -S . -B build/ \
-GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DGAZEBO_DISTRIBUTION=$(python3 -c "print('${{ matrix.gazebo }}'.capitalize())")
sudo cmake --build build/ --target install
- name: '[👷|developer] Install Python ScenarIO'
if: matrix.type == 'Developer'
run: pip install -e ./scenario
# User installation
- name: '[👤|user] Create wheel (default gazebo)'
if: matrix.type == 'User' && matrix.gazebo == 'garden'
shell: bash -i -e {0}
run: pip wheel -v -w dist/ ./scenario
# Note: Calling "pip wheel" with "--global-option" forces all dependencies to be built from their sdist.
# Since it's very slow, we create the wheel from setup.py without isolation (requires system deps).
- name: '[👤|user] Create wheel (custom gazebo)'
if: matrix.type == 'User' && matrix.gazebo != 'gardern'
shell: bash -i -e {0}
run: |
pip install wheel setuptools-scm cmake-build-extension
python3 ./scenario/setup.py bdist_wheel \
build_ext -DGAZEBO_DISTRIBUTION=$(python3 -c "print('${{ matrix.gazebo }}'.capitalize())")
- name: '[👤|user] Install local wheel'
if: matrix.type == 'User'
run: pip install -v dist/scenario-*.whl
- name: '🔍️ Inspect installed ScenarIO package'
if: matrix.type == 'User' && contains(matrix.os, 'ubuntu')
run: |
sudo apt-get install -y --no-install-recommends tree
tree $(python3 -c "import scenario, pathlib; print(pathlib.Path(scenario.__file__).parent)")
# ====================
# Install gym-gz
# ====================
- name: '🐍 Install gym-gz'
run: |
pip install -i https://test.pypi.org/simple/ gym-gz-models
pip install wheel && pip install .[all]
# ============
# Test project
# ============
- name: '🔍 Inspect installed versions'
run: pip list | grep -E "^scenario|^gym-gz"
- name: '[🐍|scenario] Python Tests'
shell: bash -i -e {0}
run: pytest -m "scenario"
- name: '[🚨|scenario] Python Tests with Valgrind'
shell: bash -i -e {0}
if: failure()
run: |
sudo apt-get install -y --no-install-recommends valgrind
pip install colour-valgrind
valgrind --log-file=/tmp/valgrind.log pytest -m "scenario" || colour-valgrind -t /tmp/valgrind.log
- name: '[🐍|gym-gz] Python Tests'
shell: bash -i -e {0}
run: pytest -m "gym_gz"
- name: '[🚨|gym-gz] Python Tests with Valgrind'
shell: bash -i -e {0}
if: failure()
run: |
sudo apt-get install -y --no-install-recommends valgrind
pip install colour-valgrind
valgrind --log-file=/tmp/valgrind.log pytest -m "gym_gz" || colour-valgrind -t /tmp/valgrind.log
# ============================
# Upload artifacts (only User)
# ============================
- name: '🗑️ Remove external wheels'
if: matrix.type == 'User'
run: find dist/ -type f -not -name 'scenario-*' -delete -print
# We have to trick PyPI that our wheels are manylinux2014 even if they are not.
# Unfortunately we cannot create self-contained wheels (neither the PEP600 perennial)
# due to the Gazebo architecture.
- name: '📝 Rename scenario wheel'
if: matrix.type == 'User' && contains(matrix.os, 'ubuntu')
run: |
ls dist/
find dist/ -type f -name "*.whl" -exec rename.ul linux manylinux2014 {} +
ls dist/
- name: '🔍 Inspect dist folder'
if: matrix.type == 'User'
run: ls -lah dist/
- name: '⬆️ Upload artifacts'
uses: actions/upload-artifact@v4
if: matrix.type == 'User' && matrix.gazebo == 'gardern'
with:
path: dist/*
name: dist
# =======
# Website
# =======
- name: '⬇️ Install website dependencies'
run: |
sudo apt-get update
sudo apt-get install -y doxygen texlive-font-utils
- name: '🔍 Inspect metadata'
run: sphinx-multiversion --dump-metadata docs/sphinx/ build/
# This is necessary because otherwise the check for uncommitted apidoc
# only detects additions, not removals.
- name: '🗑️ Remove apidoc folder'
run: rm -r docs/sphinx/apidoc
- name: '🏗️ Build sphinx website'
shell: bash -i -e {0}
run: |
[[ -d build ]] && sudo chown -R $(id -u):$(id -g) build/
cmake -S . -B build/ -DBUILD_DOCS:BOOL=ON
cmake --build build/ --target sphinx
- name: '🔍 Check new uncommitted apidoc'
run: test $(git status --porcelain | wc -l) -eq 0
- name: '🔍 git status'
if: ${{ failure() }}
run: |
git status
git diff
- name: '⬆️ Upload website folder'
uses: actions/upload-artifact@v4
if: matrix.type == 'User' && matrix.gazebo == 'garden' && contains(matrix.os, 'ubuntu')
with:
path: build/html
name: website
retention-days: 1
# ===================
website-deployment:
# ===================
name: 'Website Deployment'
if: always() && needs.build-and-test.result == 'success'
needs: [ build-and-test ]
runs-on: ubuntu-latest
steps:
- name: '⬇️ Download website folder'
uses: actions/download-artifact@v4
with:
path: build/html
name: website
- name: '🔍 Inspect html folder'
run: ls -lah build/html
- name: '🚀 Deploy'
uses: JamesIves/github-pages-deploy-action@releases/v3
if: |
github.event_name == 'push' &&
github.repository == 'andreaostuni/gym-gz' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/devel')
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: build/html
CLEAN: true
CLEAN_EXCLUDE: '[".gitignore", ".nojekyll"]'
# =================
python-packaging:
# =================
name: 'Python packaging'
if: always() && needs.build-and-test.result == 'success'
needs: [ build-and-test ]
runs-on: ubuntu-latest
steps:
- name: '🔍️ Inspect Environment'
run: |
env | grep ^GITHUB
echo ""
cat ${GITHUB_EVENT_PATH}
echo ""
env
# Any Python3 version is ok in this job
- name: '🐍 Initialize Python'
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: '🔀 Clone repository'
uses: actions/checkout@master
- name: '🔀 Download all refs'
run: git fetch --prune --unshallow
# ===============
# Download wheels
# ===============
- name: '⬇️ Download scenario wheels'
uses: actions/download-artifact@v4
with:
path: dist
name: dist
- name: '🔍 Inspect dist folder'
run: ls -lah dist/
# ===============
# Create packages
# ===============
# We use build to create sdist. Also pipx would work.
# https://github.com/pypa/build
# Compared to calling setup.py, the advantage of these tools is that
# they automatically handle the build dependencies.
- name: '🐍️️ Install dependencies'
run: pip install build
- name: '[📦|scenario]️ Create sdist'
run: python -m build --sdist scenario/ -o dist/
- name: '[📦|gym-gz]️ Create sdist and wheel'
run: python -m build .
# ================
# Upload artifacts
# ================
- name: '🗑️ Remove external packages'
run: find dist/ -type f -not \( -name '*scenario-*' -o -name '*gym_gz-*' \) -delete -print
- name: '🔍 Check packages'
run: pipx run twine check dist/*
- name: '🔍 Inspect dist folder'
run: ls -lah dist/
- name: '⬆️ Upload artifacts'
uses: actions/upload-artifact@v4
with:
path: dist/*
name: dist
# ============
upload_pypi:
# ============
name: Publish to PyPI
if: always() && needs.build-and-test.result == 'success' && needs.python-packaging.result == 'success'
needs:
- build-and-test
- python-packaging
runs-on: ubuntu-latest
# Devel branch produces pre-releases.
# GitHub releases produce stable releases.
steps:
# Needed only to extract from the git repo the last revision
- name: '🔀 Clone repository'
uses: actions/checkout@master
- name: '🔀 Download all refs'
run: git fetch --prune --unshallow
- name: '⬇️ Download Python packages'
uses: actions/download-artifact@v4
with:
path: dist
name: dist
- name: '🔍 Inspect dist folder'
run: ls -lah dist/
# Validate the last tag accordingly to PEP440
# From https://stackoverflow.com/a/37972030/12150968
- name: '📌 Check PEP440 compliance'
if: github.event_name == 'release'
run: |
sudo apt-get update
sudo apt-get install -y source-highlight
last_tag_with_v="$(git describe --abbrev=0 --tags)"
last_tag=${last_tag_with_v#v}
rel_regexp='^(\d+!)?(\d+)(\.\d+)+([\.\-\_])?((a(lpha)?|b(eta)?|c|r(c|ev)?|pre(view)?)\d*)?(\.?(post|dev)\d*)?$'
echo ""
echo $last_tag
echo ""
check-regexp ${rel_regexp} ${last_tag}
match=$(check-regexp ${rel_regexp} ${last_tag} | grep matches | cut -d ' ' -f 5)
test $match -eq 1 && true
- name: '⬆️ Publish packages to PyPI'
if: |
github.repository == 'andreaostuni/gym-gz' &&
((github.event_name == 'release' && github.event.action == 'published') ||
(github.event_name == 'push' && github.ref == 'refs/heads/devel'))
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
skip-existing: true