Merge pull request #330 from ros-drivers/fix-rolling-builds #245
This file contains 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: Build and Test | |
on: | |
push: | |
branches: | |
- 'ros2' | |
pull_request: | |
branches: | |
- 'ros2/*' | |
- 'ros2' | |
workflow_dispatch: | |
jobs: | |
get_ros_distros: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get -y install curl jq | |
- name: Get active distributions | |
run: | | |
wget https://raw.githubusercontent.com/flynneva/active_ros_distros/0.1.0/main.py -O active_ros_distros.py | |
python3 -m pip install rosdistro | |
python3 active_ros_distros.py --distribution-type ros2 | |
- name: Generate actions matrix | |
id: set-matrix | |
run: | | |
ACTIVE_ROS_DISTROS=(noetic) | |
DOCKER_DISTRO_MATRIX=() | |
RAW_DOCKER_JSON=$(curl -s "https://hub.docker.com/v2/repositories/rostooling/setup-ros-docker/tags?page_size=1000") | |
while read distro; do | |
ACTIVE_ROS_DISTROS+=( $distro ) | |
done < "/tmp/active_ros_distros.txt" | |
DISTRO_STR="[" | |
MATRIX_STR="[" | |
for distro in ${ACTIVE_ROS_DISTROS[@]}; do | |
docker_image=$(echo $RAW_DOCKER_JSON | | |
jq -r --arg DISTRO "$distro" '.results[] | select(.tag_status=="active") | select(.name | contains("ros-base-latest")) | select(.name | contains($DISTRO)) | .name' | | |
sort -u) | |
# Handle the case if two docker images were declared for one distro | |
# e.g. rolling moving from one Ubuntu Jammy to Ubuntu Noble | |
docker_image_arr=($docker_image) | |
DISTRO_STR+="\"${distro}\", " | |
MATRIX_STR+="{docker_image:\"${docker_image_arr[-1]}\",ros_distro:\"${distro}\"}, " | |
done | |
# Remove trailing , at end | |
DISTRO_STR=${DISTRO_STR%??} | |
MATRIX_STR=${MATRIX_STR%??} | |
# Close up brackets | |
DISTRO_STR+="]" | |
MATRIX_STR+="]" | |
echo "DISTRO_STR: ${DISTRO_STR}" | |
echo "MATRIX_STR: ${MATRIX_STR}" | |
echo "series=$DISTRO_STR" >> $GITHUB_OUTPUT | |
echo "matrix=$MATRIX_STR" >> $GITHUB_OUTPUT | |
outputs: | |
series: ${{ steps.set-matrix.outputs.series }} | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
build_and_test: | |
runs-on: [ubuntu-latest] | |
needs: get_ros_distros | |
strategy: | |
fail-fast: false | |
matrix: | |
ros_distro: ${{ fromJson(needs.get_ros_distros.outputs.series) }} | |
include: | |
${{ fromJson(needs.get_ros_distros.outputs.matrix) }} | |
container: | |
image: rostooling/setup-ros-docker:${{ matrix.docker_image }} | |
steps: | |
- name: Setup Directories | |
run: mkdir -p ros_ws/src | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
path: ros_ws/src | |
- name: Build and Test ROS 1 | |
uses: ros-tooling/action-ros-ci@master | |
if: ${{ contains('["melodic", "noetic"]', matrix.ros_distro) }} | |
continue-on-error: true | |
with: | |
package-name: usb_cam | |
target-ros1-distro: ${{ matrix.ros_distro }} | |
vcs-repo-file-url: "" | |
- name: Build and Test ROS 2 | |
id: build_and_test_step | |
uses: ros-tooling/action-ros-ci@master | |
if: ${{ contains('["melodic", "noetic"]', matrix.ros_distro) == false }} | |
with: | |
package-name: usb_cam | |
target-ros2-distro: ${{ matrix.ros_distro }} | |
vcs-repo-file-url: "" | |
colcon-defaults: | | |
{ | |
"build": { | |
"mixin": ["coverage-gcc"] | |
} | |
} | |
# If possible, pin the repository in the workflow to a specific commit to avoid | |
# changes in colcon-mixin-repository from breaking your tests. | |
colcon-mixin-repository: https://raw.githubusercontent.com/colcon/colcon-mixin-repository/1ddb69bedfd1f04c2f000e95452f7c24a4d6176b/index.yaml | |
- uses: actions/upload-artifact@v1 | |
with: | |
name: colcon-logs-${{ matrix.ros_distro }} | |
path: ${{ steps.build_and_test_step.outputs.ros-workspace-directory-name }}/log | |
if: always() | |
continue-on-error: true | |
- uses: actions/upload-artifact@v1 | |
with: | |
name: lcov-logs-${{ matrix.ros_distro }} | |
path: ${{ steps.build_and_test_step.outputs.ros-workspace-directory-name }}/lcov | |
if: always() | |
continue-on-error: true |