|
| 1 | +name: Humble_test_with_docker_NativeROS_string |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "main" |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, labeled] |
| 9 | +jobs: |
| 10 | + ci: |
| 11 | + runs-on: ${{ matrix.os }} |
| 12 | + if: | |
| 13 | + ((github.event.action == 'labeled') && (github.event.label.name == 'TESTING') && (github.base_ref == 'main' )) || |
| 14 | + ((github.event.action == 'synchronize') && (github.base_ref == 'main') && contains(github.event.pull_request.labels.*.name, 'TESTING')) || |
| 15 | + (github.ref_name == 'main') |
| 16 | + container: |
| 17 | + image: osrf/ros:${{ matrix.ros_distribution }}-desktop |
| 18 | + timeout-minutes: 5 |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + os: [ubuntu-22.04] |
| 23 | + ros_distribution: [humble] |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v3 |
| 27 | + with: |
| 28 | + submodules: recursive |
| 29 | + - name: Set up Docker Buildx |
| 30 | + uses: docker/setup-buildx-action@v1 |
| 31 | + |
| 32 | + - name: Install Docker Compose |
| 33 | + run: sudo apt-get update && sudo apt-get install -y docker-compose |
| 34 | + # docker-compose.yml を使ってコンテナを起動 |
| 35 | + - name: Build and run containers |
| 36 | + run: docker-compose up -d |
| 37 | + - name: Wait for containers to start |
| 38 | + run: sleep 20 # コンテナが確実に起動するのを待つ時間を長くする |
| 39 | + - name: List running containers |
| 40 | + run: docker ps -a # 全コンテナが起動しているか確認 |
| 41 | + - name: Show container logs # コンテナのログを確認する |
| 42 | + run: | |
| 43 | + docker logs app1 |
| 44 | + docker logs app2 |
| 45 | + - name: Show IP addresses |
| 46 | + run: | |
| 47 | + docker exec app1 ip addr show eth0 |
| 48 | + docker exec app2 ip addr show eth0 |
| 49 | + - name: Test communication between containers (ping) |
| 50 | + run: | |
| 51 | + docker exec app1 ping -c 4 172.19.0.3 # app1 から app2 へのPing |
| 52 | + docker exec app2 ping -c 4 172.19.0.2 # app2 から app1 へのPing |
| 53 | + - name: Test TCP connection between containers (netcat) |
| 54 | + run: | |
| 55 | + # app2でポート8080をリスン |
| 56 | + docker exec -d app2 bash -c "nc -l -p 8080" |
| 57 | + # app1からapp2へのTCP接続を確認 |
| 58 | + docker exec app1 bash -c "echo 'Test' | nc -w 3 172.19.0.3 8080" |
| 59 | + # app1: ビルドの準備 (chmod +x update_ip.sh と ./update_ip.sh の実行) |
| 60 | + - name: Prepare build in mros |
| 61 | + run: | |
| 62 | + docker cp $GITHUB_WORKSPACE app1:/root/ws_mros # ソースコードをapp1コンテナにコピー |
| 63 | + docker exec app1 bash -c " |
| 64 | + cd /root/ws_mros && |
| 65 | + chmod +x update_ip.sh && # 権限変更 |
| 66 | + ./update_ip.sh" # IPアドレス更新スクリプトの実行 |
| 67 | + # app1: クリーンビルド |
| 68 | + - name: Clean and build in mros |
| 69 | + run: | |
| 70 | + docker exec app1 bash -c " |
| 71 | + cd /root/ws_mros && |
| 72 | + pwd && |
| 73 | + ls -la && |
| 74 | + bash build.bash clean && # クリーンアップ |
| 75 | + bash build.bash all test_echoback_string" |
| 76 | + # app2: のコードをコンテナにコピーしてビルド |
| 77 | + - name: Clone Native test stub source code to app2 and build and run |
| 78 | + run: | |
| 79 | + docker exec app2 bash -c " |
| 80 | + source /opt/ros/humble/setup.bash && |
| 81 | + cd && |
| 82 | + pwd && |
| 83 | + ls -la && |
| 84 | + git clone https://github.com/mROS-base/mros2-host-examples && |
| 85 | + cd mros2-host-examples && |
| 86 | + colcon build --packages-select mros2_echoreply_string && |
| 87 | + ls -la && |
| 88 | + source install/setup.bash" |
| 89 | + - name: Run mROS and Native ROS |
| 90 | + shell: bash |
| 91 | + run : | |
| 92 | + # テスト対象をバックグラウンドで実行 |
| 93 | + docker exec app2 bash -c "source /opt/ros/humble/setup.bash && |
| 94 | + cd mros2-host-examples && |
| 95 | + source install/setup.bash && |
| 96 | + ros2 run mros2_echoreply_string echoreply_node" & |
| 97 | +
|
| 98 | + docker exec app1 bash -c "cd /root/ws_mros && ./cmake_build/mros2-posix" & |
| 99 | + mros_pid=$! # テストプログラムのプロセスIDを取得 |
| 100 | +
|
| 101 | + docker ps |
| 102 | +
|
| 103 | + # mROSが終了するまで待つ |
| 104 | + wait $mros_pid |
| 105 | + mros_status=$? |
| 106 | + # 結果に基づいてCIの成否を判断 |
| 107 | + if [ $mros_status -eq 0 ] ;then |
| 108 | + echo "Succeed pub/sub test process between mros2 and Native ROS" |
| 109 | + exit 0 |
| 110 | + else |
| 111 | + echo "Fail pub/sub test process between mros2 and Native ROS" |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | + - name: Tear down containers |
| 115 | + run: docker-compose down |
0 commit comments