Add working CI #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Drone Simulation CI | |
| on: | |
| push: | |
| branches: | |
| - CI | |
| pull_request: | |
| branches: | |
| - CI | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # Restore cached AP build | |
| - name: Cache ArduPilot Build | |
| id: cache-ardupilot | |
| uses: actions/cache@v4 | |
| with: | |
| path: ap_build_cache | |
| key: ardupilot-sitl-build-${{ runner.os }} | |
| - name: Pull Docker Image | |
| run: docker pull dierust/knr_ap_sim:latest | |
| - name: Start Docker Container | |
| run: | | |
| docker run -d --name knr_drone \ | |
| -v ${{ github.workspace }}/src:/root/ros_ws/src \ | |
| --net=host \ | |
| dierust/knr_ap_sim:latest \ | |
| tail -f /dev/null | |
| - name: Build ROS2 Workspace | |
| run: > | |
| docker exec knr_drone bash -c "source /opt/ros/humble/setup.bash && cd | |
| ~/ros_ws && colcon build" || exit 1 | |
| - name: Prepare Container Dependencies (GUI & MAVProxy fix) | |
| run: | | |
| docker exec knr_drone bash -c "apt-get update && apt-get install -y xvfb libxcb-cursor0 iproute2" | |
| docker exec knr_drone bash -c "pip3 install --upgrade MAVProxy pymavlink" | |
| # add AP build cache into container | |
| - name: Restore ArduPilot Build into Container | |
| if: steps.cache-ardupilot.outputs.cache-hit == 'true' | |
| run: | | |
| docker exec knr_drone mkdir -p /tools/ardupilot/build | |
| docker cp ap_build_cache/. knr_drone:/tools/ardupilot/build/ | |
| - name: Pre-build ArduPilot SITL | |
| run: | | |
| docker exec knr_drone bash -c "git config --global --add safe.directory /tools/ardupilot && cd /tools/ardupilot && ./modules/waf/waf-light configure --board sitl && ./modules/waf/waf-light build --target bin/arducopter -j$(nproc)" | |
| # save AP build cache | |
| - name: Save ArduPilot Build to Host | |
| run: | | |
| mkdir -p ap_build_cache | |
| docker cp knr_drone:/tools/ardupilot/build/. ap_build_cache/ | |
| - name: Start Simulation and SITL | |
| run: | | |
| cd scripts | |
| chmod +x *.sh | |
| # Uruchamiamy symulację w tle (Webots) | |
| docker exec knr_drone bash -c "source /opt/ros/humble/setup.bash && source ~/ros_ws/install/setup.bash && xvfb-run -a ros2 launch drone_bringup drone_simulation.launch.py gui:=False" > ../simulation_log.txt 2>&1 & | |
| # Uruchamiamy SITL (teraz odpali się niemal natychmiast, bo binaries są już zbudowane) | |
| ./run_ardupilot_sitl.sh > ../sitl_log.txt 2>&1 & | |
| echo "Aktywne oczekiwanie na gotowość SITL (otwarcie portu 5762)..." | |
| timeout 60 bash -c 'until docker exec knr_drone bash -c "ss -tln | grep -q 5762"; do sleep 2; echo "Czekam..."; done' | |
| echo "Port 5762 otwarty! Czekam 15 sekund na stabilizację Node'ów ROS i MAVLink..." | |
| sleep 15 | |
| - name: Run Test Mission | |
| run: | | |
| cd scripts | |
| chmod +x run_test_mission.sh | |
| # Uruchamiamy misję z limitem 120 sekund | |
| if timeout --kill-after=10s 60s ./run_test_mission.sh > ../mission_log.txt 2>&1; then | |
| echo "MISSION SUCCESS" | |
| else | |
| EXIT_CODE=$? | |
| echo "MISSION FAILED OR TIMEOUT (exit code: $EXIT_CODE)" | |
| echo "--- MISSION LOGS ---" | |
| cat ../mission_log.txt | |
| exit 0 | |
| fi | |
| - name: Upload Logs | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: logs | |
| path: | | |
| simulation_log.txt | |
| sitl_log.txt | |
| mission_log.txt |