diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 23093b203b..c70b849391 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,6 +68,15 @@ jobs: run: | ./gradlew build ./gradlew clean + - name: Build Python examples (Windows) + if: ${{ matrix.os == 'windows-2022' }} + working-directory: photonlib-python-examples + run: .\run.bat + - name: Build Python examples (POSIX) + if: ${{ matrix.os != 'windows-2022' }} + working-directory: photonlib-python-examples + run: | + ./run.sh playwright-tests: name: "Playwright E2E tests" runs-on: ubuntu-22.04 diff --git a/photonlib-python-examples/run.bat b/photonlib-python-examples/run.bat index dcb872588f..304d69c87c 100644 --- a/photonlib-python-examples/run.bat +++ b/photonlib-python-examples/run.bat @@ -1,12 +1,8 @@ @echo off +setlocal enabledelayedexpansion +set "ERRORLEVEL=0" setlocal -:: Check if the first argument is provided -if "%~1"=="" ( - echo Error: No example-to-run provided. - exit /b 1 -) - :: To run any example, we want to use photonlib out of the source code in this repo. :: Build the wheel first pushd %~dp0..\photon-lib\py @@ -14,12 +10,31 @@ if exist build rmdir /S /Q build python setup.py bdist_wheel popd +:: Setup robotpy +pip install robotpy + + :: Add the output directory to PYTHONPATH to make sure it gets picked up ahead of any other installs set PHOTONLIBPY_ROOT=%~dp0..\photon-lib\py set PYTHONPATH=%PHOTONLIBPY_ROOT% +:: If an example to run is not provided, run all examples +if "%~1"=="" ( + echo No example provided, running all examples + for /D %%d in (*) do ( + if (not "%%d"=="." if not "%%d"=="..") ( + echo Running example in %%d + call "%~dp0run.bat" "%%d" + ) + ) + exit /b 0 +) + :: Move to to the right example folder cd %~1 +:: Setup project +pip install . + :: Run the example robotpy sim diff --git a/photonlib-python-examples/run.sh b/photonlib-python-examples/run.sh index c5a82709d3..1c676ccb18 100755 --- a/photonlib-python-examples/run.sh +++ b/photonlib-python-examples/run.sh @@ -1,9 +1,4 @@ -# Check if the first argument is provided -if [ $# -eq 0 ] - then - echo "Error: No example-to-run provided." - exit 1 -fi +set -e # To run any example, we want to use photonlib out of this repo # Build the wheel first @@ -18,8 +13,26 @@ popd export PHOTONLIBPY_ROOT=../photon-lib/py export PYTHONPATH=$PHOTONLIBPY_ROOT +# Setup robotpy +pip install robotpy + +# If an example to run is not provided, run all examples +if [ $# -eq 0 ] + then + echo "No example provided, running all examples" + for dir in */ + do + echo "Running example in $dir" + ./run.sh $dir + done + exit 0 +fi + # Move to the right example folder cd $1 +# Setup project +pip install . + # Run the example robotpy sim