mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
ci: check if a versioned .msg file is changed, a new version is added as well
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
name: ROS translation node tests
|
name: ROS Translation Node Tests
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
@@ -12,7 +12,7 @@ defaults:
|
|||||||
jobs:
|
jobs:
|
||||||
build_and_test:
|
build_and_test:
|
||||||
name: Build and test
|
name: Build and test
|
||||||
runs-on: ubuntu-latest
|
runs-on: [runs-on,runner=8cpu-linux-x64,image=ubuntu24-full-x64,"run-id=${{ github.run_id }}",spot=false]
|
||||||
container:
|
container:
|
||||||
image: rostooling/setup-ros-docker:ubuntu-jammy-latest
|
image: rostooling/setup-ros-docker:ubuntu-jammy-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -21,7 +21,18 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
required-ros-distributions: humble
|
required-ros-distributions: humble
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# Workaround for https://github.com/actions/runner/issues/2033
|
||||||
|
- name: ownership workaround
|
||||||
|
run: git config --system --add safe.directory '*'
|
||||||
|
|
||||||
|
- name: Check .msg file versioning
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
run: |
|
||||||
|
./Tools/ci/check_msg_versioning.sh ${{ github.event.pull_request.base.sha }} ${{github.event.pull_request.head.sha}}
|
||||||
|
|
||||||
- name: Build and test
|
- name: Build and test
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Executable
+67
@@ -0,0 +1,67 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
# Copy a git diff between two commits if msg versioning is added
|
||||||
|
|
||||||
|
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||||
|
|
||||||
|
PX4_SRC_DIR="$DIR/.."
|
||||||
|
|
||||||
|
BASE_COMMIT="$1"
|
||||||
|
HEAD_COMMIT="$2"
|
||||||
|
if [ -z "${BASE_COMMIT}" ] || [ -z "${HEAD_COMMIT}" ]
|
||||||
|
then
|
||||||
|
echo "Usage: $0 <base_commit> <head_commit>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
failed=0
|
||||||
|
|
||||||
|
# Iterate git diff files between BASE_COMMIT and HEAD_COMMIT
|
||||||
|
modified_files="$(git --no-pager diff --no-color --name-only --diff-filter=M "${BASE_COMMIT}"..."${HEAD_COMMIT}")"
|
||||||
|
all_files="$( git --no-pager diff --no-color --name-only "${BASE_COMMIT}"..."${HEAD_COMMIT}")"
|
||||||
|
for file in ${modified_files}
|
||||||
|
do
|
||||||
|
if [[ "$file" == msg/versioned/*.msg ]]; then
|
||||||
|
echo "Modified msg file: ${file}"
|
||||||
|
# A modified versioned .msg file requires:
|
||||||
|
# - Incrementing the version
|
||||||
|
# - An old .msg version exists
|
||||||
|
# - A translation header exists and is included
|
||||||
|
diff=$(git --no-pager diff --no-color --diff-filter=M "${BASE_COMMIT}"..."${HEAD_COMMIT}" -- "${file}")
|
||||||
|
old_version=$(echo "${diff}" | sed -n 's/^-uint32 MESSAGE_VERSION = \([0-9]*\).*/\1/p')
|
||||||
|
new_version=$(echo "${diff}" | sed -n 's/^+uint32 MESSAGE_VERSION = \([0-9]*\).*/\1/p')
|
||||||
|
|
||||||
|
# Check that the version is incremented
|
||||||
|
if [ -z "${new_version}" ] || [ -z "${old_version}" ]; then
|
||||||
|
echo "ERROR: Missing version update for ${file}"
|
||||||
|
failed=1
|
||||||
|
else
|
||||||
|
if [ $((new_version-old_version)) -ne 1 ]; then
|
||||||
|
echo "ERROR: Version not incremented by +1 for ${file}"
|
||||||
|
failed=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check that an old version exists
|
||||||
|
filename=$(basename -- "$file")
|
||||||
|
filename="${filename%.*}"
|
||||||
|
old_version_file="px4_msgs_old/msg/${filename}V${old_version}.msg"
|
||||||
|
if [[ "${all_files}" != *"${old_version_file}"* ]]; then
|
||||||
|
echo "ERROR: Old message version does not exist for ${file} (missing ${old_version_file})"
|
||||||
|
failed=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check that a translation header got added by checking for a modification to all_translations.h
|
||||||
|
# If it is changed, we assume a new header got added too, so we don't explicitly check for that
|
||||||
|
if [[ "${modified_files}" != *"translations/all_translations.h"* ]]; then
|
||||||
|
echo "ERROR: missing modification to translations/all_translations.h"
|
||||||
|
failed=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ${failed} -ne 0 ]; then
|
||||||
|
echo ""
|
||||||
|
echo "ERROR: missing message versioning due to changed .msg file(s) (see above)"
|
||||||
|
echo "Check the documentation under https://docs.px4.io/main/en/ros2/px4_ros2_msg_translation_node.html for how to add a new version"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user