Skip to content

Commit

Permalink
ci: create build-and-test-differential.yaml (#95)
Browse files Browse the repository at this point in the history
* create build-and-test-differential.yaml

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* chore: update checkout action fetch-depth in build-and-test-differential.yaml

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* feat: add git diff output to check for changed packages

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* chore: update git diff command to use pull request base and head commits

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* add fetch step

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* chore: setup Git Safe Directory for wheel_stuck_ws

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* delete fetch step

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* refactor ci

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* chore: update build-and-test-differential.yaml to install dependencies only when necessary

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* update job name

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* change build-and-test ci trigger

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* chore: update build-and-test-differential.yaml to use --packages-up-to flag for colcon build

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* delete continue-on-error

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* add dir to package conversion

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* fix typo

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* fix regex

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* fix regex

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* fix status capture

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

* add packages-select option to colcon test

Signed-off-by: Autumn60 <harada.akiro@gmail.com>

---------

Signed-off-by: Autumn60 <harada.akiro@gmail.com>
  • Loading branch information
Autumn60 authored Jul 28, 2024
1 parent acc6521 commit 607b2d2
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 2 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/build-and-test-differential.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: build-and-test-differential

on:
pull_request:
branches: [main]
jobs:
build_and_test_differential:
strategy:
matrix:
os:
- ubuntu-22.04
rosdistro:
- humble

runs-on: ubuntu-latest

container:
image: ros:${{ matrix.rosdistro }}-ros-base

steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Git Safe Directory
run: |
git config --global --add safe.directory /__w/wheel_stuck_ws/wheel_stuck_ws
- name: Check for changed files
id: changed-files
run: |
echo "Base: ${{ github.event.pull_request.base.sha }}"
echo "Head: ${{ github.sha }}"
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
CHANGED_PACKAGE_DIRS=$(echo "$CHANGED_FILES" | grep -E '^(src/[^/]+(/[^/]+)*)' | while read -r file; do
dir=$(dirname "$file")
while [ "$dir" != "." ]; do
if [ -f "$dir/package.xml" ]; then
echo "$dir"
break
fi
dir=$(dirname "$dir")
done
done | sort -u)
CHANGED_PACKAGES=$(echo "$CHANGED_PACKAGE_DIRS" | awk -F'/' '{print $NF}' | sort -u)
if [ -z "$CHANGED_PACKAGES" ]; then
echo "No changed packages found."
echo "::set-output name=packages::"
else
echo "Changed packages: $CHANGED_PACKAGES"
echo "::set-output name=packages::$CHANGED_PACKAGES"
fi
if [ $(echo "$CHANGED_FILES" | grep -c "depend_packages_ci.repos") -eq 1 ]; then
echo "depend_packages_ci.repos is changed"
echo "::set-output name=repos_file_changed::true"
else
echo "depend_packages_ci.repos is not changed"
echo "::set-output name=repos_file_changed::false"
fi
- name: Install dependencies
if: steps.changed-files.outputs.repos_file_changed == 'true' || steps.changed-files.outputs.packages != ''
run: |
rosdep update &&
apt-get update &&
vcs import src < depend_packages_ci.repos &&
rosdep install --from-path . -i -y --rosdistro ${{ matrix.rosdistro }}
- name: Install diagnostic-updater
if: steps.changed-files.outputs.packages != ''
run: apt-get install ros-${{ matrix.rosdistro }}-diagnostic-updater

- name: Build tests
if: steps.changed-files.outputs.packages != ''
id: build_test
run: |
. /opt/ros/${{ matrix.rosdistro }}/setup.sh &&
colcon build --packages-up-to ${{ steps.changed-files.outputs.packages }}
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
echo "Build succeeded"
else
echo "Build failed"
exit 1
fi
- name: Run tests
if: steps.changed-files.outputs.packages != ''
id: run_test
run: |
. /opt/ros/${{ matrix.rosdistro }}/setup.sh &&
colcon test --packages-select ${{ steps.changed-files.outputs.packages }} &&
colcon test-result
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
echo "Test succeeded"
else
echo "Test failed"
exit 1
fi
6 changes: 4 additions & 2 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: build-and-test

on:
pull_request:
branches: [main]
push:
branches:
- main
workflow_dispatch:
jobs:
build_and_test:
strategy:
Expand Down

0 comments on commit 607b2d2

Please sign in to comment.